Permalink
Browse files

Added enyo.dispatcher.stopListening() to remove event listeners, as w…

…ell as enyo.unmakeBubble() to remove event listening/bubbling from enyo.makeBubble()
  • Loading branch information...
1 parent c101fcf commit 4cd9be07602025c37d6d6a88230bfdd434fcc7ca @JayCanuck JayCanuck committed Mar 25, 2013
Showing with 29 additions and 0 deletions.
  1. +29 −0 source/dom/dispatcher.js
View
29 source/dom/dispatcher.js
@@ -53,6 +53,20 @@ enyo.dispatcher = {
}
this.listen(inListener, inEventName, inHandler);
},
+ stopListening: function(inListener, inEventName, inHandler) {
+ var d = enyo.dispatch;
+ if (inListener.addEventListener) {
+ this.stopListening = function(inListener, inEventName, inHandler) {
+ inListener.removeEventListener(inEventName, inHandler || d, false);
+ };
+ } else {
+ //enyo.log("IE8 COMPAT: using 'detachEvent'");
+ this.stopListening = function(inListener, inEvent, inHandler) {
+ inListener.detachEvent("on" + inEvent, inHandler || d);
+ };
+ }
+ this.stopListening(inListener, inEventName, inHandler);
+ },
//* Fires an event for Enyo to listen for.
dispatch: function(e) {
// Find the control who maps to e.target, or the first control that maps to an ancestor of e.target.
@@ -156,6 +170,21 @@ enyo.bubbler = "enyo.bubble(arguments[0])";
}, control);
}
};
+ /**
+ * Removes the event listening and bubbling caused from enyo.makeBubble, on a specific control
+ */
+ enyo.unmakeBubble = function() {
+ var args = Array.prototype.slice.call(arguments, 0),
+ control = args.shift();
+
+ if((typeof control === "object") && (typeof control.hasNode === "function")) {
+ enyo.forEach(args, function(event) {
+ if(this.hasNode()) {
+ enyo.dispatcher.stopListening(this.node, event, bubbleUp);
+ }
+ }, control);
+ }
+ };
})();
// FIXME: we need to create and initialize dispatcher someplace else to allow overrides

0 comments on commit 4cd9be0

Please sign in to comment.