Implementing Element.hasEvent() in MooTools
MooTools allows you to easily add event listeners to elements using the addEvent and removeEvent methods. One thing MooTools doesn’t have is a hasEvent method which will check an element’s list of listeners to see if the element has been assigned a specific function per event. I experimented with implementing this functionality and believe I’ve found the best solution.
1 2 3 4 5 6 7 8 | Element.implement({ hasEvent: function(eventType,fn) { //get the element's events var myEvents = this.retrieve('events'); //can we shoot this down? return myEvents && myEvents[eventType] && (fn == undefined || myEvents[eventType].keys.contains(fn)); } }); |
文章评论 已经有 0 条评论!