-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery.mobile.tabbar.js
39 lines (32 loc) · 1.5 KB
/
jquery.mobile.tabbar.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
(function($) {
$.widget('mobile.tabbar', $.mobile.navbar, {
_create: function() {
// Set the theme before we call the prototype, which will
// ensure buttonMarkup() correctly grabs the inheritied theme.
// We default to the "a" swatch if none is found
var theme = this.element.jqmData('theme') || "a";
this.element.addClass('ui-footer ui-footer-fixed ui-bar-' + theme);
// Make sure the page has padding added to it to account for the fixed bar
this.element.closest('[data-role="page"]').addClass('ui-page-footer-fixed');
// Call the NavBar _create prototype
$.mobile.navbar.prototype._create.call(this);
},
// Set the active URL for the Tab Bar, and highlight that button on the bar
setActive: function(url) {
// Sometimes the active state isn't properly cleared, so we reset it ourselves
this.element.find('a').removeClass('ui-btn-active ui-state-persist');
this.element.find('a[href="' + url + '"]').addClass('ui-btn-active ui-state-persist');
}
});
$(document).on('pagecreate create', function(e) {
return $(e.target).find(":jqmData(role='tabbar')").tabbar();
});
$(document).on('pageshow', ":jqmData(role='page')", function(e) {
// Grab the id of the page that's showing, and select it on the Tab Bar on the page
var tabBar, id = $(e.target).attr('id');
tabBar = $.mobile.activePage.find(':jqmData(role="tabbar")');
if(tabBar.length) {
tabBar.tabbar('setActive', '#' + id);
}
});
})(jQuery);