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

Commit

Permalink
Merge branch 'filterspeed' of https://github.com/nsaleh/jquery-mobile
Browse files Browse the repository at this point in the history
…into pull-1475

Resolved Conflicts:
	js/jquery.mobile.navigation.js
		- Removed these changes as they are not related.
  • Loading branch information
jblas committed May 9, 2011
2 parents e597ccb + 4ffb0a5 commit 1387fd4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
65 changes: 53 additions & 12 deletions js/jquery.mobile.listview.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,71 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
})
.attr( "data-" + $.mobile.ns + "type", "search" )
.bind( "keyup change", function() {

var val = this.value.toLowerCase(),
listItems = list.children();
listItems.show();
listItems=null,
lastval = $( this ).jqmData('lastval')+"";

//change val as lastval for next execution
$(this).jqmData( 'lastval' , val );

change = val.replace( new RegExp( "^" + lastval ) , "" );

if( val.length < lastval.length || change.length != ( val.length - lastval.length ) ){

//removed chars or pasted something totaly different, check all items
listItems = list.children();
} else {

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

if ( val ) {

// This handles hiding regular rows without the text we search for
// and any list dividers without regular rows shown under it
var childItems = false,
item;
var item,
childItems = false,
itemtext="";

for (var i = listItems.length; i >= 0; i--) {
item = $(listItems[i]);
if (item.is("li:jqmData(role=list-divider)")) {
if (!childItems) {
item.hide();
}
item = $( listItems[i] );
itemtext = item.jqmData( 'filtertext' ) || item.text();

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

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

// New bucket!
childItems = false;
} else if (item.text().toLowerCase().indexOf( val ) === -1) {
item.hide();

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

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

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

// show items, not marked to be hidden
listItems
.filter( ':not(.ui-filter-hidequeue)' )
.toggleClass('ui-screen-hidden',false);

// hide items, marked to be hidden
listItems
.filter( '.ui-filter-hidequeue' )
.toggleClass('ui-screen-hidden',true)
.toggleClass( 'ui-filter-hidequeue' , false );

}else{

//filtervalue is empty => show all
listItems.toggleClass('ui-screen-hidden',false);
}
})
.appendTo( wrapper )
Expand All @@ -60,4 +101,4 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
wrapper.insertBefore( list );
});

})( jQuery );
})( jQuery );
2 changes: 1 addition & 1 deletion themes/default/jquery.mobile.listview.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ol.ui-listview .ui-li-jsnumbering:before { content: "" !important; } /* to avoid
.ui-listview-filter .ui-input-search { margin: 5px; width: auto; display: block; }

.ui-listview-filter-inset { margin: -15px -5px -15px -5px; background: transparent; }

.ui-li.ui-screen-hidden{display:none;}
/* Odd iPad positioning issue. */
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
.ui-li .ui-btn-text { overflow: visible; }
Expand Down

0 comments on commit 1387fd4

Please sign in to comment.