From e40cd2a8092835267a25d89a2a8543ebfd062a2d Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 9 Apr 2022 19:20:09 +0200 Subject: [PATCH] optimize window resizing --- copyparty/web/browser.js | 14 ++++++++++++-- copyparty/web/up2k.js | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 866d65ce..63231236 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -703,8 +703,12 @@ var widget = (function () { return false; clmod(document.documentElement, 'np_open', is_open); - widget.className = is_open ? 'open' : ''; + clmod(widget, 'open', is_open); bcfg_set('au_open', r.is_open = is_open); + if (window.vbar) { + pbar.onresize(); + vbar.onresize(); + } return true; }; r.toggle = function (e) { @@ -753,7 +757,7 @@ var widget = (function () { }; r.set(sread('au_open') == 1); setTimeout(function () { - clmod(ebi('widget'), 'anim', 1); + clmod(widget, 'anim', 1); }, 10); return r; })(); @@ -794,6 +798,9 @@ var pbar = (function () { grad; r.onresize = function () { + if (!widget.is_open && r.buf) + return; + r.buf = canvas_cfg(ebi('barbuf')); r.pos = canvas_cfg(ebi('barpos')); r.drawbuf(); @@ -895,6 +902,9 @@ var vbar = (function () { can, ctx, w, h, grad1, grad2; r.onresize = function () { + if (!widget.is_open && r.can) + return; + r.can = canvas_cfg(ebi('pvol')); can = r.can.can; ctx = r.can.ctx; diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index e1ad5720..999ebef8 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -1933,6 +1933,7 @@ function up2k_init(subtle) { // function onresize(e) { + // 10x faster than matchMedia('(min-width var bar = ebi('ops'), wpx = window.innerWidth, fpx = parseInt(getComputedStyle(bar)['font-size']), @@ -1942,7 +1943,6 @@ function up2k_init(subtle) { parent = ebi(wide && write ? 'u2btn_cw' : 'u2btn_ct'), btn = ebi('u2btn'); - //console.log([wpx, fpx, wem]); if (btn.parentNode !== parent) { parent.appendChild(btn); ebi('u2conf').setAttribute('class', wide);