Skip to content

Commit 76766a6

Browse files
committed
Speed up listview enhancement for WP 7.5 (Mango). This change allows the 400 listview item page to load in 3-4 seconds instead of 30 seconds.
- Modified refresh() so that it manually checks for the first image in the list item or .ui-link-inherit element. This allows us to avoid executing a selector with a direct descendant and :eq(0) pseudo which is quite slow on WP 7.5 IE.
1 parent 690696c commit 76766a6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

js/jquery.mobile.listview.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
108108
li = $list.children( "li" ),
109109
counter = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? 0 : 1,
110110
item, itemClass, itemTheme,
111-
a, last, splittheme, countParent, icon;
111+
a, last, splittheme, countParent, icon, imgParents, img;
112112

113113
if ( counter ) {
114114
$list.find( ".ui-li-dec" ).remove();
@@ -210,10 +210,26 @@ $.widget( "mobile.listview", $.mobile.widget, {
210210
$( this ).closest( "li" ).addClass( "ui-li-has-count" );
211211
}).addClass( "ui-btn-up-" + ( $list.jqmData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" );
212212

213-
li.find( ".ui-link-inherit>img:eq(0)" ).add( li.children( "img:eq(0)" ) ).addClass( "ui-li-thumb" ).each(function() {
214-
var $this = $( this );
215-
$this.closest( "li" ).addClass( $this.is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
216-
});
213+
// The idea here is to look at the first image in the list item
214+
// itself, and any .ui-link-inherit element it may contain, so we
215+
// can place the appropriate classes on the image and list item.
216+
// Note that we used to use something like:
217+
//
218+
// li.find(">img:eq(0), .ui-link-inherit>img:eq(0)").each( ... );
219+
//
220+
// But executing a find() like that on Windows Phone 7.5 took a
221+
// really long time. Walking things manually with the code below
222+
// allows the 400 listview item page to load in about 3 seconds as
223+
// opposed to 30 seconds.
224+
225+
imgParents = li.add( $list.find( ".ui-link-inherit" ) );
226+
227+
for ( pos = 0; pos < imgParents.length; pos++ ) {
228+
img = imgParents.eq( pos ).children( "img" ).first();
229+
if ( img.length ) {
230+
img.addClass( "ui-li-thumb" ).closest( "li" ).addClass( img.is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
231+
}
232+
}
217233

218234
this._refreshCorners( create );
219235
},

0 commit comments

Comments
 (0)