From 8177ec4bb5c5cecc4cee14dc633f321b9702b8d6 Mon Sep 17 00:00:00 2001 From: "jblas@adobe.com" Date: Mon, 7 Nov 2011 12:38:54 -0800 Subject: [PATCH] Shave another 200-300ms off the 400 listview item page by simply reducing the number of function calls we make during enhancement. - Got rid of _itemApply() and moved it's functionality to the bottom of refresh(), doing finds from $list where we can, and li where we can't. Boom, at least 1200+ less function calls. --- js/jquery.mobile.listview.js | 40 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/js/jquery.mobile.listview.js b/js/jquery.mobile.listview.js index 317875ad..2008827b 100644 --- a/js/jquery.mobile.listview.js +++ b/js/jquery.mobile.listview.js @@ -35,19 +35,6 @@ $.widget( "mobile.listview", $.mobile.widget, { t.refresh( true ); }, - _itemApply: function( $list, item ) { - var $countli = item.find( ".ui-li-count" ); - if ( $countli.length ) { - item.addClass( "ui-li-has-count" ); - $countli.addClass( "ui-btn-up-" + ( $list.jqmData( "counttheme" ) || this.options.countTheme ) + " ui-btn-corner-all" ); - } - - // TODO class has to be defined in markup - item.find( ">img:eq(0), .ui-link-inherit>img:eq(0)" ).addClass( "ui-li-thumb" ).each(function() { - item.addClass( $(this).is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" ); - }); - }, - _removeCorners: function( li, which ) { var top = "ui-corner-top ui-corner-tr ui-corner-tl", bot = "ui-corner-bottom ui-corner-br ui-corner-bl"; @@ -205,17 +192,28 @@ $.widget( "mobile.listview", $.mobile.widget, { } item.add( item.children( ".ui-btn-inner" ) ).addClass( itemClass ); - - self._itemApply( $list, item ); } - $list.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" ).end() - .find( "p, dl" ).addClass( "ui-li-desc" ).end() - .find( ".ui-li-aside" ).each(function() { - var $this = $(this); - $this.prependTo( $this.parent() ); //shift aside to front for css float - }); + $list.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" ) + .end() + .find( "p, dl" ).addClass( "ui-li-desc" ) + .end() + + .find( ".ui-li-aside" ).each(function() { + var $this = $(this); + $this.prependTo( $this.parent() ); //shift aside to front for css float + }) + .end() + + .find( ".ui-li-count" ).each( function() { + $( this ).closest( "li" ).addClass( "ui-li-has-count" ); + }).addClass( "ui-btn-up-" + ( $list.jqmData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" ); + + li.find( ">img:eq(0), .ui-link-inherit>img:eq(0)" ).addClass( "ui-li-thumb" ).each(function() { + var $this = $( this ); + $this.closest( "li" ).addClass( $this.is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" ); + }); this._refreshCorners( create ); },