Skip to content

Instantly share code, notes, and snippets.

@phated
Created February 7, 2012 20:09
Show Gist options
  • Save phated/1761663 to your computer and use it in GitHub Desktop.
Save phated/1761663 to your computer and use it in GitHub Desktop.
Trying to use coffeescript Class
class Stackr
constructor: ->
@stack = []
@navHeaders = $ '.nav-header'
@userStack = $ '#stack'
highlightActive: (event) =>
@navHeaders.removeClass 'active'
$(event.currentTarget).addClass 'active'
togglePackages: (event) =>
el = $(event.currentTarget)
if el.is ':checked'
@stack.push el.val()
else
@stack = @stack.filter (package) -> package isnt el.val()
@toggleStack()
console.log @stack
toggleStack: ->
@userStack.collapse 'show' unless @userStack.hasClass 'in'
@userStack.collapse 'hide' if @stack.length is 0
$ ->
stackr = new Stackr()
$('.sidebar-nav .nav-header').on 'click', stackr.highlightActive
$('input[type="checkbox"]').on 'change', stackr.togglePackages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment