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

Commit de77290

Browse files
author
Gabriel Schulhof
committed
Listview: Move sparing refresh() decision to backcompat
The decision is delegated to extension points (one for the list item and one the anchor(s) it may contain) which are predicates that always return true if the backcompat extension is absent, indicating for every item that it is to be processed. When the backcompat extension is present, the extension points contain the class-examining regex-based decision of previous versions.
1 parent 4624b7a commit de77290

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

js/widgets/listview.backcompat.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@
3232
} )( function( $ ) {
3333

3434
if ( $.mobileBackcompat !== false ) {
35+
var listviewItemClassRegex = /\bui-listview-item-static\b|\bui-listview-item-divider\b/;
36+
var buttonClassRegex = /\bui-button\b/;
37+
3538
$.widget( "mobile.listview", $.mobile.listview, {
3639
options: {
3740
corners: true,
3841
shadow: true
3942
},
40-
classProp: "ui-listview-inset"
43+
classProp: "ui-listview-inset",
44+
_processListItem: function( item ) {
45+
return !listviewItemClassRegex.test( item[ 0 ].className );
46+
},
47+
48+
_processListItemAnchor: function( a ) {
49+
return !buttonClassRegex.test( a[ 0 ].className );
50+
}
4151
} );
4252
$.widget( "mobile.listview", $.mobile.listview, $.mobile.widget.backcompat );
4353
}

js/widgets/listview.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ function addItemToDictionary( itemClassDict, element, key, extra ) {
4343
}
4444

4545
var getAttribute = $.mobile.getAttribute,
46-
countBubbleClassRegex = /\bui-listview-item-count-bubble\b/,
47-
listviewItemClassRegex = /\bui-listview-item-static\b|\bui-listview-item-divider\b/,
48-
buttonClassRegex = /\bui-button\b/;
46+
countBubbleClassRegex = /\bui-listview-item-count-bubble\b/;
4947

5048
function filterBubbleSpan() {
5149
var child, parentNode,
@@ -135,6 +133,14 @@ return $.widget( "mobile.listview", $.extend( {
135133
this._refresh();
136134
},
137135

136+
_processListItem: function( /* item */ ) {
137+
return true;
138+
},
139+
140+
_processListItemAnchor: function( /* a */ ) {
141+
return true;
142+
},
143+
138144
_refresh: function( create ) {
139145
var buttonClass, pos, numli, item, itemClass, itemExtraClass, itemTheme, itemIcon, icon, a,
140146
isDivider, startCount, newStartCount, value, last, splittheme, splitThemeClass, li, ol,
@@ -162,13 +168,13 @@ return $.widget( "mobile.listview", $.extend( {
162168
itemClass = "ui-listview-item";
163169
itemExtraClass = undefined;
164170

165-
if ( create || !listviewItemClassRegex.test( item[ 0 ].className ) ) {
171+
if ( create || this._processListItem( item ) ) {
166172
a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
167173
isDivider = ( getAttribute( item[ 0 ], "role" ) === "list-divider" );
168174
value = item.attr( "value" );
169175
itemTheme = getAttribute( item[ 0 ], "theme" );
170176

171-
if ( a.length && ( ( !buttonClassRegex.test( a[ 0 ].className ) && !isDivider ) ||
177+
if ( a.length && ( ( this._processListItemAnchor( a ) && !isDivider ) ||
172178
create ) ) {
173179
itemIcon = getAttribute( item[ 0 ], "icon" );
174180
icon = ( itemIcon === false ) ? false : ( itemIcon || currentOptions.icon );

0 commit comments

Comments
 (0)