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

Commit

Permalink
Filterable: As part of backcompat, listview refresh refreshes filterable
Browse files Browse the repository at this point in the history
Closes gh-7339
Fixes gh-5680
  • Loading branch information
Gabriel Schulhof committed May 23, 2014
1 parent 65e81c0 commit baa6932
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions js/widgets/filterable.backcompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@ $.widget( "mobile.listview", $.mobile.listview, {
this.element.filterable();
}
return this._super();
},

_afterListviewRefresh: function() {
var filterable = this.element.data( "mobile-filterable" );

if ( this.options.filter === true && filterable ) {
this._preventRefreshLoop = true;
filterable.refresh();
}
},

// Eliminate infinite recursion caused by the fact that we call filterable.refresh() from
// _afterListviewRefresh() above, which, in turn, calls _refreshChildWidget(), which, in
// turn, calls listview refresh(), which would, in turn, calls _afterListviewRefresh()
// above, if we wouldn't prevent that right here.
refresh: function() {
var returnValue;

if ( !this._preventRefreshLoop ) {
returnValue = this._superApply( arguments );
}

this._preventRefreshLoop = false;

return returnValue;
}
});

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/filterable/filterable_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ test( "Filterable input prevents default on ENTER", function() {
deepEqual( event.isDefaultPrevented(), true, "Subsequent keypress default is also prevented" );
});

module( "Filterable backwards compatibility" );

asyncTest( "Working filterable is instantiated on dynamic listview when data-filter='true'", function() {
var list = $( "<ul data-nstest-filter='true'><li>Chicago</li><li>Berlin</li><li>Windsor</li></ul>" )
.appendTo( "#content" )
Expand All @@ -61,4 +63,12 @@ asyncTest( "Working filterable is instantiated on dynamic listview when data-fil
}, 500 );
});

test( "Refreshing the listview also refreshes the filterable", function() {
var listview = $( "#listview-refresh-refreshes-filterable" );

listview.append( "<li>Item 3</li><li>Item 4</li><li>Item 5</li>" ).listview( "refresh" );
deepEqual( listview.children( ".ui-screen-hidden" ).length, 5,
"All list items are hidden after listview refresh" );
});

})( jQuery );
5 changes: 5 additions & 0 deletions tests/unit/filterable/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<li>Test 2</li>
<li>Test 3</li>
</ul>

<ul id="listview-refresh-refreshes-filterable" data-nstest-filter="true" data-nstest-filter-reveal="true" data-nstest-role="listview">
<li>Item 1</li>
<li>Item 2</li>
</ul>
</div>
</div>
</body>
Expand Down

0 comments on commit baa6932

Please sign in to comment.