Last active
November 6, 2018 16:50
-
-
Save stringparser/a3b0555fd915138a0ed3 to your computer and use it in GitHub Desktop.
`eventListenerList`
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 characters
;[Element].forEach(function(self){ | |
self.prototype.eventListenerList = {}; | |
self.prototype._addEventListener = self.prototype.addEventListener; | |
self.prototype.addEventListener = function(type, handle, useCapture) { | |
useCapture = useCapture === void 0 ? false : useCapture; | |
var node = this; | |
node._addEventListener(type, handle, useCapture); | |
if(!node.eventListenerList[type]){ | |
node.eventListenerList[type] = []; | |
} | |
node.eventListenerList[type].push({ | |
type : type, | |
handle : handle, | |
useCapture : useCapture, | |
remove : function(){ | |
node.removeEventListener( | |
this.type, this.handle, this.useCapture | |
); | |
return node.eventListenerList[type]; | |
} | |
}); | |
}; | |
self.prototype._removeEventListener = self.prototype.removeEventListener; | |
self.prototype.removeEventListener = function(type, handle, useCapture){ | |
var node = this; | |
if(!node.eventListenerList[type]) | |
return ; | |
node._removeEventListener(type, handle, useCapture); | |
node.eventListenerList[type] = node.eventListenerList[type].filter( | |
function(listener){ | |
return listener.handle.toString() !== handle.toString(); | |
} | |
) | |
if(node.eventListenerList[type].length === 0){ | |
delete node.eventListenerList[type]; | |
} | |
} | |
}) |
BlazenBundy
commented
Jun 26, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment