work out dsel bugs

also probably introduce new bugs
also work out merge conflicts
also cleanup things
also tabs instead of spaces
This commit is contained in:
icxes 2026-01-16 11:53:02 +02:00
parent 5d7cf80ff0
commit c4210e7281
No known key found for this signature in database

View file

@ -9759,144 +9759,190 @@ function reload_browser() {
} }
(function() { (function() {
var is_selma = false; var is_selma = false;
var is_drag = false; var dragging = false;
var startx, starty; var prevent_click = false;
var selbox = null;
var ttimer = null; var fwrapper = null;
var lpdelay = 400; var startx, starty;
var mvthresh = 10; var selbox = null;
function unbox() { var ttimer = null;
qsr('.selbox'); var lpdelay = 250;
selbox = null; var mvthresh = 10;
is_drag = false;
is_selma = false;
}
function getpp(e) { function unbox() {
if (e.touches && e.touches.length > 0) { qsr('.selbox');
return { x: e.touches[0].clientX, y: e.touches[0].clientY };
}
return { x: e.clientX, y: e.clientY };
}
function sel_toggle(el) { if (fwrapper) {
clmod(el, 'sel', 't'); ebi("gfiles").style.userSelect = 'auto';
var eref = el.getAttribute('ref'); fwrapper = null;
if (eref) { }
var ehidden = ebi(eref);
if (ehidden) {
var tr = ehidden.closest('tr');
if (tr) clmod(tr, 'sel', 't');
}
}
}
function bob(rect1, rect2) { selbox = null;
return !(rect1.right < rect2.left || rect1.left > rect2.right || dragging = false;
rect1.bottom < rect2.top || rect1.top > rect2.bottom); is_selma = false;
} ttimer = null;
}
function sel_start(e) { function getpp(e) {
var touch = (e.touches && e.touches[0]) || e;
return { x: touch.clientX, y: touch.clientY };
}
function sel_toggle(el) {
clmod(el, 'sel', 't');
var eref = el.getAttribute('ref');
if (eref) {
var ehidden = ebi(eref);
if (ehidden) {
var tr = ehidden.closest('tr');
if (tr) clmod(tr, 'sel', 't');
}
}
}
function bob(b1, b2) {
return !(b1.right < b2.left || b1.left > b2.right ||
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) {
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;
var pos = getpp(e);
startx = pos.x;
starty = pos.y;
if (e.type === 'mousedown') { var pos = getpp(e);
if (e.button !== 0) { startx = pos.x;
unbox(); starty = pos.y;
return; is_selma = true;
} ttimer = null;
is_selma = true; prevent_click = false;
start_drag(pos);
}
else if (e.type === 'touchstart') {
ttimer = setTimeout(function() {
is_selma = true;
start_drag(pos);
}, lpdelay);
}
}
function start_drag(pos) { fwrapper = e.target.closest('#wrap');
is_drag = true; if (fwrapper) ebi('gfiles').style.userSelect = 'none';
selbox = document.createElement('div');
selbox.className = 'selbox';
document.body.appendChild(selbox);
document.body.style.userSelect = 'none';
}
function sel_move(e) { if (e.type === 'touchstart') {
if (!treectl.dsel) return; if (ttimer) clearTimeout(ttimer);
ttimer = setTimeout(function() {
ttimer = null;
start_drag(pos);
}, lpdelay);
}
}
var pos = getpp(e); function start_drag(pos) {
if (dragging) return;
if (ttimer && !is_drag) { dragging = true;
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2)); selbox = document.createElement('div');
if (dist > mvthresh) { selbox.className = 'selbox';
clearTimeout(ttimer); document.body.appendChild(selbox);
ttimer = null; }
}
}
if (!is_drag || !selbox) return; function sel_move(e) {
if (!is_selma) return;
var pos = getpp(e);
ev(e); if (e.type === 'touchmove') {
if (ttimer !== null) {
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
if (dist > mvthresh) {
clearTimeout(ttimer);
ttimer = null;
is_selma = false;
}
return;
}
if (e.cancelable) e.preventDefault();
}
if (!dragging && !has_txtsel()) {
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
if (dist > mvthresh) {
if (!fwrapper) return;
start_drag(pos);
}
}
var width = Math.abs(pos.x - startx); if (!dragging || !selbox) return;
var height = Math.abs(pos.y - starty); ev(e);
var left = Math.min(pos.x, startx);
var top = Math.min(pos.y, starty);
selbox.style.width = width + 'px'; var width = Math.abs(pos.x - startx);
selbox.style.height = height + 'px'; var height = Math.abs(pos.y - starty);
selbox.style.left = left + 'px'; var left = Math.min(pos.x, startx);
selbox.style.top = top + 'px'; var top = Math.min(pos.y, starty);
if (IE && window.getSelection) selbox.style.width = width + 'px';
window.getSelection().removeAllRanges(); selbox.style.height = height + 'px';
} selbox.style.left = left + 'px';
selbox.style.top = top + 'px';
function sel_end(e) { if (IE && window.getSelection)
clearTimeout(ttimer); window.getSelection().removeAllRanges();
ttimer = null; }
if (!is_drag) return; function sel_end(e) {
clearTimeout(ttimer);
ttimer = null;
if (selbox) { if (dragging) {
var sbrect = selbox.getBoundingClientRect(); prevent_click = true;
var faf = QSA('#ggrid a'); if (selbox) {
var sbrect = selbox.getBoundingClientRect();
var faf = QSA('#ggrid a');
for (var a = 0, aa = faf.length; a < aa; a++)
if (bob(sbrect, faf[a].getBoundingClientRect()))
sel_toggle(faf[a]);
msel.selui();
}
ev(e);
}
for (var a = 0, aa = faf.length; a < aa; a++) unbox();
if (bob(sbrect, faf[a].getBoundingClientRect())) setTimeout(function() {
sel_toggle(faf[a]); prevent_click = false;
}, 50);
}
msel.selui(); function has_txtsel() {
} var txtsel = window.getSelection();
return txtsel && txtsel.toString().length > 0;
}
unbox(); function clickblock(e) {
document.body.style.userSelect = 'auto'; if (prevent_click) {
} e.stopImmediatePropagation();
e.preventDefault();
}
}
function dsel_init() { function dsel_init() {
window.addEventListener('mousedown', sel_start); window.addEventListener('mousedown', sel_start);
window.addEventListener('mousemove', sel_move); window.addEventListener('mousemove', sel_move);
window.addEventListener('mouseup', sel_end); window.addEventListener('mouseup', sel_end);
window.addEventListener('touchstart', sel_start, { passive: true }); window.addEventListener('click', clickblock, true);
window.addEventListener('touchmove', sel_move, { passive: false });
window.addEventListener('touchend', sel_end, { passive: true });
window.addEventListener('dragstart', function(e) { window.addEventListener('touchstart', sel_start, { passive: true });
if (treectl.dsel && (is_selma || is_drag)) { window.addEventListener('touchmove', sel_move, { passive: false });
e.preventDefault(); window.addEventListener('touchend', sel_end, { passive: true });
}
}); window.addEventListener('dragstart', function(e) {
} if (treectl.dsel && (is_selma || dragging)) {
e.preventDefault();
}
});
}
dsel_init(); dsel_init();
})(); })();