Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'filterspeed' of https://github.com/nsaleh/jquery-mobile

…into pull-1475

Resolved Conflicts:
	js/jquery.mobile.navigation.js
		- Removed these changes as they are not related.
  • Loading branch information...
commit 1387fd457fb4cbcc88219c1598e26c3ac0dfe2f4 2 parents e597ccb + 4ffb0a5
@jblas jblas authored
View
65 js/jquery.mobile.listview.filter.js
@@ -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 )
@@ -60,4 +101,4 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
wrapper.insertBefore( list );
});
-})( jQuery );
+})( jQuery );
View
2  themes/default/jquery.mobile.listview.css
@@ -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; }
Please sign in to comment.
Something went wrong with that request. Please try again.