Permalink
Browse files

Merge pull request #5419 from gseguin/issue-5198

Fixes #5198
  • Loading branch information...
gseguin committed Jan 9, 2013
2 parents 8c3c008 + 88e86a1 commit ec88ea28416f4b96372bccd5475e124868fe0e96
Showing with 40 additions and 7 deletions.
  1. +12 −7 js/widgets/listview.filter.js
  2. +28 −0 tests/unit/listview/listview_core.js
@@ -39,13 +39,7 @@ $.mobile.document.delegate( "ul, ol", "listviewcreate", function() {
e.preventDefault();
search.blur();
}),
- search = $( "<input>", {
- placeholder: listview.options.filterPlaceholder
- })
- .attr( "data-" + $.mobile.ns + "type", "search" )
- .jqmData( "lastval", "" )
- .bind( "keyup change input", function() {
-
+ onKeyUp = function( e ) {
var $this = $( this ),
val = this.value.toLowerCase(),
listItems = null,
@@ -57,6 +51,11 @@ $.mobile.document.delegate( "ul, ol", "listviewcreate", function() {
// Check if a custom filter callback applies
isCustomFilterCallback = listview.options.filterCallback !== defaultFilterCallback;
+ if ( lastval && lastval === val ) {
+ // Execute the handler only once per value change
+ return;
+ }
+
listview._trigger( "beforefilter", "beforefilter", { input: this } );
// Change val as lastval for next execution
@@ -119,7 +118,13 @@ $.mobile.document.delegate( "ul, ol", "listviewcreate", function() {
listItems.toggleClass( "ui-screen-hidden", !!listview.options.filterReveal );
}
listview._addFirstLastClasses( li, listview._getVisibles( li, false ), false );
+ },
+ search = $( "<input>", {
+ placeholder: listview.options.filterPlaceholder
})
+ .attr( "data-" + $.mobile.ns + "type", "search" )
+ .jqmData( "lastval", "" )
+ .bind( "keyup change input", onKeyUp )
.appendTo( wrapper )
.textinput();
@@ -467,6 +467,34 @@
]);
});
+ asyncTest( "event listviewbeforefilter firing", function() {
+ var $searchPage = $( searchFilterId );
+ $.testHelper.pageSequence([
+ function() {
+ $.mobile.changePage( searchFilterId );
+ },
+
+ function() {
+ var beforeFilterCount = 0;
+ $searchPage.on( "listviewbeforefilter", function( e ) {
+ beforeFilterCount += 1;
+ });
+ $searchPage.find( 'input' ).val( "a" );
+ $searchPage.find( 'input' ).trigger('input');
+ $searchPage.find( 'input' ).trigger('keyup');
+ $searchPage.find( 'input' ).trigger('change');
+ equal( beforeFilterCount, 1, "listviewbeforefilter should fire only once for the same value" );
+
+ $searchPage.find( 'input' ).val( "ab" );
+ $searchPage.find( 'input' ).trigger('input');
+ $searchPage.find( 'input' ).trigger('keyup');
+ equal( beforeFilterCount, 2, "listviewbeforefilter should fire twice since value has changed" );
+
+ start();
+ }
+ ]);
+ });
+
test( "Refresh applies thumb styling", function(){
var ul = $('.ui-page-active ul');

0 comments on commit ec88ea2

Please sign in to comment.