dsel: refactor/cleanup

This commit is contained in:
icxes 2026-01-16 20:50:16 +02:00
parent 394a07c786
commit 70351c46e9
No known key found for this signature in database

View file

@ -9761,27 +9761,29 @@ function reload_browser() {
(function() { (function() {
var is_selma = false; var is_selma = false;
var dragging = false; var dragging = false;
var prevent_click = false;
var fwrapper = null;
var startx, starty; var startx, starty;
var fwrap = null;
var selbox = null; var selbox = null;
var ttimer = null; var ttimer = null;
var lpdelay = 250; var lpdelay = 250;
var mvthresh = 10; var mvthresh = 10;
function unbox() { function unbox() {
qsr('.selbox'); qsr('.selbox');
ebi('gfiles').style.removeProperty('pointer-events')
ebi('wrap').style.removeProperty('user-select')
if (fwrapper) { if (selbox) {
ebi("gfiles").style.userSelect = 'auto'; console.log(selbox)
fwrapper = null; window.getSelection().removeAllRanges();
} }
selbox = null;
dragging = false;
is_selma = false; is_selma = false;
dragging = false;
fwrap = null;
selbox = null;
ttimer = null; ttimer = null;
} }
@ -9807,56 +9809,45 @@ function reload_browser() {
b1.bottom < b2.top || b1.top > b2.bottom); b1.bottom < b2.top || b1.top > b2.bottom);
} }
function sel_excl(e, exclist) {
for (var id of exclist) {
if ((e.target && e.target.closest(id))) {
return true
}
}
return false
}
function sel_start(e) { function sel_start(e) {
if (e.button !== 0 && e.type !== 'touchstart') return; if (e.button !== 0 && e.type !== 'touchstart') return;
if (!thegrid.en || !treectl.dsel) return; if (!thegrid.en || !treectl.dsel) return;
if (sel_excl(e, ['#widget','#ops','.opview','.doc'])) return; if (e.target.closest('#widget,#ops,.opview,.doc')) return;
if (e.target.closest('#gfiles'))
ebi('gfiles').style.userSelect = "none"
var pos = getpp(e); var pos = getpp(e);
startx = pos.x; startx = pos.x;
starty = pos.y; starty = pos.y;
is_selma = true; is_selma = true;
ttimer = null; ttimer = null;
prevent_click = false;
fwrapper = e.target.closest('#wrap');
if (fwrapper) ebi('gfiles').style.userSelect = 'none';
if (e.type === 'touchstart') { if (e.type === 'touchstart') {
if (ttimer) clearTimeout(ttimer);
ttimer = setTimeout(function() { ttimer = setTimeout(function() {
ttimer = null; ttimer = null;
start_drag(pos); start_drag();
}, lpdelay); }, lpdelay);
} }
} }
function start_drag(pos) { function start_drag() {
if (dragging) return; if (dragging) return;
dragging = true; dragging = true;
selbox = document.createElement('div'); selbox = document.createElement('div');
selbox.className = 'selbox'; selbox.className = 'selbox';
document.body.appendChild(selbox); document.body.appendChild(selbox);
ebi('gfiles').style.pointerEvents = 'none';
} }
function sel_move(e) { function sel_move(e) {
if (!is_selma) return; if (!is_selma) return;
var pos = getpp(e); var pos = getpp(e);
if (e.type === 'touchmove') {
if (ttimer !== null) {
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2)); var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
if (e.type === 'touchmove' && ttimer) {
if (dist > mvthresh) { if (dist > mvthresh) {
clearTimeout(ttimer); clearTimeout(ttimer);
ttimer = null; ttimer = null;
@ -9864,28 +9855,20 @@ function reload_browser() {
} }
return; return;
} }
if (e.cancelable) e.preventDefault(); if (!dragging && dist > mvthresh && !window.getSelection().toString()) {
} if (fwrap = e.target.closest('#wrap'))
if (!dragging && !has_txtsel()) { fwrap.style.userSelect = 'none';
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2)); else return;
if (dist > mvthresh) { start_drag();
if (!fwrapper) return;
start_drag(pos);
}
} }
if (!dragging || !selbox) return; if (!dragging || !selbox) return;
ev(e); ev(e);
var width = Math.abs(pos.x - startx); selbox.style.width = Math.abs(pos.x - startx) + 'px';
var height = Math.abs(pos.y - starty); selbox.style.height = Math.abs(pos.y - starty) + 'px';
var left = Math.min(pos.x, startx); selbox.style.left = Math.min(pos.x, startx) + 'px';
var top = Math.min(pos.y, starty); selbox.style.top = Math.min(pos.y, starty) + 'px';
selbox.style.width = width + 'px';
selbox.style.height = height + 'px';
selbox.style.left = left + 'px';
selbox.style.top = top + 'px';
if (IE && window.getSelection) if (IE && window.getSelection)
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
@ -9893,11 +9876,7 @@ function reload_browser() {
function sel_end(e) { function sel_end(e) {
clearTimeout(ttimer); clearTimeout(ttimer);
ttimer = null; if (dragging && selbox) {
if (dragging) {
prevent_click = true;
if (selbox) {
var sbrect = selbox.getBoundingClientRect(); var sbrect = selbox.getBoundingClientRect();
var faf = QSA('#ggrid a'); var faf = QSA('#ggrid a');
var sadmode = e.shiftKey ? true : e.altKey ? false : "t"; var sadmode = e.shiftKey ? true : e.altKey ? false : "t";
@ -9905,26 +9884,9 @@ function reload_browser() {
if (bob(sbrect, faf[a].getBoundingClientRect())) if (bob(sbrect, faf[a].getBoundingClientRect()))
sel_toggle(faf[a], sadmode); sel_toggle(faf[a], sadmode);
msel.selui(); msel.selui();
}
ev(e); ev(e);
} }
unbox(); unbox();
setTimeout(function() {
prevent_click = false;
}, 50);
}
function has_txtsel() {
var txtsel = window.getSelection();
return txtsel && txtsel.toString().length > 0;
}
function clickblock(e) {
if (prevent_click) {
e.stopImmediatePropagation();
e.preventDefault();
}
} }
function dsel_init() { function dsel_init() {
@ -9932,8 +9894,6 @@ function reload_browser() {
window.addEventListener('mousemove', sel_move); window.addEventListener('mousemove', sel_move);
window.addEventListener('mouseup', sel_end); window.addEventListener('mouseup', sel_end);
window.addEventListener('click', clickblock, true);
window.addEventListener('touchstart', sel_start, { passive: true }); window.addEventListener('touchstart', sel_start, { passive: true });
window.addEventListener('touchmove', sel_move, { passive: false }); window.addEventListener('touchmove', sel_move, { passive: false });
window.addEventListener('touchend', sel_end, { passive: true }); window.addEventListener('touchend', sel_end, { passive: true });