Skip to content

Instantly share code, notes, and snippets.

@jonwolfe
Last active November 12, 2015 20:59
Show Gist options
  • Save jonwolfe/f9ab8e9537c28452f0c3 to your computer and use it in GitHub Desktop.
Save jonwolfe/f9ab8e9537c28452f0c3 to your computer and use it in GitHub Desktop.
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