diff --git a/src/Interactable.js b/src/Interactable.js index 5d1cb1ef5..936c21bd5 100644 --- a/src/Interactable.js +++ b/src/Interactable.js @@ -23,37 +23,22 @@ scope.interactables = []; \*/ class Interactable { constructor (target, options) { - this.target = target; - this._context = scope.document; - this.events = new Eventable(); - - let _window; - const context = this._context = options && options.context || scope.document; - - if (isType.trySelector(target)) { - this.target = target; + options = options || {}; - _window = context? scope.getWindow(context) : scope.window; - - if (context && (_window.Node - ? context instanceof _window.Node - : (isType.isElement(context) || context === _window.document))) { - } - } - else { - _window = scope.getWindow(target); - } - - this._doc = _window.document; + this.target = target; + this.events = new Eventable(); + this._context = options.context || scope.document; + this._win = scope.getWindow(isType.trySelector(target)? this._context : target); + this._doc = this._win.document; signals.fire('new', { target, options, interactable: this, - win: _window, + win: this._win, }); - scope.addDocument( this._doc, _window ); + scope.addDocument( this._doc, this._win ); scope.interactables.push(this); @@ -505,16 +490,19 @@ scope.interactables.indexOfElement = function indexOfElement (target, context) { return -1; }; -scope.interactables.get = function interactableGet (element, options) { - return this[this.indexOfElement(element, options && options.context)]; +scope.interactables.get = function interactableGet (element, options, dontCheckInContext) { + const ret = this[this.indexOfElement(element, options && options.context)]; + + return ret && (dontCheckInContext || ret.inContext(element))? ret : null; }; -scope.interactables.forEachSelector = function (callback) { +scope.interactables.forEachSelector = function (callback, element) { for (let i = 0; i < this.length; i++) { const interactable = this[i]; - // skip non CSS selector targets - if (!isType.isString(interactable.target)) { + // skip non CSS selector targets and out of context elements + if (!isType.isString(interactable.target) + || (element && !interactable.inContext(element))) { continue; } diff --git a/src/autoStart/drag.js b/src/autoStart/drag.js index 0217407a3..ac9d5fc66 100644 --- a/src/autoStart/drag.js +++ b/src/autoStart/drag.js @@ -41,8 +41,7 @@ autoStart.signals.on('before-start', function ({ interaction, eventTarget, dx, const options = interactable.options; - if (interactable.inContext(eventTarget) - && !options.drag.manualStart + if (!options.drag.manualStart && !interactable.testIgnoreAllow(options, element, eventTarget) && matchesSelector(element, selector, elements)) { @@ -83,7 +82,7 @@ autoStart.signals.on('before-start', function ({ interaction, eventTarget, dx, break; } - const selectorInteractable = scope.interactables.forEachSelector(getDraggable); + const selectorInteractable = scope.interactables.forEachSelector(getDraggable, element); if (selectorInteractable) { interaction.prepared.name = 'drag'; diff --git a/src/autoStart/index.js b/src/autoStart/index.js index 5c37a62d6..d9617d813 100644 --- a/src/autoStart/index.js +++ b/src/autoStart/index.js @@ -112,8 +112,7 @@ function getActionInfo (interaction, pointer, event, eventTarget) { : undefined); const options = interactable.options; - if (interactable.inContext(element) - && interactable.testIgnoreAllow(options, element, eventTarget) + if (interactable.testIgnoreAllow(options, element, eventTarget) && utils.matchesSelector(element, selector, elements)) { matches.push(interactable); @@ -139,7 +138,7 @@ function getActionInfo (interaction, pointer, event, eventTarget) { }; } else { - scope.interactables.forEachSelector(pushMatches); + scope.interactables.forEachSelector(pushMatches, element); const actionInfo = validateSelector(interaction, pointer, event, matches, matchElements); diff --git a/src/pointerEvents/interactableTargets.js b/src/pointerEvents/interactableTargets.js index 72867c97a..473e7b4a2 100644 --- a/src/pointerEvents/interactableTargets.js +++ b/src/pointerEvents/interactableTargets.js @@ -18,7 +18,6 @@ pointerEvents.signals.on('collect-targets', function ({ targets, element, eventT if (eventable[eventType] && isType.isElement(element) - && interactable.inContext(element) && domUtils.matchesSelector(element, selector, els) && interactable.testIgnoreAllow(options, element, eventTarget)) { @@ -46,7 +45,7 @@ pointerEvents.signals.on('collect-targets', function ({ targets, element, eventT } } - scope.interactables.forEachSelector(collectSelectors); + scope.interactables.forEachSelector(collectSelectors, element); }); Interactable.signals.on('new', function ({ interactable }) {