function escapeXML(text) { return $("").text(text).html(); } async function pollRetractVote(id) { let poll = $(`.poll[data-id=${id}]`); poll.addClass("loading"); try { let html = (await API.Polls.unvote(poll.data("id"))).html; poll.prop("outerHTML", html); } catch(e) { MessageBox(tr("error"), "Sorry: " + e.message, ["OK"], [Function.noop]); } finally { poll.removeClass("loading"); } } async function pollFormSubmit(e, form) { e.preventDefault(); form = $(form); let options; let isMultiple = form.data("multi"); let pollId = form.data("pid"); let formData = form.serializeArray(); if(!isMultiple) { options = [Number(formData[0].value)]; } else { options = []; formData.forEach(function(record) { if(!record.name.startsWith("option") || record.value !== "on") return; options.push(Number(record.name.substr(6))); }); } let poll = form.parent(); poll.addClass("loading"); try { let html = (await API.Polls.vote(pollId, options.join(","))).html; poll.prop("outerHTML", html); } catch(e) { MessageBox(tr("error"), "Sorry: " + e.message, ["OK"], [Function.noop]); } finally { poll.removeClass("loading"); } } function pollCheckBoxPressed(cb) { cb = $(cb); let form = cb.parent().parent().parent().parent(); let checked = $("input:checked", form); if(checked.length >= 1) $("input[type=submit]", form).removeAttr("disabled"); else $("input[type=submit]", form).attr("disabled", "disabled"); } function pollRadioPressed(radio) { let form = $(radio).parent().parent().parent().parent(); form.submit(); } function initPoll(event) { let form = $(event.target.closest('.post-buttons')).parent(); const id = random_int(0, 100) let mBody = `