Fossil SCM

fossil-scm / src / fossil.page.wcontent.js
Blame History Raw 52 lines
1
/* This script implements interactivity of checkboxes that
2
* toggle visibilitiy of user-defined classes of wikipage.
3
*
4
* For the sake of compatibility with ascetic browsers the code tries
5
* to avoid modern API and ECMAScript constructs. This makes it less
6
* readable and may be reconsidered in the future.
7
*/
8
window.addEventListener( 'load', function() {
9
10
var tbody = document.querySelector(
11
"body.wiki div.content table.sortable > tbody");
12
var prc = document.getElementById("page-reload-canary");
13
if( !tbody || !prc ) return;
14
15
var reloading = prc.checked;
16
// console.log("Reloading:",reloading);
17
18
var onChange = function(event){
19
var display = event.target.checked ? "" : "none";
20
var rows = event.target.matchingRows;
21
for(var i=0; i<rows.length; i++)
22
rows[i].style.display = display;
23
}
24
var checkboxes = [];
25
document.querySelectorAll(
26
"body.wiki .submenu > label.submenuckbox > input")
27
.forEach(function(cbx){ checkboxes.push(cbx); });
28
29
for(var j=0; j<checkboxes.length; j++){
30
var cbx = checkboxes[j];
31
// see also https://caniuse.com/mdn-css_selectors_attribute
32
var attr = cbx.getAttribute("data-ctrl");
33
if( 'undefined' == typeof attr || !attr ) continue;
34
var ctrl = attr.toString();
35
var cname = cbx.parentElement.innerText.toString();
36
var hidden = ( ctrl == 'h' || ctrl == 'd' );
37
if( reloading )
38
hidden = !cbx.checked;
39
else
40
cbx.checked = !hidden;
41
cbx.matchingRows = [];
42
tbody.querySelectorAll("tr."+cname).forEach(function (tr){
43
tr.style.display = ( hidden ? "none" : "" );
44
cbx.matchingRows.push(tr);
45
});
46
cbx.addEventListener("change", onChange );
47
// console.log( cbx.matchingRows.length, cname, ctrl );
48
}
49
50
prc.checked = true;
51
}); // window.addEventListener( 'load' ...
52

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button