diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index 845cadf8..0a8b8c2a 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -530,9 +530,7 @@ window.baguetteBox = (function () { if (options.bodyClass && document.body.classList) document.body.classList.remove(options.bodyClass); - var h = ebi('bbox-halp'); - if (h) - h.parentNode.removeChild(h); + qsr('#bbox-halp'); if (options.afterHide) options.afterHide(); @@ -590,8 +588,7 @@ window.baguetteBox = (function () { image.addEventListener(is_vid ? 'loadedmetadata' : 'load', function () { // Remove loader element - var spinner = QS('#baguette-img-' + index + ' .bbox-spinner'); - figure.removeChild(spinner); + qsr('#baguette-img-' + index + ' .bbox-spinner'); if (!options.async && callback) callback(); }); diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index eb00ee10..dfd4c309 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1600,7 +1600,7 @@ function eval_hash() { i.value = uricom_dec(v.slice(3))[0]; return i.oninput(); } -}; +} (function () { @@ -1649,7 +1649,7 @@ function sortfiles(nodes) { if (v.split('?')[0].slice(-1) == '/') v = '\t' + v; - v = uricom_dec(v)[0] + v = uricom_dec(v)[0]; } nodes[b]._sv = v; @@ -4109,10 +4109,7 @@ var msel = (function () { ''; frm.style.display = 'none'; - var oldform = QS('#widgeti>form'); - if (oldform) - oldform.parentNode.removeChild(oldform); - + qsr('#widgeti>form'); ebi('widgeti').appendChild(frm); var obj = ebi('ziptxt'); obj.value = txt; diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 35a96a1f..a985ff08 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -164,10 +164,7 @@ function copydom(src, dst, lv) { function md_plug_err(ex, js) { - var errbox = ebi('md_errbox'); - if (errbox) - errbox.parentNode.removeChild(errbox); - + qsr('#md_errbox'); if (!ex) return; @@ -183,7 +180,7 @@ function md_plug_err(ex, js) { o.textContent = lns[ln - 1]; } } - errbox = mknod('div'); + var errbox = mknod('div'); errbox.setAttribute('id', 'md_errbox'); errbox.style.cssText = 'position:absolute;top:0;left:0;padding:1em .5em;background:#2b2b2b;color:#fc5' errbox.textContent = msg; @@ -381,8 +378,7 @@ function convert_markdown(md_text, dest_dom) { function init_toc() { - var loader = ebi('ml'); - loader.parentNode.removeChild(loader); + qsr('#ml'); var anchors = []; // list of toc entries, complex objects var anchor = null; // current toc node diff --git a/copyparty/web/mde.js b/copyparty/web/mde.js index 6629ab05..12577c46 100644 --- a/copyparty/web/mde.js +++ b/copyparty/web/mde.js @@ -65,8 +65,7 @@ var mde = (function () { mde.codemirror.on("change", function () { md_changed(mde); }); - var loader = ebi('ml'); - loader.parentNode.removeChild(loader); + qsr('#ml'); return mde; })(); diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 36562a33..26940964 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -332,8 +332,7 @@ function U2pvis(act, btns) { r.head++; if (!bz_act) { - var tr = ebi("f" + nfile); - tr.parentNode.removeChild(tr); + qsr("#f" + nfile); } } else return; @@ -352,9 +351,7 @@ function U2pvis(act, btns) { last = parseInt(last.getAttribute('id').slice(1)); while (r.head - first > r.wsz) { - var obj = ebi('f' + (first++)); - if (obj) - obj.parentNode.removeChild(obj); + qsr('#f' + (first++)); } while (last - r.tail < r.wsz && last < r.tab.length - 2) { var obj = ebi('f' + (++last)); @@ -1075,11 +1072,9 @@ function up2k_init(subtle) { for (var a = 0; a < st.files.length; a++) { var t = st.files[a]; if (t.done && t.name) { - var tr = ebi('f' + t.n); - if (!tr) + if (!qsr('#f' + t.n)) continue; - tr.parentNode.removeChild(tr); t.name = undefined; } } diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 37add476..d783121c 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -18,6 +18,15 @@ var ebi = document.getElementById.bind(document), mknod = document.createElement.bind(document); +function qsr(sel) { + var el = QS(sel); + if (el) + el.parentNode.removeChild(el); + + return el; +} + + // error handler for mobile devices function esc(txt) { return txt.replace(/[&"<>]/g, function (c) {