From 9838c2f0ce7bf5d7bc96dd0aecafe5beb7b78273 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 24 Apr 2022 23:47:15 +0200 Subject: [PATCH] golf --- copyparty/web/browser.html | 2 +- copyparty/web/browser.js | 24 ++++++++++++------------ copyparty/web/md.html | 2 +- copyparty/web/md.js | 8 ++++---- copyparty/web/md2.js | 22 +++++++++++----------- copyparty/web/mde.html | 2 +- copyparty/web/splash.html | 2 +- copyparty/web/up2k.js | 12 +++++------- copyparty/web/util.js | 2 +- 9 files changed, 37 insertions(+), 39 deletions(-) diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 3424df47..11155c29 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -151,7 +151,7 @@ readme = {{ readme|tojson }}, ls0 = {{ ls0|tojson }}; - document.documentElement.setAttribute("class", localStorage.theme || dtheme); + document.documentElement.className = localStorage.theme || dtheme; diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 0bb5ec07..27dbdb5e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -2508,7 +2508,7 @@ var showfile = (function () { el = el || QS('#doc>code'); Prism.highlightElement(el); - if (el.getAttribute('class') == 'language-ans') + if (el.className == 'language-ans') r.ansify(el); } catch (ex) { } @@ -2529,7 +2529,7 @@ var showfile = (function () { el.textContent = txt; el.innerHTML = '' + el.innerHTML + ''; if (!window['no_prism']) { - el.setAttribute('class', 'prism linkable-line-numbers line-numbers language-' + lang); + el.className = 'prism linkable-line-numbers line-numbers language-' + lang; if (!defer) fun(el.firstChild); else @@ -2659,7 +2659,7 @@ var showfile = (function () { }; var bdoc = ebi('bdoc'); - bdoc.setAttribute('class', 'line-numbers'); + bdoc.className = 'line-numbers'; bdoc.innerHTML = ( '
\n' + '❌ close\n' + @@ -2854,12 +2854,12 @@ var thegrid = (function () { for (var a = 0, aa = ths.length; a < aa; a++) { var tr = ebi(ths[a].getAttribute('ref')).closest('tr'), - cl = tr.getAttribute('class') || ''; + cl = tr.className || ''; if (noq_href(ths[a]).endsWith('/')) cl += ' dir'; - ths[a].setAttribute('class', cl); + ths[a].className = cl; } var uns = QS('#ggrid a[ref="unsearch"]'); if (uns) @@ -3876,7 +3876,7 @@ var treectl = (function () { cl = 'par'; } - links[a].setAttribute('class', cl); + links[a].className = cl; links[a].onclick = treego; links[a].onmouseenter = nowrap ? menter : null; links[a].onmouseleave = nowrap ? mleave : null; @@ -3943,7 +3943,7 @@ var treectl = (function () { return true; ev(e); - if (this.getAttribute('class') == 'hl' && + if (this.className == 'hl' && this.previousSibling.textContent == '-') { treegrow.call(this.previousSibling, e); return; @@ -4209,7 +4209,7 @@ var treectl = (function () { function enspin(sel) { despin(sel); var d = mknod('div'); - d.setAttribute('class', 'dumb_loader_thing'); + d.className = 'dumb_loader_thing'; d.innerHTML = '🌲'; var tgt = QS(sel); tgt.insertBefore(d, tgt.childNodes[0]); @@ -4315,7 +4315,7 @@ function find_file_col(txt) { for (var a = 0; a < tds.length; a++) { var spans = tds[a].getElementsByTagName('span'); if (spans.length && spans[0].textContent == txt) { - min = (tds[a].getAttribute('class') || '').indexOf('min') !== -1; + min = (tds[a].className || '').indexOf('min') !== -1; i = a; break; } @@ -4461,7 +4461,7 @@ var filecols = (function () { tds = QSA('#files>tbody>tr>td:nth-child(' + (a + 1) + ')'); for (var b = 0, bb = tds.length; b < bb; b++) - tds[b].setAttribute('class', cls); + tds[b].className = cls; } if (window['tt']) { tt.att(ebi('hcols')); @@ -4623,9 +4623,9 @@ var settheme = (function () { light = !!(theme.indexOf('y') + 1); function freshen() { - var cl = document.documentElement.getAttribute('class'); + var cl = document.documentElement.className; cl = cl.replace(/\b(light|dark|[a-z]{1,2})\b/g, '').replace(/ +/g, ' '); - document.documentElement.setAttribute('class', cl + ' ' + theme + ' '); + document.documentElement.className = cl + ' ' + theme + ' '; pbar.drawbuf(); pbar.drawpos(); diff --git a/copyparty/web/md.html b/copyparty/web/md.html index 01c3223f..dba71e50 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -140,7 +140,7 @@ var md_opt = { btn = document.getElementById("lightswitch"), f = function (e) { if (e) { e.preventDefault(); drk = !drk; } -document.documentElement.setAttribute("class", drk? "z":"y"); +document.documentElement.className = drk? "z":"y"; btn.innerHTML = "go " + (drk ? "light":"dark"); l.light = drk? 0:1; }; diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 355a16c2..2b11d248 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -278,7 +278,7 @@ function convert_markdown(md_text, dest_dom) { if (!txt) nodes[a].textContent = href; else if (href !== txt) - nodes[a].setAttribute('class', 'vis'); + nodes[a].className = 'vis'; } // todo-lists (should probably be a marked extension) @@ -294,7 +294,7 @@ function convert_markdown(md_text, dest_dom) { var clas = done ? 'done' : 'pend'; var char = done ? 'Y' : 'N'; - dom_li.setAttribute('class', 'task-list-item'); + dom_li.className = 'task-list-item'; dom_li.style.listStyleType = 'none'; var html = dom_li.innerHTML; dom_li.innerHTML = @@ -468,11 +468,11 @@ function init_toc() { for (var a = 0; a < anchors.length; a++) { if (anchors[a].active) { anchors[a].active = false; - links[a].setAttribute('class', ''); + links[a].className = ''; } } anchors[hit].active = true; - links[hit].setAttribute('class', 'act'); + links[hit].className = 'act'; } var pane_height = parseInt(getComputedStyle(dom_toc).height); diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index 899f0022..d584a30f 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -144,16 +144,16 @@ redraw = (function () { map_pre = genmap(dom_pre, map_pre); } function setsbs() { - dom_wrap.setAttribute('class', ''); - dom_swrap.setAttribute('class', ''); + dom_wrap.className = ''; + dom_swrap.className = ''; onresize(); } function modetoggle() { var mode = dom_nsbs.innerHTML; dom_nsbs.innerHTML = mode == 'editor' ? 'preview' : 'editor'; mode += ' single'; - dom_wrap.setAttribute('class', mode); - dom_swrap.setAttribute('class', mode); + dom_wrap.className = mode; + dom_swrap.className = mode; onresize(); } @@ -309,7 +309,7 @@ var modpoll = new Modpoll(); window.onbeforeunload = function (e) { - if ((ebi("save").getAttribute('class') + '').indexOf('disabled') >= 0) + if ((ebi("save").className + '').indexOf('disabled') >= 0) return; //nice (todo) e.preventDefault(); //ff @@ -321,7 +321,7 @@ window.onbeforeunload = function (e) { function save(e) { if (e) e.preventDefault(); var save_btn = ebi("save"), - save_cls = save_btn.getAttribute('class') + ''; + save_cls = save_btn.className + ''; if (save_cls.indexOf('disabled') >= 0) return toast.inf(2, "no changes"); @@ -678,7 +678,7 @@ function reLastIndexOf(txt, ptn, end) { // table formatter function fmt_table(e) { if (e) e.preventDefault(); - //dom_tbox.setAttribute('class', ''); + //dom_tbox.className = ''; var txt = dom_src.value, ofs = dom_src.selectionStart, @@ -829,7 +829,7 @@ function fmt_table(e) { // show unicode function mark_uni(e) { if (e) e.preventDefault(); - dom_tbox.setAttribute('class', ''); + dom_tbox.className = ''; var txt = dom_src.value, ptn = new RegExp('([^' + js_uni_whitelist + ']+)', 'g'), @@ -989,14 +989,14 @@ var set_lno = (function () { ebi('tools').onclick = function (e) { if (e) e.preventDefault(); - var is_open = dom_tbox.getAttribute('class') != 'open'; - dom_tbox.setAttribute('class', is_open ? 'open' : ''); + var is_open = dom_tbox.className != 'open'; + dom_tbox.className = is_open ? 'open' : ''; }; ebi('help').onclick = function (e) { if (e) e.preventDefault(); - dom_tbox.setAttribute('class', ''); + dom_tbox.className = ''; var dom = ebi('helpbox'); var dtxt = dom.getElementsByTagName('textarea'); diff --git a/copyparty/web/mde.html b/copyparty/web/mde.html index 0ca9b582..5a604476 100644 --- a/copyparty/web/mde.html +++ b/copyparty/web/mde.html @@ -37,7 +37,7 @@ var lightswitch = (function () { drk = l.light != 1, f = function (e) { if (e) drk = !drk; -document.documentElement.setAttribute("class", drk? "z":"y"); +document.documentElement.className = drk? "z":"y"; l.light = drk? 0:1; }; f(); diff --git a/copyparty/web/splash.html b/copyparty/web/splash.html index 366d6691..f8a9caf4 100644 --- a/copyparty/web/splash.html +++ b/copyparty/web/splash.html @@ -97,7 +97,7 @@ π diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 01e8311d..83149610 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -624,11 +624,11 @@ function up2k_init(subtle) { function setmsg(msg, type) { if (msg !== undefined) { - ebi('u2err').setAttribute('class', type); + ebi('u2err').className = type; ebi('u2err').innerHTML = msg; } else { - ebi('u2err').setAttribute('class', ''); + ebi('u2err').className = ''; ebi('u2err').innerHTML = ''; } if (msg == suggest_up2k) { @@ -1938,19 +1938,17 @@ function up2k_init(subtle) { if (btn.parentNode !== parent) { parent.appendChild(btn); - ebi('u2conf').setAttribute('class', wide); - ebi('u2cards').setAttribute('class', wide); - ebi('u2etaw').setAttribute('class', wide); + ebi('u2conf').className = ebi('u2cards').className = ebi('u2etaw').className = wide; } wide = write && wem > 78 ? 'ww' : wide; parent = ebi(wide == 'ww' && write ? 'u2c3w' : 'u2c3t'); var its = [ebi('u2etaw'), ebi('u2cards')]; if (its[0].parentNode !== parent) { - ebi('u2conf').setAttribute('class', wide); + ebi('u2conf').className = wide; for (var a = 0; a < 2; a++) { parent.appendChild(its[a]); - its[a].setAttribute('class', wide); + its[a].className = wide; } } } diff --git a/copyparty/web/util.js b/copyparty/web/util.js index e11e8ddd..f4d89645 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -327,7 +327,7 @@ function clgot(el, cls) { if (el.classList) return el.classList.contains(cls); - var lst = (el.getAttribute('class') + '').split(/ /g); + var lst = (el.className + '').split(/ /g); return has(lst, cls); }