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

Commit ed89730

Browse files
Listview: Deprecated auto detection of thumbs/icons. Add class ui-li-has-thumb/icon to the LI.
1 parent 713bac2 commit ed89730

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

css/structure/jquery.mobile.listview.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,17 @@
143143
.ui-listview .ui-btn[class*="ui-icon-"] .ui-li-count {
144144
right: 3.636em;
145145
}
146-
.ui-listview .ui-li-static > img:first-child,
147-
.ui-listview > li > .ui-btn > img:first-child {
146+
.ui-listview .ui-li-has-thumb > img:first-child,
147+
.ui-listview .ui-li-has-thumb > .ui-btn > img:first-child {
148148
position: absolute;
149149
left: 0;
150150
top: 0;
151151
max-height: 5em;
152152
max-width: 5em;
153153
}
154-
.ui-listview .ui-li-static > img.ui-li-icon,
155-
.ui-listview > li > .ui-btn > img.ui-li-icon {
154+
.ui-listview .ui-li-has-icon > img:first-child,
155+
.ui-listview .ui-li-has-icon > .ui-btn > img:first-child {
156+
position: absolute;
156157
left: .625em;
157158
top: .9em;
158159
max-height: 1em;

js/widgets/listview.js

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
4242
t.refresh( true );
4343
},
4444

45-
// This is a generic utility method for finding the first
46-
// node with a given nodeName. It uses basic DOM traversal
47-
// to be fast and is meant to be a substitute for simple
48-
// $.fn.closest() and $.fn.children() calls on a single
49-
// element. Note that callers must pass both the lowerCase
50-
// and upperCase version of the nodeName they are looking for.
51-
// The main reason for this is that this function will be
52-
// called many times and we want to avoid having to lowercase
53-
// the nodeName from the element every time to ensure we have
54-
// a match. Note that this function lives here for now, but may
55-
// be moved into $.mobile if other components need a similar method.
45+
// TODO: Remove in 1.5
5646
_findFirstElementByTagName: function( ele, nextProp, lcName, ucName ) {
5747
var dict = {};
5848
dict[ lcName ] = dict[ ucName ] = true;
@@ -64,6 +54,16 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
6454
}
6555
return null;
6656
},
57+
// TODO: Remove in 1.5
58+
_addThumbClasses: function( containers ) {
59+
var i, img, len = containers.length;
60+
for ( i = 0; i < len; i++ ) {
61+
img = $( this._findFirstElementByTagName( containers[ i ].firstChild, "nextSibling", "img", "IMG" ) );
62+
if ( img.length ) {
63+
$( this._findFirstElementByTagName( img[ 0 ].parentNode, "parentNode", "li", "LI" ) ).addClass( img.hasClass( "ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
64+
}
65+
}
66+
},
6767

6868
_getChildrenByTagName: function( ele, lcName, ucName ) {
6969
var results = [],
@@ -79,16 +79,6 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
7979
return $( results );
8080
},
8181

82-
_addThumbClasses: function( containers ) {
83-
var i, img, len = containers.length;
84-
for ( i = 0; i < len; i++ ) {
85-
img = $( this._findFirstElementByTagName( containers[ i ].firstChild, "nextSibling", "img", "IMG" ) );
86-
if ( img.length ) {
87-
$( this._findFirstElementByTagName( img[ 0 ].parentNode, "parentNode", "li", "LI" ) ).addClass( img.hasClass( "ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
88-
}
89-
}
90-
},
91-
9282
refresh: function( create ) {
9383
var o = this.options,
9484
$list = this.element,
@@ -190,20 +180,9 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
190180
$( this ).closest( "li" ).addClass( "ui-li-has-count" );
191181
}).addClass( "ui-fill-" + ( getAttr( $list[ 0 ], "counttheme", true ) || this.options.countTheme) + " ui-corner-all" );
192182

193-
// The idea here is to look at the first image in the list item
194-
// itself, and any .ui-link-inherit element it may contain, so we
195-
// can place the appropriate classes on the image and list item.
196-
// Note that we used to use something like:
197-
//
198-
// li.find(">img:eq(0), .ui-link-inherit>img:eq(0)").each( ... );
199-
//
200-
// But executing a find() like that on Windows Phone 7.5 took a
201-
// really long time. Walking things manually with the code below
202-
// allows the 400 listview item page to load in about 3 seconds as
203-
// opposed to 30 seconds.
204-
183+
// Deprecated in 1.4. From 1.5 you have to add class ui-li-has-thumb or ui-li-has-icon to the LI.
205184
this._addThumbClasses( li );
206-
this._addThumbClasses( $list.find( "li > .ui-btn" ) );
185+
this._addThumbClasses( li.find( ".ui-btn" ) );
207186

208187
this._addFirstLastClasses( li, this._getVisibles( li, create ), create );
209188
// autodividers binds to this to redraw dividers after the listview refresh

0 commit comments

Comments
 (0)