Created
February 11, 2010 11:28
-
-
Save obeattie/301435 to your computer and use it in GitHub Desktop.
This file contains 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.implement({ | |
closest: function(selector){ | |
/* Matches the nearest element with the passed selector -- much like | |
* Element.getParent, but with the starting element included */ | |
return (this.match(selector)) ? this : this.getParent(selector); | |
}, | |
addLiveEvent: function(eventType, selector, handler){ | |
/* Binds a 'live event' to all the element. Whenever the event is allowed to bubble | |
* up to this element, event.target is checked to see whether it matches the passed | |
* selector. If it does, the handler will be fired */ | |
this.addEvent(eventType, (function(event){ | |
var target = event.target; | |
var matched = target.closest(selector); | |
if (matched) handler.run([event], matched); | |
}).bindWithEvent(this, selector, handler)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment