-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspine.tabs.js
64 lines (49 loc) · 1.16 KB
/
spine.tabs.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
*
* Tabs Controller for Spine.js
*
* @author: Hjörtur Elvar Hilmarsson
*
**/
Spine.Controller.Tabs = Spine.Controller.sub({
// Register events
events:{
"click .tabs a": "tabLinkClick",
},
// Register elements
elements:{
".tabs a": "tabLinks",
"[data-tab]": "tabs"
},
/**
* Initalizes controller
**/
init:function () {
// routes for tab
this.routes({ "/:tab": this.tabChange });
},
/**
* Handles the route change for tab events
**/
tabChange: function( params ) {
// find selected tab
var selectedTab = $("[data-tab=" + params.tab + "]", this.el );
// select first if selected not found
if( !selectedTab.length ) {
selectedTab = this.tabs.first();
}
// hide all tabs
this.tabs.hide();
// show selected tab
selectedTab.fadeIn();
},
/*
-- UI Events --
*/
tabLinkClick: function( e ) {
e.preventDefault();
// navigate on link click
var link = $( e.currentTarget );
this.navigate( link.attr("href") );
}
});