diff --git a/js/jquery.mobile.listview.filter.js b/js/jquery.mobile.listview.filter.js index d6be0f45..0e79bde6 100644 --- a/js/jquery.mobile.listview.filter.js +++ b/js/jquery.mobile.listview.filter.js @@ -23,83 +23,83 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() { var wrapper = $( "
", { "class": "ui-listview-filter ui-bar-" + listview.options.filterTheme, "role": "search" - }), - search = $( "", { - placeholder: listview.options.filterPlaceholder - }) - .attr( "data-" + $.mobile.ns + "type", "search" ) - .jqmData( "lastval", "" ) - .bind( "keyup change", function() { + }), + search = $( "", { + placeholder: listview.options.filterPlaceholder + }) + .attr( "data-" + $.mobile.ns + "type", "search" ) + .jqmData( "lastval", "" ) + .bind( "keyup change", function() { - var $this = $(this), - val = this.value.toLowerCase(), - 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 item, + var $this = $(this), + val = this.value.toLowerCase(), + listItems = null, + lastval = $this.jqmData( "lastval" ) + "", childItems = false, - itemtext=""; + itemtext = "", + item; - for ( var i = listItems.length - 1; i >= 0; i-- ) { - item = $( listItems[i] ); - itemtext = item.jqmData( "filtertext" ) || item.text(); + // Change val as lastval for next execution + $this.jqmData( "lastval" , val ); - if ( item.is( "li:jqmData(role=list-divider)" ) ) { + change = val.replace( new RegExp( "^" + lastval ) , "" ); - item.toggleClass( "ui-filter-hidequeue" , !childItems ); + if ( val.length < lastval.length || change.length != ( val.length - lastval.length ) ) { - // New bucket! - childItems = false; + // Removed chars or pasted something totaly different, check all items + listItems = list.children(); + } else { - } 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; - } + // Only chars added, not removed, only use visible subset + listItems = list.children( ":not(.ui-screen-hidden)" ); } - // show items, not marked to be hidden - listItems - .filter( ":not(.ui-filter-hidequeue)" ) - .toggleClass("ui-screen-hidden",false); + if ( val ) { - // hide items, marked to be hidden - listItems - .filter( ".ui-filter-hidequeue" ) - .toggleClass("ui-screen-hidden",true) - .toggleClass( "ui-filter-hidequeue" , false ); + // This handles hiding regular rows without the text we search for + // and any list dividers without regular rows shown under it - } else { + for ( var i = listItems.length - 1; i >= 0; i-- ) { + item = $( listItems[ i ] ); + itemtext = item.jqmData( "filtertext" ) || item.text(); - //filtervalue is empty => show all - listItems.toggleClass("ui-screen-hidden",false); - } - }) - .appendTo( wrapper ) - .textinput(); + if ( item.is( "li:jqmData(role=list-divider)" ) ) { + + item.toggleClass( "ui-filter-hidequeue" , !childItems ); + + // New bucket! + childItems = false; + + } 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 ) + .textinput(); if ( $( this ).jqmData( "inset" ) ) { wrapper.addClass( "ui-listview-filter-inset" );