Created
June 26, 2012 01:34
-
-
Save tashian/2992588 to your computer and use it in GitHub Desktop.
show/hide/toggle elements - generalized JS
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
# 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