1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
function checkbox_clicked(el) {
window.webkit.messageHandlers.toPython.postMessage(
{type: 'checkbox', id: el.id, checked: el.checked});
}
function task_div_clicked(event, id) {
if (event.target.nodeName === 'A')
return;
el = document.getElementById(id);
el.checked = !el.checked;
window.webkit.messageHandlers.toPython.postMessage(
{type: 'checkbox', id: el.id, checked: el.checked});
}
function add_checkbox_handlers() {
const selectors = document.querySelectorAll('input[type=checkbox]');
for (const el of selectors) {
el.onclick = function(){checkbox_clicked(el)};
outerDiv = el.nextSibling;
div = outerDiv.firstChild;
div.onclick = function(){task_div_clicked(event, el.getAttribute('id'))};
if (div.innerHTML.startsWith(' '))
div.innerHTML = div.innerHTML.trim();
}
}
var scroll_update_queued = false;
function on_scroll() {
if (!scroll_update_queued) {
scroll_update_queued = true;
setTimeout(send_scroll_position, 250);
}
}
function send_scroll_position() {
window.webkit.messageHandlers.toPython.postMessage(
{type: 'scrollPosition', position: get_scroll_position_proportion()});
scroll_update_queued = false;
}
function get_scroll_position_proportion() {
let el = document.documentElement;
return el.scrollTop / (el.scrollHeight - el.clientHeight);
}
window.onload = function() {
if (%s)
add_checkbox_handlers();
window.addEventListener('scroll', on_scroll);
%s
}
|