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

Commit

Permalink
Browse files Browse the repository at this point in the history
Listview: New option to start with all items hidden when search input…
… in blank

Please meet: data-filter-reveal
Fixes #5090
  • Loading branch information
gseguin committed Oct 11, 2012
1 parent 68d8cb5 commit a9c80c5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion js/widgets/listview.filter.js
Expand Up @@ -11,6 +11,7 @@ define( [ "jquery", "./listview", "./forms/textinput" ], function( $ ) {
$.mobile.listview.prototype.options.filter = false;
$.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
$.mobile.listview.prototype.options.filterTheme = "c";
$.mobile.listview.prototype.options.filterReveal = false;
// TODO rename callback/deprecate and default to the item itself as the first argument
var defaultFilterCallback = function( text, searchValue, item ) {
return text.toString().toLowerCase().indexOf( searchValue ) === -1;
Expand All @@ -27,6 +28,10 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(
return;
}

if ( listview.options.filterReveal ) {
list.children().addClass( "ui-screen-hidden" );
}

var wrapper = $( "<form>", {
"class": "ui-listview-filter ui-bar-" + listview.options.filterTheme,
"role": "search"
Expand Down Expand Up @@ -60,6 +65,10 @@ $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function(

// Only chars added, not removed, only use visible subset
listItems = list.children( ":not(.ui-screen-hidden)" );

if ( !listItems.length && listview.options.filterReveal ) {
listItems = list.children( ".ui-screen-hidden" );
}
}

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

//filtervalue is empty => show all
listItems.toggleClass( "ui-screen-hidden", false );
listItems.toggleClass( "ui-screen-hidden", !!listview.options.filterReveal );
}
listview._refreshCorners();
})
Expand Down

0 comments on commit a9c80c5

Please sign in to comment.