|
1
|
/* |
|
2
|
* This script adds a checkbox to reverse the sorting on any body.tkt |
|
3
|
* pages which contain a .tktCommentArea element. |
|
4
|
*/ |
|
5
|
window.addEventListener( 'load', function() { |
|
6
|
const tgt = document.querySelectorAll('.tktCommentArea'); |
|
7
|
if( !tgt ) return; |
|
8
|
const F = globalThis.fossil, D = F.dom; |
|
9
|
let i = 0; |
|
10
|
for(const e of tgt) { |
|
11
|
++i; |
|
12
|
const childs = e.querySelectorAll('.tktCommentEntry'); |
|
13
|
if( !childs || 1===childs.length ) continue; |
|
14
|
const cbReverseKey = 'tktCommentArea:reverse'; |
|
15
|
const cbReverse = D.checkbox(); |
|
16
|
const cbId = cbReverseKey+':'+i; |
|
17
|
cbReverse.setAttribute('id',cbId); |
|
18
|
const widget = D.append( |
|
19
|
D.div(), |
|
20
|
cbReverse, |
|
21
|
D.label(cbReverse, " Show newest first? ") |
|
22
|
); |
|
23
|
widget.classList.add('newest-first-controls'); |
|
24
|
e.parentElement.insertBefore(widget,e); |
|
25
|
const cbReverseIt = ()=>{ |
|
26
|
e.classList[cbReverse.checked ? 'add' : 'remove']('reverse'); |
|
27
|
F.storage.set(cbReverseKey, cbReverse.checked ? 1 : 0); |
|
28
|
}; |
|
29
|
cbReverse.addEventListener('change', cbReverseIt, true); |
|
30
|
cbReverse.checked = !!(+F.storage.get(cbReverseKey, 0)); |
|
31
|
}; |
|
32
|
}); // window.addEventListener( 'load' ... |
|
33
|
|