@@ -44,23 +44,26 @@ return $.widget( "mobile.listview", $.extend( {
44
44
splitTheme : null ,
45
45
corners : true ,
46
46
shadow : true ,
47
- inset : false
47
+ inset : false ,
48
+ enhanced : false
48
49
} ,
49
50
50
51
_create : function ( ) {
51
52
var t = this ,
53
+ o = t . options ,
52
54
listviewClasses = "" ;
53
55
54
- listviewClasses += t . options . inset ? " ui-listview-inset" : "" ;
56
+ if ( ! o . enhanced ) {
57
+ listviewClasses += o . inset ? " ui-listview-inset" : "" ;
55
58
56
- if ( ! ! t . options . inset ) {
57
- listviewClasses += t . options . corners ? " ui-corner-all" : "" ;
58
- listviewClasses += t . options . shadow ? " ui-shadow" : "" ;
59
- }
60
-
61
- // create listview markup
62
- t . element . addClass ( " ui-listview" + listviewClasses ) ;
59
+ if ( ! ! o . inset ) {
60
+ listviewClasses += o . corners ? " ui-corner-all" : "" ;
61
+ listviewClasses += o . shadow ? " ui-shadow" : "" ;
62
+ }
63
63
64
+ // create listview markup
65
+ t . element . addClass ( " ui-listview" + listviewClasses ) ;
66
+ }
64
67
t . refresh ( true ) ;
65
68
} ,
66
69
@@ -108,127 +111,130 @@ return $.widget( "mobile.listview", $.extend( {
108
111
refresh : function ( create ) {
109
112
var buttonClass , pos , numli , item , itemClass , itemTheme , itemIcon , icon , a ,
110
113
isDivider , startCount , newStartCount , value , last , splittheme , splitThemeClass , spliticon ,
111
- altButtonClass , dividerTheme , li ,
114
+ altButtonClass , dividerTheme , li , ol , start , itemClassDict , countBubbles , countTheme , countThemeClass ,
112
115
o = this . options ,
113
- $list = this . element ,
114
- ol = ! ! $ . nodeName ( $list [ 0 ] , "ol" ) ,
115
- start = $list . attr ( "start" ) ,
116
- itemClassDict = { } ,
117
- countBubbles = $list . find ( ".ui-li-count" ) ,
118
- countTheme = getAttr ( $list [ 0 ] , "counttheme" ) || this . options . countTheme ,
116
+ $list = this . element ;
117
+
118
+ if ( ! o . enhanced ) {
119
+ ol = ! ! $ . nodeName ( $list [ 0 ] , "ol" ) ;
120
+ start = $list . attr ( "start" ) ;
121
+ itemClassDict = { } ;
122
+ countBubbles = $list . find ( ".ui-li-count" ) ;
123
+ countTheme = getAttr ( $list [ 0 ] , "counttheme" ) || this . options . countTheme ;
119
124
countThemeClass = countTheme ? "ui-body-" + countTheme : "ui-body-inherit" ;
120
125
121
- if ( o . theme ) {
122
- $list . addClass ( "ui-group-theme-" + o . theme ) ;
123
- }
126
+ if ( o . theme ) {
127
+ $list . addClass ( "ui-group-theme-" + o . theme ) ;
128
+ }
124
129
125
- // Check if a start attribute has been set while taking a value of 0 into account
126
- if ( ol && ( start || start === 0 ) ) {
127
- startCount = parseInt ( start , 10 ) - 1 ;
128
- $list . css ( "counter-reset" , "listnumbering " + startCount ) ;
129
- }
130
+ // Check if a start attribute has been set while taking a value of 0 into account
131
+ if ( ol && ( start || start === 0 ) ) {
132
+ startCount = parseInt ( start , 10 ) - 1 ;
133
+ $list . css ( "counter-reset" , "listnumbering " + startCount ) ;
134
+ }
130
135
131
- this . _beforeListviewRefresh ( ) ;
136
+ this . _beforeListviewRefresh ( ) ;
132
137
133
- li = this . _getChildrenByTagName ( $list [ 0 ] , "li" , "LI" ) ;
138
+ li = this . _getChildrenByTagName ( $list [ 0 ] , "li" , "LI" ) ;
134
139
135
- for ( pos = 0 , numli = li . length ; pos < numli ; pos ++ ) {
136
- item = li . eq ( pos ) ;
137
- itemClass = "" ;
140
+ for ( pos = 0 , numli = li . length ; pos < numli ; pos ++ ) {
141
+ item = li . eq ( pos ) ;
142
+ itemClass = "" ;
138
143
139
- if ( create || item [ 0 ] . className . search ( / \b u i - l i - s t a t i c \b | \b u i - l i - d i v i d e r \b / ) < 0 ) {
140
- a = this . _getChildrenByTagName ( item [ 0 ] , "a" , "A" ) ;
141
- isDivider = ( getAttr ( item [ 0 ] , "role" ) === "list-divider" ) ;
142
- value = item . attr ( "value" ) ;
143
- itemTheme = getAttr ( item [ 0 ] , "theme" ) ;
144
+ if ( create || item [ 0 ] . className . search ( / \b u i - l i - s t a t i c \b | \b u i - l i - d i v i d e r \b / ) < 0 ) {
145
+ a = this . _getChildrenByTagName ( item [ 0 ] , "a" , "A" ) ;
146
+ isDivider = ( getAttr ( item [ 0 ] , "role" ) === "list-divider" ) ;
147
+ value = item . attr ( "value" ) ;
148
+ itemTheme = getAttr ( item [ 0 ] , "theme" ) ;
144
149
145
- if ( a . length && a [ 0 ] . className . search ( / \b u i - b u t t o n \b / ) < 0 && ! isDivider ) {
146
- itemIcon = getAttr ( item [ 0 ] , "icon" ) ;
147
- icon = ( itemIcon === false ) ? false : ( itemIcon || o . icon ) ;
150
+ if ( a . length && a [ 0 ] . className . search ( / \b u i - b u t t o n \b / ) < 0 && ! isDivider ) {
151
+ itemIcon = getAttr ( item [ 0 ] , "icon" ) ;
152
+ icon = ( itemIcon === false ) ? false : ( itemIcon || o . icon ) ;
148
153
149
- // TODO: Remove in 1.5 together with links.js (links.js / .ui-link deprecated in 1.4)
150
- a . removeClass ( "ui-link" ) ;
154
+ // TODO: Remove in 1.5 together with links.js (links.js / .ui-link deprecated in 1.4)
155
+ a . removeClass ( "ui-link" ) ;
151
156
152
- buttonClass = "ui-button" ;
157
+ buttonClass = "ui-button" ;
153
158
154
- if ( itemTheme ) {
155
- buttonClass += " ui-button-" + itemTheme ;
156
- }
159
+ if ( itemTheme ) {
160
+ buttonClass += " ui-button-" + itemTheme ;
161
+ }
157
162
158
- if ( a . length > 1 ) {
159
- itemClass = "ui-li-has-alt" ;
163
+ if ( a . length > 1 ) {
164
+ itemClass = "ui-li-has-alt" ;
160
165
161
- last = a . last ( ) ;
162
- splittheme = getAttr ( last [ 0 ] , "theme" ) || o . splitTheme || getAttr ( item [ 0 ] , "theme" , true ) ;
163
- splitThemeClass = splittheme ? " ui-button-" + splittheme : "" ;
164
- spliticon = getAttr ( last [ 0 ] , "icon" ) || getAttr ( item [ 0 ] , "icon" ) || o . splitIcon ;
165
- altButtonClass = "ui-button ui-button-icon-only ui-icon-" + spliticon + splitThemeClass ;
166
+ last = a . last ( ) ;
167
+ splittheme = getAttr ( last [ 0 ] , "theme" ) || o . splitTheme || getAttr ( item [ 0 ] , "theme" , true ) ;
168
+ splitThemeClass = splittheme ? " ui-button-" + splittheme : "" ;
169
+ spliticon = getAttr ( last [ 0 ] , "icon" ) || getAttr ( item [ 0 ] , "icon" ) || o . splitIcon ;
170
+ altButtonClass = "ui-button ui-button-icon-only ui-icon-" + spliticon + splitThemeClass ;
166
171
167
- last
168
- . attr ( "title" , $ . trim ( last . getEncodedText ( ) ) )
169
- . addClass ( altButtonClass )
170
- . empty ( ) ;
172
+ last
173
+ . attr ( "title" , $ . trim ( last . getEncodedText ( ) ) )
174
+ . addClass ( altButtonClass )
175
+ . empty ( ) ;
171
176
172
- // Reduce to the first anchor, because only the first gets the buttonClass
173
- a = a . first ( ) ;
174
- } else if ( icon ) {
175
- buttonClass += " ui-icon-end ui-icon-" + icon ;
176
- }
177
+ // Reduce to the first anchor, because only the first gets the buttonClass
178
+ a = a . first ( ) ;
179
+ } else if ( icon ) {
180
+ buttonClass += " ui-icon-end ui-icon-" + icon ;
181
+ }
177
182
178
- // Apply buttonClass to the (first) anchor
179
- a . addClass ( buttonClass ) ;
180
- } else if ( isDivider ) {
181
- dividerTheme = ( getAttr ( item [ 0 ] , "theme" ) || o . dividerTheme || o . theme ) ;
183
+ // Apply buttonClass to the (first) anchor
184
+ a . addClass ( buttonClass ) ;
185
+ } else if ( isDivider ) {
186
+ dividerTheme = ( getAttr ( item [ 0 ] , "theme" ) || o . dividerTheme || o . theme ) ;
182
187
183
- itemClass = "ui-li-divider ui-bar-" + ( dividerTheme ? dividerTheme : "inherit" ) ;
188
+ itemClass = "ui-li-divider ui-bar-" + ( dividerTheme ? dividerTheme : "inherit" ) ;
184
189
185
- item . attr ( "role" , "heading" ) ;
186
- } else if ( a . length <= 0 ) {
187
- itemClass = "ui-li-static ui-body-" + ( itemTheme ? itemTheme : "inherit" ) ;
190
+ item . attr ( "role" , "heading" ) ;
191
+ } else if ( a . length <= 0 ) {
192
+ itemClass = "ui-li-static ui-body-" + ( itemTheme ? itemTheme : "inherit" ) ;
193
+ }
194
+ if ( ol && value ) {
195
+ newStartCount = parseInt ( value , 10 ) - 1 ;
196
+
197
+ item . css ( "counter-reset" , "listnumbering " + newStartCount ) ;
198
+ }
188
199
}
189
- if ( ol && value ) {
190
- newStartCount = parseInt ( value , 10 ) - 1 ;
191
200
192
- item . css ( "counter-reset" , "listnumbering " + newStartCount ) ;
201
+ // Instead of setting item class directly on the list item
202
+ // at this point in time, push the item into a dictionary
203
+ // that tells us what class to set on it so we can do this after this
204
+ // processing loop is finished.
205
+
206
+ if ( ! itemClassDict [ itemClass ] ) {
207
+ itemClassDict [ itemClass ] = [ ] ;
193
208
}
209
+
210
+ itemClassDict [ itemClass ] . push ( item [ 0 ] ) ;
194
211
}
195
212
196
- // Instead of setting item class directly on the list item
197
- // at this point in time, push the item into a dictionary
198
- // that tells us what class to set on it so we can do this after this
199
- // processing loop is finished.
213
+ // Set the appropriate listview item classes on each list item.
214
+ // The main reason we didn't do this
215
+ // in the for-loop above is because we can eliminate per-item function overhead
216
+ // by calling addClass() and children() once or twice afterwards. This
217
+ // can give us a significant boost on platforms like WP7.5.
200
218
201
- if ( ! itemClassDict [ itemClass ] ) {
202
- itemClassDict [ itemClass ] = [ ] ;
219
+ for ( itemClass in itemClassDict ) {
220
+ $ ( itemClassDict [ itemClass ] ) . addClass ( itemClass ) ;
203
221
}
204
222
205
- itemClassDict [ itemClass ] . push ( item [ 0 ] ) ;
206
- }
223
+ countBubbles . each ( function ( ) {
224
+ $ ( this ) . closest ( "li" ) . addClass ( "ui-li-has-count" ) ;
225
+ } ) ;
226
+ if ( countThemeClass ) {
227
+ countBubbles . not ( "[class*='ui-body-']" ) . addClass ( countThemeClass ) ;
228
+ }
207
229
208
- // Set the appropriate listview item classes on each list item.
209
- // The main reason we didn't do this
210
- // in the for-loop above is because we can eliminate per-item function overhead
211
- // by calling addClass() and children() once or twice afterwards. This
212
- // can give us a significant boost on platforms like WP7.5.
230
+ // Deprecated in 1.4. From 1.5 you have to add class ui-li-has-thumb or ui-li-has-icon to the LI.
231
+ this . _addThumbClasses ( li ) ;
232
+ this . _addThumbClasses ( li . find ( ".ui-button" ) ) ;
213
233
214
- for ( itemClass in itemClassDict ) {
215
- $ ( itemClassDict [ itemClass ] ) . addClass ( itemClass ) ;
216
- }
234
+ this . _afterListviewRefresh ( ) ;
217
235
218
- countBubbles . each ( function ( ) {
219
- $ ( this ) . closest ( "li" ) . addClass ( "ui-li-has-count" ) ;
220
- } ) ;
221
- if ( countThemeClass ) {
222
- countBubbles . not ( "[class*='ui-body-']" ) . addClass ( countThemeClass ) ;
236
+ this . _addFirstLastClasses ( li , this . _getVisibles ( li , create ) , create ) ;
223
237
}
224
-
225
- // Deprecated in 1.4. From 1.5 you have to add class ui-li-has-thumb or ui-li-has-icon to the LI.
226
- this . _addThumbClasses ( li ) ;
227
- this . _addThumbClasses ( li . find ( ".ui-button" ) ) ;
228
-
229
- this . _afterListviewRefresh ( ) ;
230
-
231
- this . _addFirstLastClasses ( li , this . _getVisibles ( li , create ) , create ) ;
232
238
}
233
239
} , $ . mobile . behaviors . addFirstLastClasses ) ) ;
234
240
0 commit comments