forked from olton/Metro-UI-CSS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metro-tab-control.js
96 lines (72 loc) · 2.89 KB
/
metro-tab-control.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(function( $ ) {
$.widget("metro.tabcontrol", {
version: "1.0.0",
options: {
effect: 'none',
activateStoredTab: false,
tabclick: function(tab){},
tabchange: function(tab){}
},
_create: function(){
var that = this,
element = this.element,
tabs = $(element.children(".tabs")).children("li"),
frames = $(element.children(".frames")).children(".frame"),
element_id = element.attr("id");
if (element.data('effect') != undefined) {
this.options.effect = element.data('effect');
}
this.init(tabs, frames);
tabs.each(function(){
var tab = $(this).children("a");
tab.on('click', function(e){
e.preventDefault();
that.options.tabclick(this);
if ($(this).parent().hasClass('disabled')) {
return false;
}
tabs.removeClass("active");
tab.parent("li").addClass("active");
frames.hide();
var current_frame = $(tab.attr("href"));
switch (that.options.effect) {
case 'slide': current_frame.slideDown(); break;
case 'fade': current_frame.fadeIn(); break;
default: current_frame.show();
}
that._trigger('change', null, current_frame);
that.options.tabchange(this);
if (element_id != undefined) window.localStorage.setItem(element_id+"-current-tab", $(this).attr("href"));
});
});
if (this.options.activateStoredTab) this._activateStoredTab(tabs);
},
init: function(tabs, frames){
var that = this;
tabs.each(function(){
if ($(this).hasClass("active")) {
var current_frame = $($($(this).children("a")).attr("href"));
frames.hide();
current_frame.show();
that._trigger('change', null, current_frame);
}
});
},
_activateStoredTab: function(tabs){
var current_stored_tab = window.localStorage.getItem(this.element.attr('id')+'-current-tab');
if (current_stored_tab != undefined) {
tabs.each(function(){
var a = $(this).children("a");
if (a.attr("href") == current_stored_tab) {
a.click();
}
});
}
},
_destroy: function(){
},
_setOption: function(key, value){
this._super('_setOption', key, value);
}
})
})( jQuery );