From 9327d161f5c8047208a039a7b20c1066d561b184 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 12 Jan 2022 20:36:29 +0300 Subject: [PATCH] simplify --- js/dom.js | 2 +- js/header-resizer.js | 29 +++++++---------------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/js/dom.js b/js/dom.js index 7a4deb19..612acf71 100644 --- a/js/dom.js +++ b/js/dom.js @@ -479,7 +479,7 @@ const dom = {}; HW, HWprefId, setHWProp(width) { - width = Math.round(Math.max(200, Math.min(innerWidth / 2, Number(width) || 0))); + width = Math.round(Math.max(200, Math.min(innerWidth / 3, Number(width) || 0))); elHtml.style.setProperty('--header-width', width + 'px'); return width; }, diff --git a/js/header-resizer.js b/js/header-resizer.js index cd36063c..0017b4d4 100644 --- a/js/header-resizer.js +++ b/js/header-resizer.js @@ -1,46 +1,32 @@ /* global $ $$ dom */// dom.js -/* global debounce */// toolbox.js /* global prefs */ 'use strict'; (() => { - let curW, offset, active; - prefs.subscribe(dom.HWprefId, (key, val) => { - if (!active && val !== curW) { - getCurWidth(); - setWidth(val); - } - }); + let curW = $('#header').offsetWidth; + let offset, perPage; + prefs.subscribe(dom.HWprefId, (key, val) => setWidth(val)); $('#header-resizer').onmousedown = e => { if (e.button) return; - getCurWidth(); offset = curW - e.clientX; - active = true; + perPage = e.shiftKey; document.body.classList.add('resizing-h'); document.on('mousemove', resize); document.on('mouseup', resizeStop); }; - function getCurWidth() { - curW = parseFloat(document.documentElement.style.getPropertyValue('--header-width')) - || $('#header').offsetWidth; - } - - /** @param {MouseEvent} e */ function resize(e) { - if (setWidth(offset + e.clientX)) { - debounce(save, 250, e.shiftKey); - } + setWidth(offset + e.clientX); } function resizeStop() { document.off('mouseup', resizeStop); document.off('mousemove', resize); document.body.classList.remove('resizing-h'); - active = false; + save(); } - function save(perPage) { + function save() { if (perPage) { prefs.set(dom.HWprefId, curW); } else { @@ -57,7 +43,6 @@ for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) { el.style.width = parseFloat(el.style.width) - delta + 'px'; } - return true; } } })();