This commit is contained in:
tophf 2022-01-12 20:36:29 +03:00
parent 228e77badc
commit 9327d161f5
2 changed files with 8 additions and 23 deletions

View File

@ -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;
},

View File

@ -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;
}
}
})();