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

Commit 6ddfca9

Browse files
Listview: No more jsCount, only use pseudo elements for list numbering. Take value attribute into account: fixes #5884.
1 parent 60aa05b commit 6ddfca9

File tree

2 files changed

+20
-42
lines changed

2 files changed

+20
-42
lines changed

css/structure/jquery.mobile.listview.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,14 @@ ol.ui-listview .ui-li-divider {
200200
counter-reset: listnumbering;
201201
}
202202
ol.ui-listview .ui-li > .ui-btn:before,
203-
ol.ui-listview .ui-li-static:before,
204-
.ui-li-dec {
203+
ol.ui-listview .ui-li-static:before {
205204
font-size: .8em;
206205
display: inline-block;
207206
padding-right: .3em;
208207
font-weight: normal;
209208
counter-increment: listnumbering;
210209
content: counter(listnumbering) ". ";
211210
}
212-
ol.ui-listview .ui-li-jsnumbering:before {
213-
content: "" !important;
214-
}
215211
ol.ui-listview .ui-li-heading {
216212
display: inline-block;
217213
width: 100%;

js/widgets/listview.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,16 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
108108
listicon = getAttr( $list[ 0 ], "icon", true ),
109109
li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
110110
ol = !!$.nodeName( $list[ 0 ], "ol" ),
111-
jsCount = !$.support.cssPseudoElement,
112111
start = $list.attr( "start" ),
113112
itemClassDict = {},
114113
item, itemClass, itemTheme,
115-
a, last, splittheme, counter, startCount, newStartCount, countParent, icon, linkIcon,
114+
a, last, splittheme, startCount, newStartCount, value, countParent, icon, linkIcon,
116115
pos, numli, isDivider, buttonClass;
117116

118-
if ( ol && jsCount ) {
119-
$list.find( ".ui-li-dec" ).remove();
120-
}
121-
122-
if ( ol ) {
123-
// Check if a start attribute has been set while taking a value of 0 into account
124-
if ( start || start === 0 ) {
125-
if ( !jsCount ) {
126-
startCount = parseInt( start , 10 ) - 1;
127-
$list.css( "counter-reset", "listnumbering " + startCount );
128-
} else {
129-
counter = parseInt( start , 10 );
130-
}
131-
} else if ( jsCount ) {
132-
counter = 1;
133-
}
117+
// Check if a start attribute has been set while taking a value of 0 into account
118+
if ( ol && ( start || start === 0 ) ) {
119+
startCount = parseInt( start, 10 ) - 1;
120+
$list.css( "counter-reset", "listnumbering " + startCount );
134121
}
135122

136123
if ( !o.theme ) {
@@ -145,6 +132,7 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
145132
if ( create || !item.hasClass( "ui-li" ) ) {
146133
itemTheme = getAttr( item[ 0 ], "theme", true ) || o.theme;
147134
a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
135+
value = item.attr( "value" );
148136
isDivider = ( getAttr( item[ 0 ], "role", true ) === "list-divider" );
149137

150138
if ( a.length && !isDivider ) {
@@ -170,6 +158,11 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
170158
}
171159

172160
a.first().removeClass( "ui-link" ).addClass( buttonClass );
161+
162+
if ( ol && value ) {
163+
newStartCount = parseInt( value , 10 ) - 1;
164+
a.css( "counter-reset", "listnumbering " + newStartCount );
165+
}
173166

174167
if ( a.length > 1 ) {
175168
itemClass += " ui-li-has-alt";
@@ -206,32 +199,21 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
206199
itemClass += " ui-li-divider ui-bar-" + ( getAttr( item[ 0 ], "theme", true ) || dividertheme );
207200
item.attr( "role", "heading" );
208201

209-
if ( ol ) {
210-
//reset counter when a divider heading is encountered
211-
if ( start || start === 0 ) {
212-
if ( !jsCount ) {
213-
newStartCount = parseInt( start , 10 ) - 1;
214-
item.css( "counter-reset", "listnumbering " + newStartCount );
215-
} else {
216-
counter = parseInt( start , 10 );
217-
}
218-
} else if ( jsCount ) {
219-
counter = 1;
220-
}
202+
if ( ol && ( start || start === 0 ) ) {
203+
newStartCount = parseInt( start , 10 ) - 1;
204+
item.css( "counter-reset", "listnumbering " + newStartCount );
221205
}
222206

223207
} else {
224208
itemClass += " ui-li-static ui-body-" + itemTheme;
209+
210+
if ( ol && value ) {
211+
newStartCount = parseInt( value , 10 ) - 1;
212+
item.css( "counter-reset", "listnumbering " + newStartCount );
213+
}
225214
}
226215
}
227216

228-
if ( ol && jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
229-
countParent = itemClass.indexOf( "ui-li-static" ) > 0 ? item : item.find( ".ui-link-inherit" );
230-
231-
countParent.addClass( "ui-li-jsnumbering" )
232-
.prepend( "<span class='ui-li-dec'>" + ( counter++ ) + ". </span>" );
233-
}
234-
235217
// Instead of setting item class directly on the list item and its
236218
// btn-inner at this point in time, push the item into a dictionary
237219
// that tells us what class to set on it so we can do this after this

0 commit comments

Comments
 (0)