Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix for issue 5198 #5419

Merged
merged 2 commits into from Jan 9, 2013
Jump to file or symbol
Failed to load files and symbols.
+40 −7
Split
@@ -39,13 +39,7 @@ $( 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 @@ $( 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 @@ $( 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');