Created
July 14, 2010 13:43
-
-
Save rwz/475419 to your computer and use it in GitHub Desktop.
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
/* | |
Prototype's helper for quick and easy observing | |
click events on different elements including | |
anchors with '#' href | |
Usage examples: | |
instead of: | |
elementsArray.invoke('observe', 'click', function(event){ | |
var el = event.findElement(); | |
event.preventDefault(); | |
doStuffWithElement(el) | |
}); | |
do this: | |
elementsArray.invoke('clk', doStuffWithElement); | |
*/ | |
(function(){ | |
'use strict'; | |
Element.clk = function(element, callback){ | |
element.observe('click', function(event){ | |
event.stop(); | |
callback(element, event); | |
}); | |
}; | |
Element.prototype.clk = Element.clk.methodize(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment