-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathnavbar.xml
181 lines (148 loc) · 9.43 KB
/
navbar.xml
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
179
180
181
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="../entries2html.xsl" ?>
<entry name="navbar" namespace="fn" type="widget" widgetnamespace="mobile" init-selector=":jqmData(role='navbar')">
<title>Navbar Widget</title>
<desc>Creates a navbar widget</desc>
<longdesc>
<h2>Simple navbar</h2>
<p>jQuery Mobile has a very basic navbar widget that is useful for providing up to 5 buttons with optional icons in a bar, typically within a header or footer. There is also a persistent navbar variation that works more like a tab bar that stays fixed as you navigate across pages.</p>
<p>A navbar is coded as an unordered list of links wrapped in a container element that has the <code>data-role="navbar"</code> attribute. This is an example of a two-button navbar:</p>
<pre><code><![CDATA[
<div data-role="navbar">
<ul>
<li><a href="a.html">One</a></li>
<li><a href="b.html">Two</a></li>
</ul>
</div><!-- /navbar -->
]]></code></pre>
<p>When a link in the navbar is clicked it gets the active (selected) state. The <code>ui-btn-active</code> class is first removed from all anchors in the navbar before it is added to the activated link. If this is a link to another page, the class will be removed again after the transition has completed.</p>
<p>To set an item to the active state upon initialization of the navbar, add <code>class="ui-btn-active"</code> to the corresponding anchor in your markup. Additionaly add a class of <code>ui-state-persist</code> to make the framework restore the active state each time the page is shown while it exists in the DOM. The example below shows a navbar with item "One" set to active:</p>
<pre><code><![CDATA[
<div data-role="navbar">
<ul>
<li><a href="a.html" class="ui-btn-active ui-state-persist">One</a></li>
<li><a href="b.html">Two</a></li>
</ul>
</div><!-- /navbar -->
]]></code></pre>
<p>Note that this on applies to navbars that are inside a page. If you use a true persistent toolbar that lives outside the page and want to set current item to the active state, you have to add a script that adds the <code>class="ui-btn-active"</code> class.</p>
<p>The navbar items are set to divide the space evenly so in this case, each button is 1/2 the width of the browser window:
<iframe src="/resources/navbar/example1.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>Adding a third item will automatically make each button 1/3 the width of the browser window:
<iframe src="/resources/navbar/example2.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>Adding a fourth more item will automatically make each button 1/4 the width of the browser window:
<iframe src="/resources/navbar/example3.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>The navbar maxes out with 5 items, each 1/5 the width of the browser window:
<iframe src="/resources/navbar/example4.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>If more than 5 items are added, the navbar will simply wrap to multiple lines:
<iframe src="/resources/navbar/example5.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>Navbars with 1 item will simply render as 100%.
<iframe src="/resources/navbar/example6.html" style="width:100%;height:90px;border:0px"></iframe></p>
<h3>Navbars in headers</h3>
<p>If you want to add a navbar to the top of the page, you can still have a page title and buttons. Just add the navbar container inside the header block, right after the title and buttons in the source order.
<iframe src="/resources/navbar/example7.html" style="width:100%;height:90px;border:0px"></iframe></p>
<h3>Navbars in footers</h3>
<p>If you want to add a navbar to the bottom of the page so it acts more like a tab bar, simply wrap the navbar in a container with a <code>data-role="footer"</code></p>
<pre><code><![CDATA[
<div data-role="footer">
<div data-role="navbar">
<ul>
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
]]></code></pre>
<iframe src="/resources/navbar/example8.html" style="width:100%;height:90px;border:0px"></iframe>
<xi:include href="../includes/widget-theming.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<ul>
<li>
<code>ui-navbar</code>: Outermost container for navbar widget
<ul>
<li>
<code>ui-navbar-row</code>: Rows of navbar systems. This represents every navbar row except first
</li>
<li>
<code>ui-navbar-row-n</code>: (n+1)th row of navbar system except first row
</li>
</ul>
</li>
</ul>
<h3>Icons in navbars</h3>
<p>Icons can be added to navbar items by adding the <code>data-icon</code> attribute specifying a standard mobile icon to each anchor. By default, icons are added above the text (<code>data-iconpos="top"</code>). The following examples add icons to a navbar in a footer.</p>
<iframe src="/resources/navbar/example9.html" style="width:100%;height:90px;border:0px"></iframe>
<p>The icon position is set <em>on the navbar container</em> instead of for individual links within for visual consistency. For example, to place the icons below the labels, add the <code>data-iconpos="bottom"</code> attribute to the navbar container.</p>
<pre><code><![CDATA[
<div data-role="navbar" data-iconpos="bottom">
]]></code></pre>
<p>This will result in a bottom icon alignment:
<iframe src="/resources/navbar/example10.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>The icon position can be set to <code>data-iconpos="left"</code>:
<iframe src="/resources/navbar/example11.html" style="width:100%;height:90px;border:0px"></iframe></p>
<p>Or the icon position can be set to <code>data-iconpos="right"</code>:
<iframe src="/resources/navbar/example12.html" style="width:100%;height:90px;border:0px"></iframe></p>
<h3>Using 3rd party icon sets</h3>
<p>You can add any of the popular icon libraries like Glyphish to achieve the iOS style tab that has large icons stacked on top of text labels. All that is required is a bit of custom styles to link to the icons and position them in the navbar. Here is an example using Glyphish icons and custom styles (view page source for styles) in our navbar:</p>
<iframe src="/resources/navbar/example13.html" style="width:100%;height:90px;border:0px"></iframe>
<p>Icons by Joseph Wain / glyphish.com. Licensed under the Creative Commons Attribution 3.0 United States License.</p>
<h3>Theming navbars</h3>
<p>Navbars inherit the theme swatch from their parent container, just like buttons. If a navbar is placed in the header or footer toolbar, it will inherit the default toolbar swatch "a" for bars unless you set this in the markup. </p>
<p>Here are a few examples of navbars in various container swatches that automatically inherit their parent's swatch letter. Note that in these examples, instead of using a <code>data-theme</code> attribute, we're manually adding the swatch classes to apply the body swatch (<code>ui-body-a</code>) and the class to add the standard body padding (ui-body), but the inheritance works the same way:</p>
<iframe src="/resources/navbar/example14.html" style="width:100%;height:290px;border:0px"></iframe>
<p>To set the theme color for a navbar item, add the <code>data-theme</code> attribute to the individual links and specify a theme swatch. Note that applying a theme swatch to the navbar container is <em>not</em> supported.</p>
<iframe src="/resources/navbar/example15.html" style="width:100%;height:90px;border:0px"></iframe>
</longdesc>
<added>1.0</added>
<options>
<option name="classes" type="Object">
<default>{}</default>
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</option>
<xi:include href="../includes/widget-option-defaults.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-option-defaults.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<option name="iconpos" default='"top"'>
<desc>Positions the icon in the button. Possible values: left, right, top, bottom, none, notext. The notext value will display an icon-only button with no text feedback.
<pre><code><![CDATA[
<div data-role="navbar" data-iconpos="bottom">
]]></code></pre>
</desc>
<type name="String" />
</option>
<xi:include href="../includes/widget-option-initSelector.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</options>
<events>
<event name="create">
<desc>triggered when a navbar is created</desc>
<pre><code><![CDATA[
$( "div" ).navbar({
create: function(event, ui) { ... }
});
]]></code></pre>
</event>
</events>
<example>
<desc>A basic example of a navbar</desc>
<html><![CDATA[
<div data-role="page" id="page1">
<div data-role="header">
<h1>jQuery Mobile Example</h1>
</div>
<div role="main" class="ui-content">
<p>Some Content here</p>
</div>
<div data-role="footer">
<div data-role="navbar">
<ul>
<li><a href="#" class="ui-btn-active">One</a></li>
<li><a href="#">Two</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</div><!-- /page -->]]></html>
</example>
<category slug="widgets"/>
</entry>