Last active
December 22, 2015 00:28
-
-
Save xrado/6389156 to your computer and use it in GitHub Desktop.
Revisions
-
xrado revised this gist
Aug 30, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ [Element, Window, Document].invoke('implement', { // Call as element.addNsEvent('event.namespace', function() {}); addNsEvent: function(name, fn) { // Get event type and namespace var split = name.split('.'), -
xrado created this gist
Aug 30, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ Element.implement({ // Call as element.addNsEvent('event.namespace', function() {}); addNsEvent: function(name, fn) { // Get event type and namespace var split = name.split('.'), eventName = split[0], namespace = split[1]; // Store the event by its full name including namespace this.bindCache = this.bindCache || {}; if(this.bindCache[name]) { this.bindCache[name].push(fn); } else { this.bindCache[name] = [fn]; } // Bind the function to the event this.addEvent(eventName, fn); return this; }, // Call as element.removeNsEvent('event.namespace'); removeNsEvent: function(name) { // Unbind the specified event var eventName = name.split('.')[0], fns = this.bindCache[name], x = 0, fn; for(; fn = fns[x++]; ) { this.removeEvent(eventName, fn); } return this; }, // Call as element.removeNsEvents('namespace'); removeNsEvents: function(namespace){ var fns, x, fn, self = this; Object.each(this.bindCache, function(fns,name){ if(name.contains('.') && name.split('.').getLast() == namespace) { x = 0; for(; fn = fns[x++]; ) { self.removeEvent(name.split('.')[0], fn); } } }); return this; } });