Skip to content

Instantly share code, notes, and snippets.

@VinSpee
Last active December 11, 2015 17:48
Show Gist options
  • Save VinSpee/4636551 to your computer and use it in GitHub Desktop.
Save VinSpee/4636551 to your computer and use it in GitHub Desktop.
coffee class fail: This should be a simple reusable toggler. it's defined in toggle.coffee and initiated in ui.coffee. The problem is this: @doToggle is begin called immediately upon init, it's not waiting for a click. any Ideas?
define ["jquery"], ($)->
class Toggle
constructor: (context, toggle, toggler, togglable, callback) ->
@context = context
@$context = $(@context)
@$toggle = $(@context).find(toggle)
@$toggler = $(@context).find(toggler)
@$togglable = $(@context).find(togglable)
@callback = callback
@$toggler.on("click", (event) => @doToggle(@$togglable))
doToggle:(togglable) ->
togglable.slideToggle ->
do @callback if @callback and typeof (@callback) is "function"
define ["toggler"], (Toggler)->
initialize: ->
resultsToggler = new Toggler(".results", "[data-widget=toggle]", "[data-widget-component=toggler]", "[data-widget-component=togglable]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment