This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
navbar.js
95 lines (77 loc) · 2.47 KB
/
navbar.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
94
95
/*!
* jQuery Mobile Navbar @VERSION
* http://jquerymobile.com
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
//>>label: Navbars
//>>group: Widgets
//>>description: Formats groups of links as horizontal navigation bars.
//>>docs: http://api.jquerymobile.com/navbar/
//>>demos: http://demos.jquerymobile.com/@VERSION/navbar/
//>>css.structure: ../css/structure/jquery.mobile.navbar.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
( function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define( [
"jquery",
"../widget",
"../grid" ], factory );
} else {
// Browser globals
factory( jQuery );
}
} )( function( $ ) {
return $.widget( "mobile.navbar", {
version: "@VERSION",
options: {
iconpos: "top",
grid: null
},
_create: function() {
var $navbar = this.element,
$navbuttons = $navbar.find( "a, button" ),
iconpos = $navbuttons.filter( ":jqmData(icon)" ).length ? this.options.iconpos : undefined;
$navbar.addClass( "ui-navbar" )
.attr( "role", "navigation" )
.find( "ul" )
.jqmEnhanceable()
.grid( { grid: this.options.grid } );
$navbuttons
.each( function() {
var icon = $.mobile.getAttribute( this, "icon" ),
theme = $.mobile.getAttribute( this, "theme" ),
classes = "ui-button";
if ( theme ) {
classes += " ui-button-" + theme;
}
if ( icon ) {
classes += " ui-icon-" + icon + " ui-button-icon-" + iconpos;
}
$( this ).addClass( classes );
} );
$navbar.delegate( "a", "vclick", function( /* event */ ) {
var activeBtn = $( this );
if ( !( activeBtn.hasClass( "ui-state-disabled" ) ||
// DEPRECATED as of 1.4.0 - remove after 1.4.0 release
// only ui-state-disabled should be present thereafter
activeBtn.hasClass( "ui-disabled" ) ||
activeBtn.hasClass( "ui-button-active" ) ) ) {
$navbuttons.removeClass( "ui-button-active" );
activeBtn.addClass( "ui-button-active" );
// The code below is a workaround to fix #1181
$( document ).one( "pagehide", function() {
activeBtn.removeClass( "ui-button-active" );
} );
}
} );
// Buttons in the navbar with ui-state-persist class should regain their active state before page show
$navbar.closest( ".ui-page" ).bind( "pagebeforeshow", function() {
$navbuttons.filter( ".ui-state-persist" ).addClass( "ui-button-active" );
} );
}
} );
} );