@@ -43,9 +43,7 @@ function addItemToDictionary( itemClassDict, element, key, extra ) {
4343}
4444
4545var 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 / ;
4947
5048function filterBubbleSpan ( ) {
5149 var child , parentNode ,
@@ -94,7 +92,7 @@ return $.widget( "mobile.listview", $.extend( {
9492 if ( this . options . inset ) {
9593 this . _addClass ( "ui-listview-inset" ) ;
9694 }
97- this . refresh ( true ) ;
95+ this . _refresh ( true ) ;
9896 } ,
9997
10098 // We only handle the theme option through the theme extension. Theme options concerning list
@@ -131,40 +129,55 @@ return $.widget( "mobile.listview", $.extend( {
131129 _beforeListviewRefresh : $ . noop ,
132130 _afterListviewRefresh : $ . noop ,
133131
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 ) {
135149 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 ,
138151 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 = { } ;
145156
146157 // Check if a start attribute has been set while taking a value of 0 into account
147158 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 ) ) ;
150160 }
151161
152162 this . _beforeListviewRefresh ( ) ;
153163
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 ;
155168
156169 for ( pos = 0 , numli = li . length ; pos < numli ; pos ++ ) {
157170 item = li . eq ( pos ) ;
158171 itemClass = "ui-listview-item" ;
159172 itemExtraClass = undefined ;
160173
161- if ( create || ! listviewItemClassRegex . test ( item [ 0 ] . className ) ) {
174+ if ( create || this . _processListItem ( item ) ) {
162175 a = this . _getChildrenByTagName ( item [ 0 ] , "a" , "A" ) ;
163176 isDivider = ( getAttribute ( item [ 0 ] , "role" ) === "list-divider" ) ;
164177 value = item . attr ( "value" ) ;
165178 itemTheme = getAttribute ( item [ 0 ] , "theme" ) ;
166179
167- if ( a . length && ( ( ! buttonClassRegex . test ( a [ 0 ] . className ) && ! isDivider ) ||
180+ if ( a . length && ( ( this . _processListItemAnchor ( a ) && ! isDivider ) ||
168181 create ) ) {
169182 itemIcon = getAttribute ( item [ 0 ] , "icon" ) ;
170183 icon = ( itemIcon === false ) ? false : ( itemIcon || currentOptions . icon ) ;
@@ -176,35 +189,48 @@ return $.widget( "mobile.listview", $.extend( {
176189 }
177190
178191 if ( a . length > 1 ) {
179- itemClass = "ui-listview-item-has-alternate" ;
192+ itemClass + = " ui-listview-item-has-alternate" ;
180193
181194 last = a . last ( ) ;
182195 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+
191205 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 ) ) ;
193209 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 : "" ) ) ;
195213 last . attr ( "title" , $ . trim ( last . getEncodedText ( ) ) ) ;
196- if ( ! createEnhanced ) {
214+
215+ if ( newSpan ) {
197216 last . empty ( ) . prepend ( span ) ;
198217 }
199218
200219 // Reduce to the first anchor, because only the first gets the buttonClass
201220 a = a . first ( ) ;
202221 } 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+
205230 addItemToDictionary ( itemClassDict , span [ 0 ] , "ui-listview-item-icon" ,
206231 "ui-icon ui-icon-" + icon + " ui-widget-icon-floatend" ) ;
207- if ( ! createEnhanced ) {
232+
233+ if ( newSpan ) {
208234 a . prepend ( span ) ;
209235 }
210236 }
@@ -213,21 +239,17 @@ return $.widget( "mobile.listview", $.extend( {
213239 addItemToDictionary ( itemClassDict , a [ 0 ] , "ui-listview-item-button" ,
214240 buttonClass ) ;
215241 } 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" ) ;
221245
222246 item . attr ( "role" , "heading" ) ;
223247 } else if ( a . length <= 0 ) {
224- itemClass = "ui-listview-item-static" ;
248+ itemClass + = " ui-listview-item-static" ;
225249 itemExtraClass = "ui-body-" + ( itemTheme ? itemTheme : "inherit" ) ;
226250 }
227251 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 ) ) ;
231253 }
232254 }
233255
@@ -259,7 +281,9 @@ return $.widget( "mobile.listview", $.extend( {
259281
260282 this . _afterListviewRefresh ( ) ;
261283
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 ) ;
263287
264288 // Untrack removed items
265289 if ( this . _oldListItems ) {
@@ -269,7 +293,7 @@ return $.widget( "mobile.listview", $.extend( {
269293 } ) ,
270294 "ui-listview-item ui-listview-item-static ui-listview-item-has-count " +
271295 "ui-listview-item-has-alternate ui-listview-item-divider" ) ;
272- this . _oldListItems = li ;
296+ this . _oldListItems = allItems ;
273297 }
274298 }
275299} , $ . mobile . behaviors . addFirstLastClasses ) ) ;
0 commit comments