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

issue 2092; created optional method for terms based listview filtering #2093

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions js/jquery.mobile.listview.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$.mobile.listview.prototype.options.filter = false;
$.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
$.mobile.listview.prototype.options.filterTheme = "c";
$.mobile.listview.prototype.options.filterTerms = false;

$( ":jqmData(role='listview')" ).live( "listviewcreate", function() {

Expand Down Expand Up @@ -63,22 +64,45 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
item = $( listItems[ i ] );
itemtext = item.jqmData( "filtertext" ) || item.text();

if ( item.is( "li:jqmData(role=list-divider)" ) ) {
// array of the val text terms to match on.
//Only create arrays and continue loop if data-filter-terms="true"
if ( listview.options.filterTerms == true ){

var subVals = val.toLowerCase().split(' ');
var j = subVals.length - 1;

//switch val over to the individual terms if this filter should run
val = subVals[j];

}else{

//loop should only run once
var j = 0;
}


do {

if ( item.is( "li:jqmData(role=list-divider)" ) ) {

item.toggleClass( "ui-filter-hidequeue" , !childItems );
item.toggleClass( 'ui-filter-hidequeue' , !childItems );

// New bucket!
childItems = false;
// New bucket!
childItems = false;

} else if ( itemtext.toLowerCase().indexOf( val ) === -1 ) {
} else if ( itemtext.toLowerCase().indexOf( val ) === -1 ) {

//mark to be hidden
item.toggleClass( "ui-filter-hidequeue" , true );
} else {
//mark to be hidden
item.toggleClass( 'ui-filter-hidequeue' , true );
} else {

// There"s a shown item in the bucket
childItems = true;
}
// There's a shown item in the bucket
childItems = true;
}

j--;

} while ( j >= 0 )
}

// Show items, not marked to be hidden
Expand Down