fix calc better
This commit is contained in:
parent
eda3fb18fd
commit
6cf9826277
|
@ -1,40 +1,51 @@
|
||||||
/* global $ $$ */// dom.js
|
/* global $ $$ */// dom.js
|
||||||
/* global editor */
|
/* global editor */
|
||||||
|
/* global debounce */// toolbox.js
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function HeaderResizer() {
|
(function HeaderResizer() {
|
||||||
const PREF_ID = 'editor.headerWidth';
|
const PREF_ID = 'editor.headerWidth';
|
||||||
const el = $('#header-resizer');
|
const el = $('#header-resizer');
|
||||||
let curW, offset;
|
let curW, offset, active;
|
||||||
prefs.subscribe(PREF_ID, (key, val) => {
|
prefs.subscribe(PREF_ID, (key, val) => {
|
||||||
rememberCurWidth();
|
if (!active && val !== curW) {
|
||||||
setWidth(val);
|
getCurWidth();
|
||||||
|
setWidth(val);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
el.onmousedown = e => {
|
el.onmousedown = e => {
|
||||||
if (e.button) return;
|
if (e.button) return;
|
||||||
rememberCurWidth();
|
getCurWidth();
|
||||||
offset = curW - e.clientX;
|
offset = curW - e.clientX;
|
||||||
|
active = true;
|
||||||
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 rememberCurWidth() {
|
function getCurWidth() {
|
||||||
curW = $('#header').offsetWidth;
|
curW = parseFloat(document.documentElement.style.getPropertyValue('--header-width'))
|
||||||
|
|| $('#header').offsetWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resize({clientX: x}) {
|
function resize({clientX: x}) {
|
||||||
prefs.set(PREF_ID, setWidth(offset + x));
|
if (setWidth(offset + x)) {
|
||||||
|
debounce(save, 250);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
prefs.set(PREF_ID, curW);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {number|void} new width in case it's different, otherwise void */
|
|
||||||
function setWidth(w) {
|
function setWidth(w) {
|
||||||
const delta = (w = editor.updateHeaderWidth(w)) - curW;
|
const delta = (w = editor.updateHeaderWidth(w)) - curW;
|
||||||
if (delta) {
|
if (delta) {
|
||||||
|
@ -42,7 +53,7 @@
|
||||||
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;
|
||||||
}
|
}
|
||||||
return w;
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user