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

Commit 03775e9

Browse files
committed
Listview Filter: Prevent onKeyUp handler to be called twice for the same value
1 parent e0602bb commit 03775e9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

js/widgets/listview.filter.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ $( document ).delegate( "ul, ol", "listviewcreate", function() {
3939
e.preventDefault();
4040
search.blur();
4141
}),
42-
search = $( "<input>", {
43-
placeholder: listview.options.filterPlaceholder
44-
})
45-
.attr( "data-" + $.mobile.ns + "type", "search" )
46-
.jqmData( "lastval", "" )
47-
.bind( "keyup change input", function() {
48-
42+
onKeyUp = function( e ) {
4943
var $this = $( this ),
5044
val = this.value.toLowerCase(),
5145
listItems = null,
@@ -57,6 +51,11 @@ $( document ).delegate( "ul, ol", "listviewcreate", function() {
5751
// Check if a custom filter callback applies
5852
isCustomFilterCallback = listview.options.filterCallback !== defaultFilterCallback;
5953

54+
if ( lastval && lastval === val ) {
55+
// Execute the handler only once per value change
56+
return;
57+
}
58+
6059
listview._trigger( "beforefilter", "beforefilter", { input: this } );
6160

6261
// Change val as lastval for next execution
@@ -119,7 +118,13 @@ $( document ).delegate( "ul, ol", "listviewcreate", function() {
119118
listItems.toggleClass( "ui-screen-hidden", !!listview.options.filterReveal );
120119
}
121120
listview._addFirstLastClasses( li, listview._getVisibles( li, false ), false );
121+
},
122+
search = $( "<input>", {
123+
placeholder: listview.options.filterPlaceholder
122124
})
125+
.attr( "data-" + $.mobile.ns + "type", "search" )
126+
.jqmData( "lastval", "" )
127+
.bind( "keyup change input", onKeyUp )
123128
.appendTo( wrapper )
124129
.textinput();
125130

0 commit comments

Comments
 (0)