Skip to content

Commit 683d732

Browse files
committed
Reduced number of calls to addClass.
1 parent f91b252 commit 683d732

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

js/jquery.mobile.listview.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ $.widget( "mobile.listview", $.mobile.widget, {
120120
$list = this.element,
121121
dividertheme = $list.data( "dividertheme" ) || o.dividerTheme,
122122
li = $list.children( "li" ),
123-
counter = jQuery.support.cssPseudoElement || !jQuery.nodeName( $list[0], "ol" ) ? 0 : 1;
123+
counter = jQuery.support.cssPseudoElement || !jQuery.nodeName( $list[0], "ol" ) ? 0 : 1,
124+
itemClass = "ui-li";
124125

125126
if ( counter ) {
126127
$list.find( ".ui-li-dec" ).remove();
@@ -138,8 +139,6 @@ $.widget( "mobile.listview", $.mobile.widget, {
138139
return;
139140
}
140141

141-
item.addClass( "ui-li" );
142-
143142
var a = item.find( "a" );
144143

145144
if ( a.length ) {
@@ -156,7 +155,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
156155
a.first().addClass( "ui-link-inherit" );
157156

158157
if ( a.length > 1 ) {
159-
item.addClass( "ui-li-has-alt" );
158+
itemClass += " ui-li-has-alt";
160159

161160
var last = a.last();
162161

@@ -182,19 +181,26 @@ $.widget( "mobile.listview", $.mobile.widget, {
182181
}
183182

184183
} else if ( item.data( "role" ) === "list-divider" ) {
185-
item.addClass( "ui-li-divider ui-btn ui-bar-" + dividertheme ).attr( "role", "heading" );
184+
itemClass += " ui-li-divider ui-btn ui-bar-" + dividertheme;
185+
item.attr( "role", "heading" );
186+
187+
//reset counter when a divider heading is encountered
188+
if ( counter ) {
189+
counter = 1;
190+
}
186191

187192
} else {
188-
item.addClass( "ui-li-static ui-btn-up-" + o.theme );
193+
itemClass += " ui-li-static ui-btn-up-" + o.theme;
189194
}
190195

191196
if ( pos === 0 ) {
192197
item.find( "img" ).addClass( "ui-corner-tl" );
193198

194199
if ( o.inset ) {
200+
itemClass += " ui-corner-top";
201+
195202
item
196203
.add( item.find( ".ui-btn-inner" ) )
197-
.addClass( "ui-corner-top" )
198204
.find( ".ui-li-link-alt" )
199205
.addClass( "ui-corner-tr" )
200206
.end()
@@ -206,9 +212,10 @@ $.widget( "mobile.listview", $.mobile.widget, {
206212
item.find( "img" ).addClass( "ui-corner-bl" );
207213

208214
if ( o.inset ) {
215+
itemClass += " ui-corner-bottom";
216+
209217
item
210218
.add( item.find( ".ui-btn-inner" ) )
211-
.addClass( "ui-corner-bottom" )
212219
.find( ".ui-li-link-alt" )
213220
.addClass( "ui-corner-br" )
214221
.end()
@@ -217,19 +224,15 @@ $.widget( "mobile.listview", $.mobile.widget, {
217224
}
218225
}
219226

220-
if ( counter ) {
221-
if ( item.hasClass( "ui-li-divider" ) ) {
222-
//reset counter when a divider heading is encountered
223-
counter = 1;
224-
225-
} else {
226-
item
227-
.find( ".ui-link-inherit" ).first()
228-
.addClass( "ui-li-jsnumbering" )
229-
.prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
230-
}
227+
if ( counter && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
228+
item
229+
.find( ".ui-link-inherit" ).first()
230+
.addClass( "ui-li-jsnumbering" )
231+
.prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
231232
}
232233

234+
item.addClass( itemClass );
235+
233236
if ( !create ) {
234237
this._itemApply( $list, item );
235238
}

0 commit comments

Comments
 (0)