@@ -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,40 +129,55 @@ 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
- isDivider , startCount , newStartCount , value , last , splittheme , splitThemeClass , li , ol ,
137
- altButtonClass , dividerTheme , start , itemClassDict , dictionaryKey , span , spliticon ,
150
+ isDivider , value , last , splittheme , li , dictionaryKey , span , allItems , newSpan ,
138
151
currentOptions = this . options ,
139
- createEnhanced = create && this . options . enhanced ,
140
- list = this . element ;
141
-
142
- ol = ! ! $ . nodeName ( list [ 0 ] , "ol" ) ;
143
- start = list . attr ( "start" ) ;
144
- itemClassDict = { } ;
152
+ list = this . element ,
153
+ ol = ! ! $ . nodeName ( list [ 0 ] , "ol" ) ,
154
+ start = list . attr ( "start" ) ,
155
+ itemClassDict = { } ;
145
156
146
157
// Check if a start attribute has been set while taking a value of 0 into account
147
158
if ( ol && ( start || start === 0 ) ) {
148
- startCount = parseInt ( start , 10 ) - 1 ;
149
- list . css ( "counter-reset" , "listnumbering " + startCount ) ;
159
+ list . css ( "counter-reset" , "listnumbering " + ( parseInt ( start , 10 ) - 1 ) ) ;
150
160
}
151
161
152
162
this . _beforeListviewRefresh ( ) ;
153
163
154
- li = this . _getChildrenByTagName ( list [ 0 ] , "li" , "LI" ) ;
164
+ // We need all items even if a set was passed in - we just won't iterate over them in the
165
+ // main refresh loop.
166
+ allItems = this . _getChildrenByTagName ( list [ 0 ] , "li" , "LI" ) ;
167
+ li = items || allItems ;
155
168
156
169
for ( pos = 0 , numli = li . length ; pos < numli ; pos ++ ) {
157
170
item = li . eq ( pos ) ;
158
171
itemClass = "ui-listview-item" ;
159
172
itemExtraClass = undefined ;
160
173
161
- if ( create || ! listviewItemClassRegex . test ( item [ 0 ] . className ) ) {
174
+ if ( create || this . _processListItem ( item ) ) {
162
175
a = this . _getChildrenByTagName ( item [ 0 ] , "a" , "A" ) ;
163
176
isDivider = ( getAttribute ( item [ 0 ] , "role" ) === "list-divider" ) ;
164
177
value = item . attr ( "value" ) ;
165
178
itemTheme = getAttribute ( item [ 0 ] , "theme" ) ;
166
179
167
- if ( a . length && ( ( ! buttonClassRegex . test ( a [ 0 ] . className ) && ! isDivider ) ||
180
+ if ( a . length && ( ( this . _processListItemAnchor ( a ) && ! isDivider ) ||
168
181
create ) ) {
169
182
itemIcon = getAttribute ( item [ 0 ] , "icon" ) ;
170
183
icon = ( itemIcon === false ) ? false : ( itemIcon || currentOptions . icon ) ;
@@ -176,35 +189,48 @@ return $.widget( "mobile.listview", $.extend( {
176
189
}
177
190
178
191
if ( a . length > 1 ) {
179
- itemClass = "ui-listview-item-has-alternate" ;
192
+ itemClass + = " ui-listview-item-has-alternate" ;
180
193
181
194
last = a . last ( ) ;
182
195
splittheme = getAttribute ( last [ 0 ] , "theme" ) ||
183
- currentOptions . splitTheme || getAttribute ( item [ 0 ] , "theme" , true ) ;
184
- splitThemeClass = splittheme ? " ui-button-" + splittheme : "" ;
185
- spliticon = getAttribute ( last [ 0 ] , "icon" ) ||
186
- getAttribute ( item [ 0 ] , "icon" ) || currentOptions . splitIcon ;
187
- altButtonClass = "ui-button ui-button-icon-only" + splitThemeClass ;
188
-
189
- span = createEnhanced ? last . children ( ".ui-listview-item-split-icon" ) :
190
- $ ( "<span>" ) ;
196
+ currentOptions . splitTheme || itemTheme ;
197
+
198
+ newSpan = false ;
199
+ span = last . children ( ".ui-listview-item-split-icon" ) ;
200
+ if ( ! span . length ) {
201
+ span = $ ( "<span>" ) ;
202
+ newSpan = true ;
203
+ }
204
+
191
205
addItemToDictionary ( itemClassDict , span [ 0 ] ,
192
- "ui-listview-item-split-icon" , "ui-icon ui-icon-" + spliticon ) ;
206
+ "ui-listview-item-split-icon" , "ui-icon ui-icon-" +
207
+ ( getAttribute ( last [ 0 ] , "icon" ) || itemIcon ||
208
+ currentOptions . splitIcon ) ) ;
193
209
addItemToDictionary ( itemClassDict , last [ 0 ] ,
194
- "ui-listview-item-split-button" , altButtonClass ) ;
210
+ "ui-listview-item-split-button" ,
211
+ "ui-button ui-button-icon-only" +
212
+ ( splittheme ? " ui-button-" + splittheme : "" ) ) ;
195
213
last . attr ( "title" , $ . trim ( last . getEncodedText ( ) ) ) ;
196
- if ( ! createEnhanced ) {
214
+
215
+ if ( newSpan ) {
197
216
last . empty ( ) . prepend ( span ) ;
198
217
}
199
218
200
219
// Reduce to the first anchor, because only the first gets the buttonClass
201
220
a = a . first ( ) ;
202
221
} else if ( icon ) {
203
- span = createEnhanced ? a . children ( ".ui-listview-item-icon" ) :
204
- $ ( "<span>" ) ;
222
+
223
+ newSpan = false ;
224
+ span = a . children ( ".ui-listview-item-icon" ) ;
225
+ if ( ! span . length ) {
226
+ span = $ ( "<span>" ) ;
227
+ newSpan = true ;
228
+ }
229
+
205
230
addItemToDictionary ( itemClassDict , span [ 0 ] , "ui-listview-item-icon" ,
206
231
"ui-icon ui-icon-" + icon + " ui-widget-icon-floatend" ) ;
207
- if ( ! createEnhanced ) {
232
+
233
+ if ( newSpan ) {
208
234
a . prepend ( span ) ;
209
235
}
210
236
}
@@ -213,21 +239,17 @@ return $.widget( "mobile.listview", $.extend( {
213
239
addItemToDictionary ( itemClassDict , a [ 0 ] , "ui-listview-item-button" ,
214
240
buttonClass ) ;
215
241
} else if ( isDivider ) {
216
- dividerTheme = ( getAttribute ( item [ 0 ] , "theme" ) ||
217
- currentOptions . dividerTheme || currentOptions . theme ) ;
218
-
219
- itemClass = "ui-listview-item-divider" ;
220
- itemExtraClass = "ui-bar-" + ( dividerTheme ? dividerTheme : "inherit" ) ;
242
+ itemClass += " ui-listview-item-divider" ;
243
+ itemExtraClass = "ui-bar-" + ( itemTheme || currentOptions . dividerTheme ||
244
+ currentOptions . theme || "inherit" ) ;
221
245
222
246
item . attr ( "role" , "heading" ) ;
223
247
} else if ( a . length <= 0 ) {
224
- itemClass = "ui-listview-item-static" ;
248
+ itemClass + = " ui-listview-item-static" ;
225
249
itemExtraClass = "ui-body-" + ( itemTheme ? itemTheme : "inherit" ) ;
226
250
}
227
251
if ( ol && value ) {
228
- newStartCount = parseInt ( value , 10 ) - 1 ;
229
-
230
- item . css ( "counter-reset" , "listnumbering " + newStartCount ) ;
252
+ item . css ( "counter-reset" , "listnumbering " + ( parseInt ( value , 10 ) - 1 ) ) ;
231
253
}
232
254
}
233
255
@@ -259,7 +281,9 @@ return $.widget( "mobile.listview", $.extend( {
259
281
260
282
this . _afterListviewRefresh ( ) ;
261
283
262
- this . _addFirstLastClasses ( li , this . _getVisibles ( li , create ) , create ) ;
284
+ // NOTE: Using the extension addFirstLastClasses is deprecated as of 1.5.0 and this and the
285
+ // extension itself will be removed in 1.6.0.
286
+ this . _addFirstLastClasses ( allItems , this . _getVisibles ( allItems , create ) , create ) ;
263
287
264
288
// Untrack removed items
265
289
if ( this . _oldListItems ) {
@@ -269,7 +293,7 @@ return $.widget( "mobile.listview", $.extend( {
269
293
} ) ,
270
294
"ui-listview-item ui-listview-item-static ui-listview-item-has-count " +
271
295
"ui-listview-item-has-alternate ui-listview-item-divider" ) ;
272
- this . _oldListItems = li ;
296
+ this . _oldListItems = allItems ;
273
297
}
274
298
}
275
299
} , $ . mobile . behaviors . addFirstLastClasses ) ) ;
0 commit comments