forked from romulomachado/simpletabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpletabs.coffee
48 lines (40 loc) · 1.32 KB
/
simpletabs.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$ ->
hashTabs = ->
_element: ""
element: (element) ->
this._element = element
updateTab: ->
this.updateTabLink()
this.updateTabContainer()
$('body').scrollTop(0)
updateTabLink: ->
this._element.parent().addClass('is-active').siblings('.is-active').removeClass('is-active')
updateTabContainer: ->
dataTab = this._element.data('tab')
contentTab = $("[data-content='" + dataTab + "']")
$('[data-content]').not(contentTab).removeClass('is-active')
contentTab.each ->
$(this).addClass('is-active')
updateURLHash: ->
window.location.hash = this._element.data('tab')
if $('[data-tab]').length
$(window).on 'load', ->
if window.location.hash != ""
hash = window.location.hash.replace("#", "")
tabs = new hashTabs()
tabs.element $("[data-tab='"+hash+"']")
tabs.updateTab()
else
tabs = new hashTabs()
tabs.element $("[data-tab]").first()
tabs.updateTab()
$(window).on 'hashchange', ->
hash = window.location.hash.replace("#", "")
tabs = new hashTabs()
tabs.element $("[data-tab='"+hash+"']")
tabs.updateTab()
$('[data-tab]').on 'click', (e) ->
tabs = new hashTabs()
tabs.element $(this)
tabs.updateURLHash()
e.preventDefault()