Skip to content

Commit f124942

Browse files
committed
Expand all nodes when pressing ctrl+f.
1 parent 09c1308 commit f124942

File tree

3 files changed

+61
-38
lines changed

3 files changed

+61
-38
lines changed

resources/compiled/sage.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.

resources/js/base.js

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,19 @@ if (typeof _sageInitialized === 'undefined') {
1717
Array.prototype.slice.call(document.querySelectorAll(selector), 0).forEach(callback)
1818
},
1919

20-
hasClass: function (target, className) {
21-
if (!target.classList) return false;
22-
23-
if (typeof className === 'undefined') {
24-
className = '_sage-show';
20+
hasClass: function (target, className = '_sage-show') {
21+
if (!target.classList) {
22+
return false;
2523
}
24+
2625
return target.classList.contains(className);
2726
},
2827

29-
addClass: function (target, className) {
30-
if (typeof className === 'undefined') {
31-
className = '_sage-show';
32-
}
28+
addClass: function (target, className = '_sage-show') {
3329
target.classList.add(className);
3430
},
3531

36-
removeClass: function (target, className) {
37-
if (typeof className === 'undefined') {
38-
className = '_sage-show';
39-
}
32+
removeClass: function (target, className = '_sage-show') {
4033
target.classList.remove(className);
4134
return target;
4235
},
@@ -87,13 +80,16 @@ if (typeof _sageInitialized === 'undefined') {
8780
_sage.toggle(element, hide);
8881
},
8982

90-
toggleAll: function (caret) {
83+
toggleAll: function (show) {
9184
const elements = document.getElementsByClassName('_sage-parent')
9285
let i = elements.length
93-
const visible = _sage.hasClass(caret.parentNode);
9486

9587
while (i--) {
96-
_sage.toggle(elements[i], visible);
88+
if (show) {
89+
_sage.addClass(elements[i]);
90+
} else {
91+
_sage.removeClass(elements[i]);
92+
}
9793
}
9894
},
9995

@@ -115,7 +111,9 @@ if (typeof _sageInitialized === 'undefined') {
115111
isSibling: function (el) {
116112
for (; ;) {
117113
el = el.parentNode;
118-
if (!el || _sage.hasClass(el, '_sage')) break;
114+
if (!el || _sage.hasClass(el, '_sage')) {
115+
break;
116+
}
119117
}
120118

121119
return !!el;
@@ -216,11 +214,13 @@ if (typeof _sageInitialized === 'undefined') {
216214
}
217215
};
218216

219-
window.addEventListener("click", function (e) {
217+
window.addEventListener('click', function (e) {
220218
let target = e.target
221219
, tagName = target.tagName;
222220

223-
if (!_sage.isSibling(target)) return;
221+
if (!_sage.isSibling(target)) {
222+
return;
223+
}
224224

225225
// auto-select name of variable
226226
if (tagName === 'DFN') {
@@ -240,7 +240,9 @@ if (typeof _sageInitialized === 'undefined') {
240240
if (tagName === 'LI' && target.parentNode.className === '_sage-tabs') {
241241
if (target.className !== '_sage-active-tab') {
242242
_sage.switchTab(target);
243-
if (_sage.currentPlus !== -1) _sage.fetchVisiblePluses();
243+
if (_sage.currentPlus !== -1) {
244+
_sage.fetchVisiblePluses();
245+
}
244246
}
245247
return false;
246248
}
@@ -259,7 +261,9 @@ if (typeof _sageInitialized === 'undefined') {
259261
target._sageTimer--;
260262
} else {
261263
_sage.toggleChildren(target.parentNode); // <dt>
262-
if (_sage.currentPlus !== -1) _sage.fetchVisiblePluses();
264+
if (_sage.currentPlus !== -1) {
265+
_sage.fetchVisiblePluses();
266+
}
263267
}
264268
}, 300);
265269
}
@@ -268,7 +272,9 @@ if (typeof _sageInitialized === 'undefined') {
268272
return false;
269273
} else if (_sage.hasClass(target, '_sage-parent')) {
270274
_sage.toggle(target);
271-
if (_sage.currentPlus !== -1) _sage.fetchVisiblePluses();
275+
if (_sage.currentPlus !== -1) {
276+
_sage.fetchVisiblePluses();
277+
}
272278
return false;
273279
} else if (_sage.hasClass(target, '_sage-ide-link')) {
274280
fetch(target.href);
@@ -289,29 +295,38 @@ if (typeof _sageInitialized === 'undefined') {
289295
}
290296
}, false);
291297

292-
window.addEventListener("dblclick", function (e) {
298+
window.addEventListener('dblclick', function (e) {
293299
const target = e.target;
294-
if (!_sage.isSibling(target)) return;
300+
if (!_sage.isSibling(target)) {
301+
return;
302+
}
295303

296304
if (target.tagName === 'NAV') {
297305
target._sageTimer = 2;
298-
_sage.toggleAll(target);
299-
if (_sage.currentPlus !== -1) _sage.fetchVisiblePluses();
306+
_sage.toggleAll(_sage.hasClass(target));
307+
if (_sage.currentPlus !== -1) {
308+
_sage.fetchVisiblePluses();
309+
}
300310
e.stopPropagation();
301311
}
302312
}, false);
303313

304314
// keyboard navigation
305315
window.onkeydown = function (e) { // direct assignment is used to have priority over ex FAYT
306-
307-
// do nothing if alt/ctrl key is pressed or if we're actually typing somewhere
308-
if (["INPUT", "TEXTAREA"].includes(e.target.tagName) || e.altKey || e.ctrlKey) return;
309-
310316
// todo use e.key https://www.toptal.com/developers/keycode
311-
const keyCode = e.keyCode
312-
, shiftKey = e.shiftKey
317+
const keyCode = e.keyCode;
313318
let i = _sage.currentPlus;
314319

320+
// user pressed ctrl+f
321+
if (keyCode === 70 && e.ctrlKey) {
322+
_sage.toggleAll(true);
323+
return;
324+
}
325+
326+
// do nothing if alt/ctrl key is pressed or if we're actually typing somewhere
327+
if (['INPUT', 'TEXTAREA'].includes(e.target.tagName) || e.altKey || e.ctrlKey) {
328+
return;
329+
}
315330

316331
if (keyCode === 9) { // TAB jumps out of navigation
317332
_sage.keyCallBacks.cleanup(-1);
@@ -327,7 +342,9 @@ if (typeof _sageInitialized === 'undefined') {
327342
return false;
328343
}
329344
} else {
330-
if (i === -1) return;
345+
if (i === -1) {
346+
return;
347+
}
331348

332349
if (keyCode === 38) { // ARROW UP : moves up
333350
return _sage.keyCallBacks.moveCursor(true, i);
@@ -398,16 +415,20 @@ if (typeof _sageInitialized === 'undefined') {
398415
}
399416
};
400417

401-
window.addEventListener("load", function () { // colorize microtime results relative to others
418+
window.addEventListener('load', function () { // colorize microtime results relative to others
402419
const elements = Array.prototype.slice.call(document.querySelectorAll('._sage-microtime'), 0);
403420
let min = Infinity
404421
, max = -Infinity;
405422

406423
elements.forEach(function (el) {
407424
const val = parseFloat(el.innerHTML);
408425

409-
if (min > val) min = val;
410-
if (max < val) max = val;
426+
if (min > val) {
427+
min = val;
428+
}
429+
if (max < val) {
430+
max = val;
431+
}
411432
});
412433

413434
elements.forEach(function (el) {
@@ -421,7 +442,9 @@ if (typeof _sageInitialized === 'undefined') {
421442

422443
// debug purposes only, removed in minified source
423444
function clg(i) {
424-
if (!window.console) return;
445+
if (!window.console) {
446+
return;
447+
}
425448
const l = arguments.length;
426449
let o = 0;
427450
while (o < l) console.log(arguments[o++])

sage.phar

-39 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)