Skip to content

Instantly share code, notes, and snippets.

@uk-ar
Forked from mizchi/tab.coffee
Created October 19, 2012 21:20
Show Gist options
  • Save uk-ar/3920795 to your computer and use it in GitHub Desktop.
Save uk-ar/3920795 to your computer and use it in GitHub Desktop.
class Tab
constructor: ->
@$tabs = ($ '.tab')
@$sections = ($ '.section')
@_idx = 0
current_tab: =>
@$tabs.eq(@_idx)
current_section: =>
$tab = @current_tab()
type = $tab.data 'type'
@$sections.filter ".#{type}"
select: (@_idx) =>
@render()
delegate: =>
@$tabs.off()
@$tabs.each (idx, el) =>
($ el).on 'click', 'a', (event) =>
event.preventDefault()
@select idx
render: =>
$tab = @current_tab()
$section = @current_section()
@$tabs.removeClass 'selected'
$tab.addClass 'selected'
@$sections.removeClass 'selected'
$section.addClass 'selected'
$ =>
tab = new Tab
tab.select(0)
tab.delegate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment