Created
April 16, 2015 14:08
-
-
Save zorbash/fc4d58c7c8e8bc21a1b5 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
| class Toggler | |
| defaults = | |
| toggled_class: 'open' | |
| constructor: (el, options) -> | |
| @$element = $(el) | |
| @options = $.extend {}, defaults, options | |
| @init() | |
| $target: -> $(@$element.data('target')) | |
| open: -> | |
| @$element.trigger('toggler.open') | |
| $target.addClass('open') | |
| close: -> | |
| @$element.trigger('toggler.close') | |
| @$target().removeClass('open') | |
| onClick: => $target?.toggleClass @options.toggled_class | |
| bindHandlers: -> | |
| @$element.on 'click', @onClick | |
| Toggler::init = -> | |
| @bindHandlers() | |
| $.fn.toggler = (options, params...) -> | |
| @each -> | |
| toggler = $.data @, 'plugin_toggler' | |
| if typeof options == 'string' | |
| toggler?[options].apply toggler, params | |
| else | |
| $.data @, 'plugin_toggler', new Toggler @, options if !toggler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment