forked from telerik/kendo-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkendo.mobile.tabstrip.js
More file actions
178 lines (143 loc) · 5.1 KB
/
kendo.mobile.tabstrip.js
File metadata and controls
178 lines (143 loc) · 5.1 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
(function(f, define){
define([ "./kendo.core" ], f);
})(function(){
var __meta__ = {
id: "mobile.tabstrip",
name: "TabStrip",
category: "mobile",
description: "The mobile TabStrip widget is used inside a mobile view or layout footer element to display an application-wide group of navigation buttons.",
depends: [ "core" ]
};
(function($, undefined) {
var kendo = window.kendo,
ui = kendo.mobile.ui,
Widget = ui.Widget,
ACTIVE_STATE_CLASS = "km-state-active",
SELECT = "select";
function createBadge(value) {
return $('<span class="km-badge">' + value + '</span>');
}
var TabStrip = Widget.extend({
init: function(element, options) {
var that = this;
Widget.fn.init.call(that, element, options);
that.container().bind("show", $.proxy(this, "refresh"));
that.element
.addClass("km-tabstrip")
.find("a").each(that._buildButton)
.eq(that.options.selectedIndex).addClass(ACTIVE_STATE_CLASS);
that.element.on("down", "a", "_release");
},
events: [
SELECT
],
switchTo: function(url) {
var tabs = this.element.find('a'),
tab,
path,
idx = 0,
length = tabs.length;
if(isNaN(url)) {
for (; idx < length; idx ++) {
tab = tabs[idx];
path = tab.href.replace(/(\#.+)(\?.+)$/, "$1"); // remove the fragment query string - http://www.foo.com?foo#bar**?baz=qux**
if (path.indexOf(url, path.length - url.length) !== -1) {
this._setActiveItem($(tab));
return true;
}
}
} else {
this._setActiveItem(tabs.eq(url));
return true;
}
return false;
},
switchByFullUrl: function(url) {
var tab;
tab = this.element.find("a[href$='" + url + "']");
this._setActiveItem(tab);
},
clear: function() {
this.currentItem().removeClass(ACTIVE_STATE_CLASS);
},
currentItem: function() {
return this.element.children("." + ACTIVE_STATE_CLASS);
},
badge: function(item, value) {
var tabstrip = this.element, badge;
if (!isNaN(item)) {
item = tabstrip.children().get(item);
}
item = tabstrip.find(item);
badge = $(item.find(".km-badge")[0] || createBadge(value).insertAfter(item.children(".km-icon")));
if (value || value === 0) {
badge.html(value);
return this;
}
if (value === false) {
badge.empty().remove();
return this;
}
return badge.html();
},
_release: function(e) {
if (e.which > 1) {
return;
}
var that = this,
item = $(e.currentTarget);
if (item[0] === that.currentItem()[0]) {
return;
}
if (that.trigger(SELECT, {item: item})) {
e.preventDefault();
} else {
that._setActiveItem(item);
}
},
_setActiveItem: function(item) {
if (!item[0]) {
return;
}
this.clear();
item.addClass(ACTIVE_STATE_CLASS);
},
_buildButton: function() {
var button = $(this),
icon = kendo.attrValue(button, "icon"),
badge = kendo.attrValue(button, "badge"),
image = button.find("img"),
iconSpan = $('<span class="km-icon"/>');
button
.addClass("km-button")
.attr(kendo.attr("role"), "tab")
.contents().not(image)
.wrapAll('<span class="km-text"/>');
if (image[0]) {
image.addClass("km-image").prependTo(button);
} else {
button.prepend(iconSpan);
if (icon) {
iconSpan.addClass("km-" + icon);
if (badge || badge === 0) {
createBadge(badge).insertAfter(iconSpan);
}
}
}
},
refresh: function(e) {
var url = e.view.element.attr(kendo.attr("url"));
if (!this.switchTo(e.view.id) && url) {
this.switchTo(url);
}
},
options: {
name: "TabStrip",
selectedIndex: 0,
enable: true
}
});
ui.plugin(TabStrip);
})(window.kendo.jQuery);
return window.kendo;
}, typeof define == 'function' && define.amd ? define : function(_, f){ f(); });