Skip to content

Instantly share code, notes, and snippets.

@tashian
Created June 26, 2012 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tashian/2992588 to your computer and use it in GitHub Desktop.
Save tashian/2992588 to your computer and use it in GitHub Desktop.
show/hide/toggle elements - generalized JS
# General event handler for showing, hiding, and toggling elements.
#
# Usage: <a href="x" data-show="#my_form">
# If #my_form exists, we'll call show() on it.
# Otherwise, we'll follow the link to x.
$(document).on 'click', 'a[data-toggle], a[data-show], a[data-hide]', (e) ->
link = $(@)
for opt in ['toggle', 'show', 'hide']
if link.data(opt)? && $(link.data(opt)).length > 0
$(link.data(opt))[opt]()
e.preventDefault() unless e.isDefaultPrevented()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment