mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-17 06:20:26 +00:00
code cleanup
This commit is contained in:
parent
b10c71814c
commit
ca767ff3aa
1 changed files with 40 additions and 16 deletions
|
|
@ -24,43 +24,67 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
|
|||
})
|
||||
.attr( "data-" + $.mobile.ns + "type", "search" )
|
||||
.bind( "keyup change", function() {
|
||||
lastval=$(this).jqmData('lastval')+"";
|
||||
var val = this.value.toLowerCase(),listItems=null;
|
||||
lastval = $( this ).jqmData('lastval')+"";
|
||||
var val = this.value.toLowerCase(),
|
||||
listItems=null;
|
||||
|
||||
//change val as lastval for next execution
|
||||
$(this).jqmData('lastval',val);
|
||||
$(this).jqmData( 'lastval' , val );
|
||||
|
||||
change=val.replace(new RegExp("^"+lastval),"");
|
||||
change = val.replace( new RegExp( "^" + lastval ) , "" );
|
||||
|
||||
if(val.length<lastval.length || change.length!=(val.length-lastval.length)){
|
||||
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{
|
||||
} else {
|
||||
|
||||
//only chars added, not removed, only use visible subset
|
||||
listItems = list.children(':visible');
|
||||
listItems = list.children( ':visible' );
|
||||
}
|
||||
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,itemtext="";
|
||||
item,
|
||||
itemtext="";
|
||||
|
||||
for (var i = listItems.length; i >= 0; i--) {
|
||||
item = $(listItems[i]);
|
||||
itemtext=item.jqmData('filtertext') || item.text();
|
||||
if (item.is("li:jqmData(role=list-divider)")) {
|
||||
item.toggleClass('ui-filter-hidequeue',!childItems);
|
||||
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 (itemtext.toLowerCase().indexOf( val ) === -1) {
|
||||
item.toggleClass('ui-filter-hidequeue',true);
|
||||
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
listItems.filter(':not(.ui-filter-hidequeue)').show();
|
||||
listItems.filter('.ui-filter-hidequeue').hide().toggleClass('ui-filter-hidequeue',false);
|
||||
|
||||
// show items, not marked to be hidden
|
||||
listItems
|
||||
.filter( ':not(.ui-filter-hidequeue)' )
|
||||
.show();
|
||||
|
||||
// hide items, marked to be hidden
|
||||
listItems
|
||||
.filter( '.ui-filter-hidequeue' )
|
||||
.hide()
|
||||
.toggleClass( 'ui-filter-hidequeue' , false );
|
||||
}else{
|
||||
|
||||
//filtervalue is empty => show all
|
||||
listItems.show();
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue