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

Commit baa6932

Browse files
author
Gabriel Schulhof
committed
Filterable: As part of backcompat, listview refresh refreshes filterable
Closes gh-7339 Fixes gh-5680
1 parent 65e81c0 commit baa6932

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

js/widgets/filterable.backcompat.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,31 @@ $.widget( "mobile.listview", $.mobile.listview, {
205205
this.element.filterable();
206206
}
207207
return this._super();
208+
},
209+
210+
_afterListviewRefresh: function() {
211+
var filterable = this.element.data( "mobile-filterable" );
212+
213+
if ( this.options.filter === true && filterable ) {
214+
this._preventRefreshLoop = true;
215+
filterable.refresh();
216+
}
217+
},
218+
219+
// Eliminate infinite recursion caused by the fact that we call filterable.refresh() from
220+
// _afterListviewRefresh() above, which, in turn, calls _refreshChildWidget(), which, in
221+
// turn, calls listview refresh(), which would, in turn, calls _afterListviewRefresh()
222+
// above, if we wouldn't prevent that right here.
223+
refresh: function() {
224+
var returnValue;
225+
226+
if ( !this._preventRefreshLoop ) {
227+
returnValue = this._superApply( arguments );
228+
}
229+
230+
this._preventRefreshLoop = false;
231+
232+
return returnValue;
208233
}
209234
});
210235

tests/unit/filterable/filterable_core.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ test( "Filterable input prevents default on ENTER", function() {
4444
deepEqual( event.isDefaultPrevented(), true, "Subsequent keypress default is also prevented" );
4545
});
4646

47+
module( "Filterable backwards compatibility" );
48+
4749
asyncTest( "Working filterable is instantiated on dynamic listview when data-filter='true'", function() {
4850
var list = $( "<ul data-nstest-filter='true'><li>Chicago</li><li>Berlin</li><li>Windsor</li></ul>" )
4951
.appendTo( "#content" )
@@ -61,4 +63,12 @@ asyncTest( "Working filterable is instantiated on dynamic listview when data-fil
6163
}, 500 );
6264
});
6365

66+
test( "Refreshing the listview also refreshes the filterable", function() {
67+
var listview = $( "#listview-refresh-refreshes-filterable" );
68+
69+
listview.append( "<li>Item 3</li><li>Item 4</li><li>Item 5</li>" ).listview( "refresh" );
70+
deepEqual( listview.children( ".ui-screen-hidden" ).length, 5,
71+
"All list items are hidden after listview refresh" );
72+
});
73+
6474
})( jQuery );

tests/unit/filterable/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<li>Test 2</li>
6666
<li>Test 3</li>
6767
</ul>
68+
69+
<ul id="listview-refresh-refreshes-filterable" data-nstest-filter="true" data-nstest-filter-reveal="true" data-nstest-role="listview">
70+
<li>Item 1</li>
71+
<li>Item 2</li>
72+
</ul>
6873
</div>
6974
</div>
7075
</body>

0 commit comments

Comments
 (0)