2022-06-16 20:36:27 -04:00
|
|
|
"use strict";
|
2019-10-24 19:27:09 -07:00
|
|
|
function somethingSelected() {
|
|
|
|
return typeof window.getSelection == 'function' && window.getSelection().toString() != "";
|
|
|
|
}
|
2022-06-14 17:52:23 -04:00
|
|
|
const remover = / |\n|\t/g; //should it be /\s/g ?
|
2019-10-24 19:27:09 -07:00
|
|
|
$('.dragscroll').each(function(_, el) {
|
2022-06-16 20:36:27 -04:00
|
|
|
let previouslyMouseDown = false
|
2019-10-24 19:27:09 -07:00
|
|
|
el.addEventListener('mousemove', function(e) {
|
2019-10-24 22:40:32 -07:00
|
|
|
if (e.buttons != 1) {
|
2019-10-24 19:27:09 -07:00
|
|
|
if (previouslyMouseDown) {
|
2022-06-16 20:36:27 -04:00
|
|
|
el.style.removeProperty('user-select')
|
|
|
|
el.style.removeProperty('-webkit-user-select')
|
2019-10-24 19:27:09 -07:00
|
|
|
previouslyMouseDown = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-06-16 20:36:27 -04:00
|
|
|
if (somethingSelected()) return
|
2019-10-24 19:27:09 -07:00
|
|
|
if (!previouslyMouseDown) {
|
2022-06-14 17:52:23 -04:00
|
|
|
if ([...e.target.childNodes].some(
|
2022-06-14 17:56:06 -04:00
|
|
|
el => el.nodeType === Node.TEXT_NODE
|
|
|
|
&&
|
|
|
|
el.textContent.replace(remover, '').length
|
|
|
|
)
|
2022-06-16 20:36:27 -04:00
|
|
|
) return
|
2022-06-14 17:52:23 -04:00
|
|
|
|
2022-06-16 20:36:27 -04:00
|
|
|
el.style['user-select'] = 'none'
|
|
|
|
el.style['-webkit-user-select'] = 'none'
|
2019-10-24 19:27:09 -07:00
|
|
|
previouslyMouseDown = true;
|
|
|
|
}
|
2022-06-16 20:36:27 -04:00
|
|
|
//el.scrollLeft -= e.movementX
|
2019-10-24 19:27:09 -07:00
|
|
|
el.scrollTop -= e.movementY;
|
|
|
|
}, {passive: true});
|
|
|
|
});
|