simplify
This commit is contained in:
parent
228e77badc
commit
9327d161f5
|
@ -479,7 +479,7 @@ const dom = {};
|
||||||
HW,
|
HW,
|
||||||
HWprefId,
|
HWprefId,
|
||||||
setHWProp(width) {
|
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');
|
elHtml.style.setProperty('--header-width', width + 'px');
|
||||||
return width;
|
return width;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,46 +1,32 @@
|
||||||
/* global $ $$ dom */// dom.js
|
/* global $ $$ dom */// dom.js
|
||||||
/* global debounce */// toolbox.js
|
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
let curW, offset, active;
|
let curW = $('#header').offsetWidth;
|
||||||
prefs.subscribe(dom.HWprefId, (key, val) => {
|
let offset, perPage;
|
||||||
if (!active && val !== curW) {
|
prefs.subscribe(dom.HWprefId, (key, val) => setWidth(val));
|
||||||
getCurWidth();
|
|
||||||
setWidth(val);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('#header-resizer').onmousedown = e => {
|
$('#header-resizer').onmousedown = e => {
|
||||||
if (e.button) return;
|
if (e.button) return;
|
||||||
getCurWidth();
|
|
||||||
offset = curW - e.clientX;
|
offset = curW - e.clientX;
|
||||||
active = true;
|
perPage = e.shiftKey;
|
||||||
document.body.classList.add('resizing-h');
|
document.body.classList.add('resizing-h');
|
||||||
document.on('mousemove', resize);
|
document.on('mousemove', resize);
|
||||||
document.on('mouseup', resizeStop);
|
document.on('mouseup', resizeStop);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCurWidth() {
|
|
||||||
curW = parseFloat(document.documentElement.style.getPropertyValue('--header-width'))
|
|
||||||
|| $('#header').offsetWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param {MouseEvent} e */
|
|
||||||
function resize(e) {
|
function resize(e) {
|
||||||
if (setWidth(offset + e.clientX)) {
|
setWidth(offset + e.clientX);
|
||||||
debounce(save, 250, e.shiftKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeStop() {
|
function resizeStop() {
|
||||||
document.off('mouseup', resizeStop);
|
document.off('mouseup', resizeStop);
|
||||||
document.off('mousemove', resize);
|
document.off('mousemove', resize);
|
||||||
document.body.classList.remove('resizing-h');
|
document.body.classList.remove('resizing-h');
|
||||||
active = false;
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function save(perPage) {
|
function save() {
|
||||||
if (perPage) {
|
if (perPage) {
|
||||||
prefs.set(dom.HWprefId, curW);
|
prefs.set(dom.HWprefId, curW);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +43,6 @@
|
||||||
for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) {
|
for (const el of $$('.CodeMirror-linewidget[style*="width:"]')) {
|
||||||
el.style.width = parseFloat(el.style.width) - delta + 'px';
|
el.style.width = parseFloat(el.style.width) - delta + 'px';
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user