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

Commit a9c80c5

Browse files
committed
Listview: New option to start with all items hidden when search input in blank
Please meet: data-filter-reveal Fixes #5090
1 parent 68d8cb5 commit a9c80c5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

js/widgets/listview.filter.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ define( [ "jquery", "./listview", "./forms/textinput" ], function( $ ) {
1111
$.mobile.listview.prototype.options.filter = false;
1212
$.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
1313
$.mobile.listview.prototype.options.filterTheme = "c";
14+
$.mobile.listview.prototype.options.filterReveal = false;
1415
// TODO rename callback/deprecate and default to the item itself as the first argument
1516
var defaultFilterCallback = function( text, searchValue, item ) {
1617
return text.toString().toLowerCase().indexOf( searchValue ) === -1;
@@ -27,6 +28,10 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
2728
return;
2829
}
2930

31+
if ( listview.options.filterReveal ) {
32+
list.children().addClass( "ui-screen-hidden" );
33+
}
34+
3035
var wrapper = $( "<form>", {
3136
"class": "ui-listview-filter ui-bar-" + listview.options.filterTheme,
3237
"role": "search"
@@ -60,6 +65,10 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
6065

6166
// Only chars added, not removed, only use visible subset
6267
listItems = list.children( ":not(.ui-screen-hidden)" );
68+
69+
if ( !listItems.length && listview.options.filterReveal ) {
70+
listItems = list.children( ".ui-screen-hidden" );
71+
}
6372
}
6473

6574
if ( val ) {
@@ -103,7 +112,7 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
103112
} else {
104113

105114
//filtervalue is empty => show all
106-
listItems.toggleClass( "ui-screen-hidden", false );
115+
listItems.toggleClass( "ui-screen-hidden", !!listview.options.filterReveal );
107116
}
108117
listview._refreshCorners();
109118
})

0 commit comments

Comments
 (0)