@@ -43,9 +43,7 @@ function addItemToDictionary( itemClassDict, element, key, extra ) {
43
43
}
44
44
45
45
var getAttribute = $ . mobile . getAttribute ,
46
- countBubbleClassRegex = / \b u i - l i s t v i e w - i t e m - c o u n t - b u b b l e \b / ,
47
- listviewItemClassRegex = / \b u i - l i s t v i e w - i t e m - s t a t i c \b | \b u i - l i s t v i e w - i t e m - d i v i d e r \b / ,
48
- buttonClassRegex = / \b u i - b u t t o n \b / ;
46
+ countBubbleClassRegex = / \b u i - l i s t v i e w - i t e m - c o u n t - b u b b l e \b / ;
49
47
50
48
function filterBubbleSpan ( ) {
51
49
var child , parentNode ,
@@ -94,7 +92,7 @@ return $.widget( "mobile.listview", $.extend( {
94
92
if ( this . options . inset ) {
95
93
this . _addClass ( "ui-listview-inset" ) ;
96
94
}
97
- this . refresh ( true ) ;
95
+ this . _refresh ( true ) ;
98
96
} ,
99
97
100
98
// We only handle the theme option through the theme extension. Theme options concerning list
@@ -131,12 +129,28 @@ return $.widget( "mobile.listview", $.extend( {
131
129
_beforeListviewRefresh : $ . noop ,
132
130
_afterListviewRefresh : $ . noop ,
133
131
134
- refresh : function ( create ) {
132
+ updateItems : function ( items ) {
133
+ this . _refresh ( false , items ) ;
134
+ } ,
135
+
136
+ refresh : function ( ) {
137
+ this . _refresh ( ) ;
138
+ } ,
139
+
140
+ _processListItem : function ( /* item */ ) {
141
+ return true ;
142
+ } ,
143
+
144
+ _processListItemAnchor : function ( /* a */ ) {
145
+ return true ;
146
+ } ,
147
+
148
+ _refresh : function ( create , items ) {
135
149
var buttonClass , pos , numli , item , itemClass , itemExtraClass , itemTheme , itemIcon , icon , a ,
136
150
isDivider , startCount , newStartCount , value , last , splittheme , splitThemeClass , li , ol ,
137
151
altButtonClass , dividerTheme , start , itemClassDict , dictionaryKey , span , spliticon ,
152
+ allItems , newSpan ,
138
153
currentOptions = this . options ,
139
- createEnhanced = create && this . options . enhanced ,
140
154
list = this . element ;
141
155
142
156
ol = ! ! $ . nodeName ( list [ 0 ] , "ol" ) ;
@@ -151,20 +165,23 @@ return $.widget( "mobile.listview", $.extend( {
151
165
152
166
this . _beforeListviewRefresh ( ) ;
153
167
154
- li = this . _getChildrenByTagName ( list [ 0 ] , "li" , "LI" ) ;
168
+ // We need all items even if a set was passed in - we just won't iterate over them in the
169
+ // main refresh loop.
170
+ allItems = this . _getChildrenByTagName ( list [ 0 ] , "li" , "LI" ) ;
171
+ li = items || allItems ;
155
172
156
173
for ( pos = 0 , numli = li . length ; pos < numli ; pos ++ ) {
157
174
item = li . eq ( pos ) ;
158
175
itemClass = "ui-listview-item" ;
159
176
itemExtraClass = undefined ;
160
177
161
- if ( create || ! listviewItemClassRegex . test ( item [ 0 ] . className ) ) {
178
+ if ( create || this . _processListItem ( item ) ) {
162
179
a = this . _getChildrenByTagName ( item [ 0 ] , "a" , "A" ) ;
163
180
isDivider = ( getAttribute ( item [ 0 ] , "role" ) === "list-divider" ) ;
164
181
value = item . attr ( "value" ) ;
165
182
itemTheme = getAttribute ( item [ 0 ] , "theme" ) ;
166
183
167
- if ( a . length && ( ( ! buttonClassRegex . test ( a [ 0 ] . className ) && ! isDivider ) ||
184
+ if ( a . length && ( ( this . _processListItemAnchor ( a ) && ! isDivider ) ||
168
185
create ) ) {
169
186
itemIcon = getAttribute ( item [ 0 ] , "icon" ) ;
170
187
icon = ( itemIcon === false ) ? false : ( itemIcon || currentOptions . icon ) ;
@@ -176,7 +193,7 @@ return $.widget( "mobile.listview", $.extend( {
176
193
}
177
194
178
195
if ( a . length > 1 ) {
179
- itemClass = "ui-listview-item-has-alternate" ;
196
+ itemClass + = " ui-listview-item-has-alternate" ;
180
197
181
198
last = a . last ( ) ;
182
199
splittheme = getAttribute ( last [ 0 ] , "theme" ) ||
@@ -186,25 +203,38 @@ return $.widget( "mobile.listview", $.extend( {
186
203
getAttribute ( item [ 0 ] , "icon" ) || currentOptions . splitIcon ;
187
204
altButtonClass = "ui-button ui-button-icon-only" + splitThemeClass ;
188
205
189
- span = createEnhanced ? last . children ( ".ui-listview-item-split-icon" ) :
190
- $ ( "<span>" ) ;
206
+ newSpan = false ;
207
+ span = last . children ( ".ui-listview-item-split-icon" ) ;
208
+ if ( ! span . length ) {
209
+ span = $ ( "<span>" ) ;
210
+ newSpan = true ;
211
+ }
212
+
191
213
addItemToDictionary ( itemClassDict , span [ 0 ] ,
192
214
"ui-listview-item-split-icon" , "ui-icon ui-icon-" + spliticon ) ;
193
215
addItemToDictionary ( itemClassDict , last [ 0 ] ,
194
216
"ui-listview-item-split-button" , altButtonClass ) ;
195
217
last . attr ( "title" , $ . trim ( last . getEncodedText ( ) ) ) ;
196
- if ( ! createEnhanced ) {
218
+
219
+ if ( newSpan ) {
197
220
last . empty ( ) . prepend ( span ) ;
198
221
}
199
222
200
223
// Reduce to the first anchor, because only the first gets the buttonClass
201
224
a = a . first ( ) ;
202
225
} else if ( icon ) {
203
- span = createEnhanced ? a . children ( ".ui-listview-item-icon" ) :
204
- $ ( "<span>" ) ;
226
+
227
+ newSpan = false ;
228
+ span = a . children ( ".ui-listview-item-icon" ) ;
229
+ if ( ! span . length ) {
230
+ span = $ ( "<span>" ) ;
231
+ newSpan = true ;
232
+ }
233
+
205
234
addItemToDictionary ( itemClassDict , span [ 0 ] , "ui-listview-item-icon" ,
206
235
"ui-icon ui-icon-" + icon + " ui-widget-icon-floatend" ) ;
207
- if ( ! createEnhanced ) {
236
+
237
+ if ( newSpan ) {
208
238
a . prepend ( span ) ;
209
239
}
210
240
}
@@ -216,12 +246,12 @@ return $.widget( "mobile.listview", $.extend( {
216
246
dividerTheme = ( getAttribute ( item [ 0 ] , "theme" ) ||
217
247
currentOptions . dividerTheme || currentOptions . theme ) ;
218
248
219
- itemClass = "ui-listview-item-divider" ;
249
+ itemClass + = " ui-listview-item-divider" ;
220
250
itemExtraClass = "ui-bar-" + ( dividerTheme ? dividerTheme : "inherit" ) ;
221
251
222
252
item . attr ( "role" , "heading" ) ;
223
253
} else if ( a . length <= 0 ) {
224
- itemClass = "ui-listview-item-static" ;
254
+ itemClass + = " ui-listview-item-static" ;
225
255
itemExtraClass = "ui-body-" + ( itemTheme ? itemTheme : "inherit" ) ;
226
256
}
227
257
if ( ol && value ) {
@@ -259,7 +289,9 @@ return $.widget( "mobile.listview", $.extend( {
259
289
260
290
this . _afterListviewRefresh ( ) ;
261
291
262
- this . _addFirstLastClasses ( li , this . _getVisibles ( li , create ) , create ) ;
292
+ // NOTE: Using the extension addFirstLastClasses is deprecated as of 1.5.0 and this and the
293
+ // extension itself will be removed in 1.6.0.
294
+ this . _addFirstLastClasses ( allItems , this . _getVisibles ( allItems , create ) , create ) ;
263
295
264
296
// Untrack removed items
265
297
if ( this . _oldListItems ) {
@@ -269,7 +301,7 @@ return $.widget( "mobile.listview", $.extend( {
269
301
} ) ,
270
302
"ui-listview-item ui-listview-item-static ui-listview-item-has-count " +
271
303
"ui-listview-item-has-alternate ui-listview-item-divider" ) ;
272
- this . _oldListItems = li ;
304
+ this . _oldListItems = allItems ;
273
305
}
274
306
}
275
307
} , $ . mobile . behaviors . addFirstLastClasses ) ) ;
0 commit comments