Skip to content

Instantly share code, notes, and snippets.

@tanshio
Created January 27, 2015 21:30
Show Gist options
  • Save tanshio/546791458f3a0e17725e to your computer and use it in GitHub Desktop.
Save tanshio/546791458f3a0e17725e to your computer and use it in GitHub Desktop.
$.fn.extend
tabs: (options) ->
# Default settings
settings =
duration: 500
# Merge default settings with options.
settings = $.extend settings, options
$(@).on('click',(e)->
e.preventDefault()
link = @.href
link = link.split('#')[1]
if $(@).attr('data-tab') is 'active'
else
$('[data-tab-contents="active"]').fadeOut(settings.duration,->
$(@).attr('data-tab-contents','hide')
$(@).attr('aria-hidden','true')
$('#'+link).fadeIn(settings.duration,->
$(@).attr('data-tab-contents','active')
$(@).attr('aria-hidden','false')
)
)
$('[data-tab="active"]').attr('data-tab','hide')
$('[data-tab="active"]').attr('aria-selected','false')
$(@).attr('data-tab','active')
$(@).attr('aria-selected','true')
)
ul.tab(role="tablist").js-tabs
li(role="presentation")
a(id="tabaaa" href="#aaa" role="tab" aria-controls="tabAAA" aria-selected="true" data-tab="active").tab__list 本社
li(role="presentation")
a(id="tabbbb" href="#bbb" role="tab" aria-controls="tabBB" aria-selected="false" data-tab="hide").tab__list 支店
section(data-tab-contents="active" role="tabpanel" aria-labelledby="aaaTab" aria-hidden="false")#aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment