Permalink
Browse files

Listview Filter: Prevent onKeyUp handler to be called twice for the s…

…ame value
  • Loading branch information...
1 parent e0602bb commit 03775e93f2a0ec31c65142fd69e2bd7ff87e3f4b @gseguin gseguin committed Jan 4, 2013
Showing with 12 additions and 7 deletions.
  1. +12 −7 js/widgets/listview.filter.js
@@ -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();

0 comments on commit 03775e9

Please sign in to comment.