ftdomdelegate
Advanced tools
Comparing version 3.0.2 to 3.1.0
/*jshint browser:true, node:true*/ | ||
/* global HTMLDocument */ | ||
@@ -32,2 +33,5 @@ 'use strict'; | ||
this.handle = Delegate.prototype.handle.bind(this); | ||
// Cache of event listeners removed during an event cycle | ||
this._removedListeners = []; | ||
} | ||
@@ -243,2 +247,3 @@ | ||
if ((!selector || selector === listener.selector) && (!handler || handler === listener.handler)) { | ||
this._removedListeners.push(listener); | ||
listenerList.splice(i, 1); | ||
@@ -282,2 +287,7 @@ } | ||
// Handle SVG <use> elements in IE | ||
if (target.correspondingUseElement) { | ||
target = target.correspondingUseElement; | ||
} | ||
root = this.rootElement; | ||
@@ -300,2 +310,4 @@ | ||
var toFire = []; | ||
// Need to continuously check | ||
@@ -319,2 +331,10 @@ // that the specific list is | ||
if( | ||
target.tagName && | ||
["button", "input", "select", "textarea"].indexOf(target.tagName.toLowerCase()) > -1 && | ||
target.hasAttribute("disabled") | ||
) { | ||
// Remove things that have previously fired | ||
toFire = []; | ||
} | ||
// Check for match and fire | ||
@@ -326,14 +346,5 @@ // the event if there's one | ||
// was called. If so, break both loops. | ||
if (listener.matcher.call(target, listener.matcherParam, target)) { | ||
returned = this.fire(event, target, listener); | ||
else if (listener.matcher.call(target, listener.matcherParam, target)) { | ||
toFire.push([event, target, listener]); | ||
} | ||
// Stop propagation to subsequent | ||
// callbacks if the callback returned | ||
// false | ||
if (returned === false) { | ||
event[EVENTIGNORE] = true; | ||
event.preventDefault(); | ||
return; | ||
} | ||
} | ||
@@ -351,4 +362,33 @@ | ||
l = listenerList.length; | ||
target = target.parentElement; | ||
// Fall back to parentNode since SVG children have no parentElement in IE | ||
target = target.parentElement || target.parentNode; | ||
// Do not traverse up to document root when using parentNode, though | ||
if (target instanceof HTMLDocument) { | ||
break; | ||
} | ||
} | ||
var ret; | ||
for(i=0; i<toFire.length; i++) { | ||
// Has it been removed during while the event function was fired | ||
if(this._removedListeners.indexOf(toFire[i][2]) > -1) { | ||
continue; | ||
} | ||
returned = this.fire.apply(this, toFire[i]); | ||
// Stop propagation to subsequent | ||
// callbacks if the callback returned | ||
// false | ||
if (returned === false) { | ||
toFire[i][0][EVENTIGNORE] = true; | ||
toFire[i][0].preventDefault(); | ||
ret = false; | ||
break; | ||
} | ||
} | ||
return ret; | ||
}; | ||
@@ -407,3 +447,12 @@ | ||
/*jshint validthis:true*/ | ||
if (this.rootElement === window) return element === document; | ||
if (this.rootElement === window) { | ||
return ( | ||
// Match the outer document (dispatched from document) | ||
element === document || | ||
// The <html> element (dispatched from document.body or document.documentElement) | ||
element === document.documentElement || | ||
// Or the window itself (dispatched from window) | ||
element === window | ||
); | ||
} | ||
return this.rootElement === element; | ||
@@ -410,0 +459,0 @@ } |
{ | ||
"name": "ftdomdelegate", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"author": "FT Labs <enquiries@labs.ft.com> (http://labs.ft.com/)", | ||
@@ -5,0 +5,0 @@ "description": "Create and manage a DOM event delegator.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39253
845