Created
October 18, 2012 07:27
-
-
Save mizchi/3910284 to your computer and use it in GitHub Desktop.
This file contains 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 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() | |
@_idx
を持ってるならdata-type使わずに@$sections.eq(@_idx)
で良いすね
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
えっ、
select: (@_idx)
で@_idxに引数入るの、すごい