Skip to content

Commit

Permalink
Merge pull request #2 from skillstream/fix-nodrag-option
Browse files Browse the repository at this point in the history
fix: nodrag option.
  • Loading branch information
davegudge authored Mar 26, 2019
2 parents 64d12dd + a244067 commit ba1cf5c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dragscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@
(cont = el.container || el)[addEventListener](
mousedown,
cont.md = function(e) {
// Return if the element or it's parent cannot be dragged.
// Return if the target (of the mousedown event) or any of it's ancestors cannot be dragged.
// Ideally composedPath() would be used here but it's not supported by IE.
// https://stackoverflow.com/a/39245638
if (e.target.hasAttribute('nodrag') || e.target.parentNode.hasAttribute('nodrag')) {
var element = e.target;
var elements = [];
while (element) {
elements.push(element);
element = element.parentNode;
}
for (j = 0; j < elements.length; j++) {
if (typeof elements[j].hasAttribute === 'function' && elements[j].hasAttribute('nodrag')) {
return true;
}
}

if (!el.hasAttribute('nochilddrag') || _document.elementFromPoint(e.pageX, e.pageY) == cont) {
Expand Down

0 comments on commit ba1cf5c

Please sign in to comment.