mirror of
https://github.com/9001/copyparty.git
synced 2026-02-26 21:43:08 -07:00
dsel: refactor/cleanup
This commit is contained in:
parent
394a07c786
commit
70351c46e9
|
|
@ -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')
|
||||||
if (fwrapper) {
|
ebi('wrap').style.removeProperty('user-select')
|
||||||
ebi("gfiles").style.userSelect = 'auto';
|
|
||||||
fwrapper = null;
|
if (selbox) {
|
||||||
|
console.log(selbox)
|
||||||
|
window.getSelection().removeAllRanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
selbox = null;
|
|
||||||
dragging = false;
|
|
||||||
is_selma = false;
|
is_selma = false;
|
||||||
|
dragging = false;
|
||||||
|
fwrap = null;
|
||||||
|
selbox = null;
|
||||||
ttimer = null;
|
ttimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -9807,124 +9809,84 @@ 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);
|
||||||
|
var dist = Math.sqrt(Math.pow(pos.x - startx, 2) + Math.pow(pos.y - starty, 2));
|
||||||
|
|
||||||
if (e.type === 'touchmove') {
|
if (e.type === 'touchmove' && ttimer) {
|
||||||
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 (dist > mvthresh) {
|
||||||
if (!fwrapper) return;
|
clearTimeout(ttimer);
|
||||||
start_drag(pos);
|
ttimer = null;
|
||||||
|
is_selma = false;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!dragging && dist > mvthresh && !window.getSelection().toString()) {
|
||||||
|
if (fwrap = e.target.closest('#wrap'))
|
||||||
|
fwrap.style.userSelect = 'none';
|
||||||
|
else return;
|
||||||
|
start_drag();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sel_end(e) {
|
function sel_end(e) {
|
||||||
clearTimeout(ttimer);
|
clearTimeout(ttimer);
|
||||||
ttimer = null;
|
if (dragging && selbox) {
|
||||||
|
var sbrect = selbox.getBoundingClientRect();
|
||||||
if (dragging) {
|
var faf = QSA('#ggrid a');
|
||||||
prevent_click = true;
|
var sadmode = e.shiftKey ? true : e.altKey ? false : "t";
|
||||||
if (selbox) {
|
for (var a = 0, aa = faf.length; a < aa; a++)
|
||||||
var sbrect = selbox.getBoundingClientRect();
|
if (bob(sbrect, faf[a].getBoundingClientRect()))
|
||||||
var faf = QSA('#ggrid a');
|
sel_toggle(faf[a], sadmode);
|
||||||
var sadmode = e.shiftKey ? true : e.altKey ? false : "t";
|
msel.selui();
|
||||||
for (var a = 0, aa = faf.length; a < aa; a++)
|
|
||||||
if (bob(sbrect, faf[a].getBoundingClientRect()))
|
|
||||||
sel_toggle(faf[a], sadmode);
|
|
||||||
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 });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue