Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit aa99674

Browse files
Listview: Added support for start attribute on numbered listviews. Fixes #4613 - Ordered list ignores "start" attribute.
1 parent 82d0eaf commit aa99674

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

js/jquery.mobile.listview.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,34 @@ $.widget( "mobile.listview", $.mobile.widget, {
155155
var o = this.options,
156156
$list = this.element,
157157
self = this,
158+
listIcon = $list.jqmData( "icon" ) || o.icon,
158159
dividertheme = $list.jqmData( "dividertheme" ) || o.dividerTheme,
159160
listsplittheme = $list.jqmData( "splittheme" ),
160161
listspliticon = $list.jqmData( "spliticon" ),
161162
li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
162-
counter = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? 0 : 1,
163+
jsCount = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? false : true,
164+
start = $list.attr( "start" ),
163165
itemClassDict = {},
164166
item, itemClass, itemTheme,
165-
a, last, splittheme, countParent, icon, imgParents, img, linkIcon;
167+
a, last, splittheme, counter, countParent, icon, imgParents, img, linkIcon;
166168

167-
if ( counter ) {
169+
if ( jsCount ) {
168170
$list.find( ".ui-li-dec" ).remove();
169171
}
172+
173+
// Check if a start attribute has been set and take a value of 0 into account
174+
if ( typeof start !== "undefined" && start !== false ) {
175+
if ( !jsCount ) {
176+
var startAt = parseInt( start ) - 1;
177+
$list.css( "counter-reset", "listnumbering " + startAt );
178+
} else {
179+
counter = parseInt( start );
180+
}
181+
} else {
182+
if ( jsCount ) {
183+
counter = 1;
184+
}
185+
}
170186

171187
if ( !o.theme ) {
172188
o.theme = $.mobile.getInheritedTheme( this.element, "c" );
@@ -236,16 +252,25 @@ $.widget( "mobile.listview", $.mobile.widget, {
236252
item.attr( "role", "heading" );
237253

238254
//reset counter when a divider heading is encountered
239-
if ( counter ) {
240-
counter = 1;
255+
if ( typeof start !== "undefined" && start !== false ) {
256+
if ( !jsCount ) {
257+
var startAt = parseInt( start ) - 1;
258+
item.css( "counter-reset", "listnumbering " + startAt );
259+
} else {
260+
counter = parseInt( start );
261+
}
262+
} else {
263+
if ( jsCount ) {
264+
counter = 1;
265+
}
241266
}
242267

243268
} else {
244269
itemClass += " ui-li-static ui-body-" + itemTheme;
245270
}
246271
}
247272

248-
if ( counter && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
273+
if ( jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
249274
countParent = itemClass.indexOf( "ui-li-static" ) > 0 ? item : item.find( ".ui-link-inherit" );
250275

251276
countParent.addClass( "ui-li-jsnumbering" )

0 commit comments

Comments
 (0)