Skip to content

Commit 32c5e3b

Browse files
authored
[TASK] Split up custom JavaScript files (#220)
The code was moved without modification from the previous `theme.js` file. This makes it easier to get the purpose of a file. They are combined again to `theme.min.js` upon build. The initialization of `window.T3Docs = {};` was removed as this is not used anymore (as far as I can tell).
1 parent b276ca1 commit 32c5e3b

File tree

5 files changed

+52
-60
lines changed

5 files changed

+52
-60
lines changed

packages/typo3-docs-theme/Gruntfile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ module.exports = function (grunt) {
115115
target: {
116116
files: {
117117
'<%= paths.output %>js/theme.min.js': [
118-
'<%= paths.source %>js/code-clipboard.js',
119-
'<%= paths.source %>js/theme.js',
118+
'<%= paths.source %>js/*.js',
120119
]
121120
}
122121
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// toggle expand-collapse state of menu item
2+
function toggleCurrent(event) { 'use strict';
3+
event.preventDefault();
4+
var link = event.currentTarget.parentElement;
5+
var element = link.parentElement;
6+
var siblings = element.parentElement.parentElement.querySelectorAll('li.current');
7+
for (var i = 0; i < siblings.length; i++) {
8+
if (siblings[i] !== element) {
9+
siblings[i].classList.remove('current');
10+
}
11+
}
12+
element.classList.toggle('current');
13+
}
14+
15+
// add toggle icon to a-tags of menu items in .toc navigations
16+
function makeMenuExpandable() { 'use strict';
17+
var tocs = document.getElementsByClassName('toc');
18+
for (var i = 0; i < tocs.length; i++) {
19+
var links = tocs[i].getElementsByTagName('a');
20+
for (var ii = 0; ii < links.length; ii++) {
21+
if (links[ii].nextSibling) {
22+
var expand = document.createElement('span');
23+
expand.classList.add('toctree-expand');
24+
expand.addEventListener('click', toggleCurrent, true);
25+
links[ii].prepend(expand);
26+
}
27+
}
28+
}
29+
}
30+
makeMenuExpandable();
31+
32+
jQuery(document).ready(function () {
33+
'use strict';
34+
35+
// start with collapsed menu on a TYPO3 Exceptions page
36+
jQuery('li.toctree-l1.current').filter(":contains('TYPO3 Exceptions')").removeClass('current');
37+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// wrap tables to make them responsive
2+
function makeTablesResponsive() { 'use strict';
3+
var tables = document.querySelectorAll('.rst-content table.docutils');
4+
for (var i = 0; i < tables.length; i++) {
5+
var wrapper = document.createElement('div');
6+
wrapper.classList.add('table-responsive');
7+
tables[i].parentNode.insertBefore(wrapper, tables[i]);
8+
wrapper.appendChild(tables[i]);
9+
}
10+
}
11+
makeTablesResponsive();
Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
1-
// T3Docs
2-
3-
// ensure our own namespace
4-
if (typeof window.T3Docs === 'undefined') {
5-
window.T3Docs = {};
6-
}
7-
8-
// toggle expand-collapse state of menu item
9-
function toggleCurrent(event) { 'use strict';
10-
event.preventDefault();
11-
var link = event.currentTarget.parentElement;
12-
var element = link.parentElement;
13-
var siblings = element.parentElement.parentElement.querySelectorAll('li.current');
14-
for (var i = 0; i < siblings.length; i++) {
15-
if (siblings[i] !== element) {
16-
siblings[i].classList.remove('current');
17-
}
18-
}
19-
element.classList.toggle('current');
20-
}
21-
22-
// add toggle icon to a-tags of menu items in .toc navigations
23-
function makeMenuExpandable() { 'use strict';
24-
var tocs = document.getElementsByClassName('toc');
25-
for (var i = 0; i < tocs.length; i++) {
26-
var links = tocs[i].getElementsByTagName('a');
27-
for (var ii = 0; ii < links.length; ii++) {
28-
if (links[ii].nextSibling) {
29-
var expand = document.createElement('span');
30-
expand.classList.add('toctree-expand');
31-
expand.addEventListener('click', toggleCurrent, true);
32-
links[ii].prepend(expand);
33-
}
34-
}
35-
}
36-
}
37-
makeMenuExpandable();
38-
39-
40-
// wrap tables to make them responsive
41-
function makeTablesResponsive() { 'use strict';
42-
var tables = document.querySelectorAll('.rst-content table.docutils');
43-
for (var i = 0; i < tables.length; i++) {
44-
var wrapper = document.createElement('div');
45-
wrapper.classList.add('table-responsive');
46-
tables[i].parentNode.insertBefore(wrapper, tables[i]);
47-
wrapper.appendChild(tables[i]);
48-
}
49-
}
50-
makeTablesResponsive();
51-
52-
53-
jQuery(document).ready(function () { 'use strict';
1+
jQuery(document).ready(function () {
2+
'use strict';
543

554
function setVersionContent(content) {
565
var options = document.createElement('dl');
@@ -85,9 +34,6 @@ jQuery(document).ready(function () { 'use strict';
8534
});
8635
}
8736

88-
// start with collapsed menu on a TYPO3 Exceptions page
89-
jQuery('li.toctree-l1.current').filter(":contains('TYPO3 Exceptions')").removeClass('current');
90-
9137
// fill in version hints
9238
if (!!DOCUMENTATION_OPTIONS && !!DOCUMENTATION_OPTIONS.URL_ROOT) {
9339
var coll = document.getElementsByClassName('version-hints-inner');
@@ -100,5 +46,4 @@ jQuery(document).ready(function () { 'use strict';
10046
});
10147
}
10248
}
103-
10449
});

packages/typo3-docs-theme/resources/public/js/theme.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)