Skip to content

Commit

Permalink
*: fix Interactable context for element targets
Browse files Browse the repository at this point in the history
  • Loading branch information
taye committed Sep 4, 2016
1 parent 63a015f commit 8f64a7a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
44 changes: 16 additions & 28 deletions src/Interactable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions src/autoStart/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down Expand Up @@ -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';
Expand Down
5 changes: 2 additions & 3 deletions src/autoStart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/pointerEvents/interactableTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down Expand Up @@ -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 }) {
Expand Down

0 comments on commit 8f64a7a

Please sign in to comment.