From c26a58a5258e8ba5323c7ed7b6c2317642a77630 Mon Sep 17 00:00:00 2001 From: Taye Adeyemi Date: Sat, 27 Aug 2016 01:26:08 +0200 Subject: [PATCH] *: move testIgnore and testAllow to Interactable Also add interactable.testIgnoreAllow() to do both checks --- src/Interactable.js | 34 ++++++++++++++++++++++++++++++++++ src/autoStart/drag.js | 6 +++--- src/autoStart/index.js | 40 +++------------------------------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Interactable.js b/src/Interactable.js index c43b78c83..32e6b6677 100644 --- a/src/Interactable.js +++ b/src/Interactable.js @@ -1,6 +1,7 @@ const isType = require('./utils/isType'); const events = require('./utils/events'); const extend = require('./utils/extend'); +const domUtils = require('./utils/domUtils'); const actions = require('./actions'); const scope = require('./scope'); const Eventable = require('./Eventable'); @@ -213,6 +214,39 @@ class Interactable { || nodeContains(this._context, element)); } + testIgnore (ignoreFrom, interactableElement, element) { + if (!ignoreFrom || !isType.isElement(element)) { return false; } + + if (isType.isString(ignoreFrom)) { + return domUtils.matchesUpTo(element, ignoreFrom, interactableElement); + } + else if (isType.isElement(ignoreFrom)) { + return domUtils.nodeContains(ignoreFrom, element); + } + + return false; + } + + testAllow (allowFrom, interactableElement, element) { + if (!allowFrom) { return true; } + + if (!isType.isElement(element)) { return false; } + + if (isType.isString(allowFrom)) { + return domUtils.matchesUpTo(element, allowFrom, interactableElement); + } + else if (isType.isElement(allowFrom)) { + return domUtils.nodeContains(allowFrom, element); + } + + return false; + } + + testIgnoreAllow (options, interactableElement, element) { + return (!this.testIgnore(options.ignoreFrom, interactableElement, element) + && this.testAllow(options.allowFrom, interactableElement, element)); + } + /*\ * Interactable.fire [ method ] diff --git a/src/autoStart/drag.js b/src/autoStart/drag.js index c506560c1..2e4fb52a5 100644 --- a/src/autoStart/drag.js +++ b/src/autoStart/drag.js @@ -39,12 +39,12 @@ autoStart.signals.on('before-start', function ({ interaction, eventTarget, dx, if (interactable === interaction.target) { return; } + const options = interactable.options; let action = null; if (interactable.inContext(eventTarget) - && !interactable.options.drag.manualStart - && !autoStart.testIgnore(interactable, element, eventTarget) - && autoStart.testAllow(interactable, element, eventTarget) + && !options.drag.manualStart + && !interactable.testIgnoreAllow(options, element, eventTarget) && matchesSelector(element, selector, elements)) { action = interactable.getAction(interaction.downPointer, interaction.downEvent, interaction, element); diff --git a/src/autoStart/index.js b/src/autoStart/index.js index 715d602f9..785b04a57 100644 --- a/src/autoStart/index.js +++ b/src/autoStart/index.js @@ -10,8 +10,6 @@ const signals = require('../utils/Signals').new(); const autoStart = { signals, - testIgnore, - testAllow, withinInteractionLimit, // Allow this many interactions to happen simultaneously maxInteractions: Infinity, @@ -25,38 +23,6 @@ const autoStart = { }, }; -function testIgnore (interactable, interactableElement, element) { - const ignoreFrom = interactable.options.ignoreFrom; - - if (!ignoreFrom || !utils.isElement(element)) { return false; } - - if (utils.isString(ignoreFrom)) { - return utils.matchesUpTo(element, ignoreFrom, interactableElement); - } - else if (utils.isElement(ignoreFrom)) { - return utils.nodeContains(ignoreFrom, element); - } - - return false; -} - -function testAllow (interactable, interactableElement, element) { - const allowFrom = interactable.options.allowFrom; - - if (!allowFrom) { return true; } - - if (!utils.isElement(element)) { return false; } - - if (utils.isString(allowFrom)) { - return utils.matchesUpTo(element, allowFrom, interactableElement); - } - else if (utils.isElement(allowFrom)) { - return utils.nodeContains(allowFrom, element); - } - - return false; -} - // set cursor style on mousedown Interaction.signals.on('down', function ({ interaction, pointer, event, eventTarget }) { if (interaction.interacting()) { return; } @@ -138,11 +104,11 @@ function getActionInfo (interaction, pointer, event, eventTarget) { const elements = (browser.useMatchesSelectorPolyfill ? context.querySelectorAll(selector) : undefined); + const options = interactable.options; if (interactable.inContext(element) - && !module.exports.testIgnore(interactable, element, eventTarget) - && module.exports.testAllow(interactable, element, eventTarget) - && utils.matchesSelector(element, selector, elements)) { + && interactable.testIgnoreAllow(options, element, eventTarget) + && utils.matchesSelector(element, selector, elements)) { matches.push(interactable); matchElements.push(element);