Skip to content

Commit

Permalink
Merge pull request #247 from JayCanuck/master
Browse files Browse the repository at this point in the history
Added enyo.dispatcher.stopListening() to remove event listeners, as well as enyo.unmakeBubble() to remove event listening/bubbling from enyo.makeBubble()

Reviewed-By: Ben Combee (ben.combee@lge.com)
  • Loading branch information
unwiredben committed Mar 25, 2013
2 parents b5b8038 + 09a35f9 commit ba2fef3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions source/dom/dispatcher.js
Expand Up @@ -53,6 +53,20 @@ enyo.dispatcher = {
} }
this.listen(inListener, inEventName, inHandler); 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. //* Fires an event for Enyo to listen for.
dispatch: function(e) { dispatch: function(e) {
// Find the control who maps to e.target, or the first control that maps to an ancestor of e.target. // Find the control who maps to e.target, or the first control that maps to an ancestor of e.target.
Expand Down Expand Up @@ -156,6 +170,21 @@ enyo.bubbler = "enyo.bubble(arguments[0])";
}, control); }, 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 // FIXME: we need to create and initialize dispatcher someplace else to allow overrides
Expand Down

0 comments on commit ba2fef3

Please sign in to comment.