-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathlistview.xml
358 lines (308 loc) · 21.9 KB
/
listview.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="../entries2html.xsl" ?>
<entry name="listview" namespace="fn" type="widget" widgetnamespace="mobile" event-prefix="listview" init-selector=":jqmData(role='listview')">
<title>Listview Widget</title>
<desc>Creates a listview widget</desc>
<longdesc>
<h3>Basic linked lists</h3>
<p>A listview is coded as a simple unordered list containing linked list items with a <code>data-role="listview"</code> attribute. jQuery Mobile will apply all the necessary styles to transform the list into a mobile-friendly listview with right arrow indicator that fills the full width of the browser window. When you tap on the list item, the framework will trigger a click on the first link inside the list item, issue an Ajax request for the URL in the link, create the new page in the DOM, then kick off a page transition. View the <a href="/data-attribute/">data- attribute reference</a> to see all the possible attributes you can add to listviews.</p>
<p>Here is the HTML markup for a basic linked list.</p>
<pre><code><![CDATA[
<ul data-role="listview">
<li><a href="acura.html">Acura</a></li>
<li><a href="audi.html">Audi</a></li>
<li><a href="bmw.html">BMW</a></li>
</ul>
]]></code></pre>
<p><iframe src="/resources/listview/example1.html" style="width:100%;height:990px;border:0px"></iframe></p>
<xi:include href="../includes/widget-theming.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<ul>
<li>
<code>ui-listview</code>: Outermost container for listview widget
<ul>
<li>
<code>ui-listview-item-static</code>: Simplest list item of listview when there are no anchor tags nested inside an item
</li>
<li>
<code>ui-listview-item-divider</code>: List item element which is a divider
</li>
<li>
<code>ui-listview-item-has-alternate</code>: List item element which has more than one anchor elements
<ul>
<li>
<code>ui-listview-item-button</code>: First anchor element
</li>
<li>
<code>ui-listview-item-split-button</code>: Last anchor element
<ul>
<li>
<code>ui-listview-item-split-icon</code>: Icon of last anchor element
</li>
</ul>
</li>
</ul>
</li>
<li>
<code>ui-listview-item</code>: List item element which has only one anchor elements. If the listview item has count bubble, it will additionally have <code>ui-listview-item-has-count</code> class.
<ul>
<li>
<code>ui-listview-item-button</code>: Anchor element of the list item
</li>
<li>
<code>ui-listview-item-icon</code>: Icon for the list item
</li>
<li>
<code>ui-listview-item-count-bubble</code>: Count bubble for list item if present
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Style note on non-inset lists</strong>: all standard, non-inset lists have a -1em (16px) margin to negate the 1em padding on the content area to make lists extend to the edges of the screen. If you add other widgets above or below a list, the negative margin may make these elements overlap so you'll need to add additional spacing in your custom CSS.</p>
<h3>Numbered lists</h3>
<p>Lists can also be created from ordered lists (<code>ol</code>) which is useful when presenting items that are in a sequence such as search results or a movie queue. When the enhanced markup is applied to the listview, jQuery Mobile will try to first use CSS to add numbers to the list and, if not supported, will fall back to injecting numbers with JavaScript.</p>
<p><iframe src="/resources/listview/example3.html" style="width:100%;height:940px;border:0px"></iframe></p>
<h3>Read-only lists</h3>
<p>Listviews can also be used to display a non-interactive list of items, usually as an inset list. This list is built from an unordered or ordered list that don't have linked list items. The framework styles static list items identically to list items containing links, but static items receive the body background color (<code>ui-body-a</code>) rather than the button background color (<code>ui-btn-a</code>).</p>
<p><iframe src="/resources/listview/example4.html" style="width:100%;height:2340px;border:0px"></iframe></p>
<h3>Split button lists</h3>
<p>In cases where there is more than one possible action per list item, a split button can be used to offer two independently clickable items - the list item and a small arrow icon in the far right. To make a split list item, simply add a second link inside the <code>li</code> and the framework will add a vertical divider line, style the link as an icon-only arrow button, and set the <code>title</code> attribute of the link to the text of the link for accessibility.</p>
<p>You can set the icon for the right split icon by specifying a <code>data-split-icon</code> attribute on the listview with an <a href="/classes/#icons">icon name</a> you want. The default icon is "carat-r" but can be configured with the <code>splitIcon</code> <a href="#option-splitIcon">listview option</a>. By adding a <code>data-icon</code> attribute to the list item, you can set individual icons for each split. The theme swatch color of the split button defaults to "b" (blue in the default theme) but can be set by specifying a swatch letter with the <code>data-split-theme</code> attribute at the listview level or for individual splits with the <code>data-theme</code> attribute at the link level.</p>
<p><iframe src="/resources/listview/example5.html" style="width:100%;height:950px;border:0px"></iframe></p>
<h3>List dividers</h3>
<p>List items can be turned into dividers to organize and group the list items. This is done by adding the <code>data-role="list-divider"</code> to any list item. These items are styled with the bar swatch "b" by default (blue in the default theme) but you can specify a theme for dividers by adding the <code>data-divider-theme</code> attribute to the list element (<code>ul</code> or <code>ol</code>) and specifying a theme swatch letter.</p>
<p><iframe src="/resources/listview/example6.html" style="width:100%;height:1410px;border:0px"></iframe></p>
<h3>Autodividers</h3>
<p>A listview can be configured to automatically generate dividers for its items. This is done by adding a <code>data-autodividers="true"</code> attribute to any listview.</p>
<p>By default, the text used to create dividers is the uppercased first letter of the item's text. Alternatively you can specify divider text by setting the <code>autodividersSelector</code> option on the listview programmatically. For example, to add a custom selector to the element with <code>id="mylistview"</code>:</p>
<pre><code><![CDATA[
$( "#mylistview" ).listview({
autodividers: true,
// the selector function is passed a <li> element from the listview;
// it should return the appropriate divider text for that <li>
// element as a string
autodividersSelector: function ( li ) {
var out = /* generate a string based on the content of li */;
return out;
}
});
]]></code></pre>
<p>Note that if you are using formatted list items that contain a floating element (for example <code>ui-li-aside</code>), this element precedes its siblings regardless of the order in your HTML markup. This results in the first character of the floating element being used as divider text. Therefore it is recommended to specify the divider text in this case.</p>
<p>If new list items are added to the list or removed from it, the dividers are <em>not</em> automatically updated: you should call <code>refresh()</code> on the listview to redraw the autodividers.</p>
<p><iframe src="/resources/listview/example7.html" style="width:100%;height:1410px;border:0px"></iframe></p>
<h3>Hiding dividers</h3>
<p>The listview hidedividers extension provides the option <a href="#option-hideDividers"><code>hideDividers</code></a>. When set to true, and you call <code>.listview( "refresh" )</code> after hiding a list item by adding the class <code>ui-screen-hidden</code> to it, the extension will hide those dividers that are followed immediately by another divider.</p>
<p><iframe src="/resources/listview/example17.html" style="width:100%;height:640px;border:0px"></iframe></p>
<h3>Search filter</h3>
<p>As of jQuery Mobile 1.4.0 this functionality has been transferred to the <a href="/filterable/">filterable</a> widget, which provides a more generic solution.</p>
<p><strong>Note:</strong> Features such as automatic text input generation and special handling of listview dividers are deprecated as of 1.4.0. The documentation for <a href="/filterable/">filterable</a> describes the migration path for listviews.</p>
<h3>Filter reveal</h3>
<p>The filter reveal feature makes is easy to build a simple autocomplete with local data. When a filterable list has the <code>data-filter-reveal="true"</code> attribute, it will auto-hide all the list items when the search field is blank. The <code>data-filter-placeholder</code> attribute can be added to specify the placeholder text for the filter. If you need to search against a long list of values, we provide a way to create a filter with a remote data source.</p>
<p><iframe src="/resources/listview/example15.html" style="width:100%;height:240px;border:0px"></iframe></p>
<h3>Remote autocomplete with listview filter</h3>
<p>To use the filter as an autocomplete that taps into remote data sources, you can use the <code>filterablebeforefilter</code> event to dynamically populate a listview as a user types a search query. This is useful when you have a very large data set like cities, zip codes, or products that can't be loaded up-front locally. Use the view source button to see the JavaScript that powers this demo.</p>
<p>If you have a small list of items, you can use the listview filter reveal option to make an autocomplete with local listview data.</p>
<p><iframe src="/resources/listview/example16.html" style="width:100%;height:1040px;border:0px"></iframe></p>
<h3>Cities worldwide</h3>
<p>After you enter <strong>at least three characters</strong> the autocomplete function will show all possible matches.</p>
<h3>Text formatting & counts</h3>
<p>The framework includes text formatting conventions for common list patterns like header/descriptions, secondary information and counts through semantic HTML markup.</p>
<ul>
<li>To add a count indicator to the right of the list item, wrap the number in an element with a class of <code>ui-li-count</code></li>
<li>To add text hierarchy, use headings to increase font emphasis and use paragraphs to reduce emphasis. </li>
<li>Supplemental information can be added to the right of each list item by wrapping content in an element with a class of <code>ui-li-aside</code></li>
</ul>
<p><iframe src="/resources/listview/example10.html" style="width:100%;height:240px;border:0px"></iframe></p>
<p><iframe src="/resources/listview/example11.html" style="width:100%;height:990px;border:0px"></iframe></p>
<h3>Thumbnails & icons</h3>
<p>To add thumbnails to the left of a list item, simply add an image inside a list item as the first child element. The framework will scale the image to 80 pixels square. To use standard 16x16 pixel icons in list items, add the class of <code>ui-li-icon</code> to the image element.</p>
<p><iframe src="/resources/listview/example12.html" style="width:100%;height:940px;border:0px"></iframe></p>
<p><iframe src="/resources/listview/example13.html" style="width:100%;height:290px;border:0px"></iframe></p>
<h3>Inset lists</h3>
<p>If lists are embedded in a page with other types of content, an inset list packages the list into a block that sits inside the content area with a bit of margin and rounded corners (theme controlled). By adding the <code>data-inset="true"</code> attribute to the list (ul or ol), applies the inset appearance.</p>
<p><iframe src="/resources/listview/example14.html" style="width:100%;height:2340px;border:0px"></iframe></p>
<h3>Calling the listview plugin</h3>
<p>You can directly call the listview plugin on any selector, just like any jQuery plugin:</p>
<pre><code><![CDATA[
$( "#mylist" ).listview();
]]></code></pre>
<h3>Updating lists</h3>
<p>If you add items to a listview, you'll need to call the <code>refresh()</code> method on it to update the styles. For example:</p>
<pre><code><![CDATA[
$( "#mylist" ).listview( "refresh" );
]]></code></pre>
<p>Note that the <code>refresh()</code> method only affects <strong>new nodes</strong> appended to a list. This is done for performance reasons. Any list items already enhanced will be ignored by the refresh process. This means that if you change the contents or attributes on an already enhanced list item, these won't be reflected. If you want a list item to be updated, replace it with fresh markup before calling refresh.</p>
<p>If you initially want to hide a list item you can do this by adding a class of <strong><code>ui-screen-hidden</code></strong> to the li element. Using this class ensures the corner styling is applied correctly as well as border-bottom on the last visible item.</p>
</longdesc>
<added>1.0</added>
<options>
<option name="autodividers" default="false" example="true" type="Boolean">
<desc>This option is provided by the <code>listview.autodividers</code> extension.
<p>When set to true, dividers are automatically created for the listview items.</p>
<p>The function stored in the value of the <a href="#option-autodividersSelector">autodividersSelector</a> option governs the text displayed on the dividers.</p>
<p>This option is also exposed as a data-attribute: <code>data-autodividers="true"</code>.</p>
</desc>
</option>
<option name="autodividersSelector" default="n/a" type="Function">
<desc>This option is provided by the <code>listview.autodividers</code> extension.
<p>The value of this option is a function that returns a string. It receives a jQuery collection object containing an element. It computes the returned string from the element. The function is called for each list item in sequence, and a divider is created whenever the function returns a value for a list item that is different from the value it returned for the previous list item.</p>
<p>The function may return <code>null</code> for a given list item. In that case, no new divider is created even if the value returned for the previous list item was something other than <code>null</code>.</p>
<p>The default value of this option is a function that returns the capitalized first letter of the list item text:</p>
<pre><code><![CDATA[
function defaultAutodividersSelector( elt ) {
// look for the text in the given element
var text = $.trim( elt.text() ) || null;
if ( !text ) {
return null;
}
// create the text for the divider (first uppercased letter)
text = text.slice( 0, 1 ).toUpperCase();
return text;
}
]]></code></pre>
</desc>
</option>
<option name="classes" type="Object">
<default>{
"ui-listview-inset": "ui-corner-all ui-shadow"
}</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>
<option name="countTheme" type="String" default="null, inherited from parent" example-value='"b"' deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0.</strong>
<p>Sets the color scheme (swatch) for the list item count bubble. It accepts a single letter from a-z that maps to the swatches included in your theme.</p>
<p>Possible values: swatch letter (a-z).</p>
<p>This option is also exposed as a data attribute: <code>data-count-theme="b"</code>.</p>
</desc>
</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"/>
<option name="dividerTheme" default='null, inherited from parent' example-value='"b"'>
<desc>Sets the color scheme (swatch) for list dividers. It accepts a single letter from a-z that maps to one of the swatches included in your theme.
<p>This option is also exposed as a data attribute: <code>data-divider-theme="b"</code>.</p>
</desc>
<type name="String" />
</option>
<option name="filter" default="false" example-value="true" deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0. It has become the <code>initSelector</code> for the <a href="/filterable/">filterable</a> widget.</strong>
<p>Adds a search filter bar to listviews.</p>
<p>This option is also exposed as a data attribute: <code>data-filter="true"</code>.</p>
</desc>
<type name="Boolean" />
</option>
<option name="filterCallback" default="n/a" deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0. It is now implemented in the <a href="/filterable/#option-filterCallback">filterable</a> widget.</strong>
<p>The function to determine which rows to hide when the search filter textbox changes. The function accepts two arguments -- the text of the list item (or data-filtertext value if present), and the search string. Return true to hide the item, false to leave it visible.</p>
<pre><code><![CDATA[
$( document ).on( "mobileinit", function() {
$.mobile.listview.prototype.options.filterCallback = function( text, searchValue ) {
// only show items that *begin* with the search string
return text.toLowerCase().substring( 0, searchValue.length ) !== searchValue;
};
});
]]></code></pre>
</desc>
<type name="Function" />
</option>
<option name="filterPlaceholder" default='"Filter items..."' example-value='"Search..."' deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0.</strong>
<p>The placeholder text used in search filter bars.</p>
<p>This option is also exposed as a data attribute: <code>data-filter-placeholder="Search..."</code>.</p>
</desc>
<type name="String" />
</option>
<option name="filterReveal" default='false' example-value='true' deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0. It is now implemented in the <a href="/filterable/#option-filterReveal">filterable</a> widget.</strong>
<p>When <code>true</code>, and the search input string is empty, all items are hidden instead of shown.</p>
<p>This option is also exposed as a data attribute: <code>data-filter-reveal="true"</code>.</p>
</desc>
<type name="String" />
</option>
<option name="filterTheme" default='null, inherited from parent' example-value='"b"' deprecated="1.4.0">
<desc>
<strong>This option is deprecated in 1.4.0 and will be removed in 1.5.0.</strong>
<p>Sets the color scheme (swatch) for the search filter bar. It accepts a single letter from a-z that maps to one of the swatches included in your theme.</p>
<p>This option is also exposed as a data attribute: <code>data-filter-theme="a"</code>.</p>
</desc>
<type name="String" />
</option>
<option name="hideDividers" default="false" example-value="true">
<desc>This option is provided by the <code>listview.hidedividers</code> extension.
<p>When set to <code>true</code> and all list items residing under a given divider become hidden, then the divider itself is hidden.</p>
<p>This option is also exposed as a data-attribute: <code>data-hide-dividers="true"</code>.</p>
</desc>
</option>
<option name="icon" default='"carat-r"' example-value='"star"'>
<desc>Applies an icon from the icon set to all linked list buttons.
<p>This option is also exposed as a data attribute: <code>data-icon="star"</code>.</p>
</desc>
<type name="String" />
</option>
<xi:include href="../includes/widget-option-initSelector.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<option name="inset" default="false" example-value="true">
<desc>Adds inset list styles.
<p>This option is also exposed as a data attribute: <code>data-inset="true"</code>.</p>
</desc>
<type name="Boolean" />
</option>
<option name="splitIcon" default='"carat-r"' example-value='"star"'>
<desc>Applies an icon from the icon set to all split list buttons.
<p>This option is also exposed as a data attribute: <code>data-split-icon="star"</code>.</p>
</desc>
<type name="String" />
</option>
<option name="splitTheme" default='null, inherited from parent' example-value='"b"'>
<desc>Sets the color scheme (swatch) for split list buttons. It accepts a single letter from a-z that maps to one of the swatches included in your theme.
<p>This option is also exposed as a data attribute: <code>data-split-theme="b"</code>.</p>
</desc>
<type name="String" />
</option>
<xi:include href="../includes/widget-option-theme.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</options>
<events>
<event name="create" type="listviewcreate">
<desc>triggered when a listview is created</desc>
<argument name="event" type="Event">
<desc></desc>
</argument>
<argument name="ui" type="Object">
<desc></desc>
</argument>
</event>
</events>
<methods>
<method name="refresh">
<desc>update the listview.
<p>If you manipulate a listview via JavaScript (e.g. add new LI elements), you must call the refresh method on it to update the visual styling.</p>
</desc>
</method>
</methods>
<example>
<height>280</height>
<desc>A basic example of a listview</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">
<ul data-role="listview">
<li><a href="index.html">Acura</a></li>
<li><a href="index.html">Audi</a></li>
<li><a href="index.html">BMW</a></li>
<li><a href="index.html">Cadillac</a></li>
<li><a href="index.html">Chrysler</a></li>
</ul>
</div>
<div>
]]></html>
</example>
<category slug="widgets"/>
</entry>