Last active
November 12, 2015 20:59
-
-
Save jonwolfe/f9ab8e9537c28452f0c3 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
class @E | |
@on: (selector, eventName, callback) -> | |
$(document).on eventName, selector, (event) => | |
el = $(event.currentTarget) | |
callback(event, el) | |
@click: (selector, callback) -> | |
@on selector, 'click', (event) => | |
target = $(event.currentTarget) | |
unless callback(event, target) == true | |
event.preventDefault() | |
# usage example | |
E.click '[showmodal]', (e, el) -> | |
show $ el.attr('href') | |
E.click '[hidemodal]', (e, el) -> | |
modal = $ el.closest('.modal') | |
hide $ el.closest('.modal') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment