-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery-viewstack.js
More file actions
63 lines (61 loc) · 1.52 KB
/
jquery-viewstack.js
File metadata and controls
63 lines (61 loc) · 1.52 KB
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
/*!
* jquery viewstack (0.22)
* Copyright 2012, Nikhilesh Katakam
* Distributed under MIT license.
* https://github.com/niki4810/jquery-viewstack
*/
$.widget("nk.viewstack", {
version : "0.1",
options : {
selectedIndex : 0
},
_viewStackChildren : null,
_create : function() {
this._viewStackChildren = this.element.find("> div");
if (!this._viewStackChildren) {
throw Error("Expected viewstack children to be defined");
}
this._createView();
},
_setOption : function(key, value) {
if (key === "selectedIndex") {
this.options[key] = value;
this._updateDisplayList();
}
},
_createView : function() {
this._refreshView();
//trigger a creation complete event
this._trigger("creationComplete", null, {
selectedIndex : this.options.selectedIndex
});
},
_updateDisplayList : function() {
this._refreshView();
//trigger selected index changed event
this._trigger("selectedIndexChanged", null, {
selectedIndex : this.options.selectedIndex
});
},
_refreshView : function() {
var viewStackChildren = this._viewStackChildren;
for (var i = 0; i < viewStackChildren.length; i++) {
if (this.options.selectedIndex === i) {
$(viewStackChildren[i]).show();
} else {
$(viewStackChildren[i]).hide();
}
}
},
destroy : function() {
// call the base destroy function
$.Widget.prototype.destroy.call(this);
},
/*public methods*/
getSelectedIndex : function() {
return this.options.selectedIndex;
},
getChildrenCount : function() {
return this._viewStackChildren.length;
}
});