Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.mobile.listview.prototype.options.xFilter = false;
- $.mobile.listview.prototype.options.xFilterId = false;
- $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function() {
- var listview = $(this).data( "listview" );
- if ( !listview.options.xFilter || !$(this).attr('id') ) {
- return;
- }
- var list = $(this).add('ul:jqmData(x-filter-id='+$(this).attr('id')+')');
- if ( listview.options.filterReveal ) {
- list.children().addClass( "ui-screen-hidden" );
- }
- var wrapper = $( "<form>", {
- "class": "ui-listview-filter ui-bar-" + listview.options.filterTheme,
- "role": "search"
- }),
- search = $( "<input>", {
- 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" ) + "",
- childItems = false,
- itemtext = "",
- item,
- // Check if a custom filter callback applies
- isCustomFilterCallback = listview.options.filterCallback !== $.mobile.listview.prototype.options.filterCallback;
- listview._trigger( "beforefilter", "beforefilter", { input: this } );
- // Change val as lastval for next execution
- $this.jqmData( "lastval" , val );
- if ( isCustomFilterCallback || val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
- // Custom filter callback applies or removed chars or pasted something totally 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 ( !listItems.length && listview.options.filterReveal ) {
- listItems = list.children( ".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
- for ( var i = listItems.length - 1; 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 );
- // New bucket!
- childItems = false;
- } else if ( listview.options.filterCallback( itemtext, val, item ) ) {
- //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", !!listview.options.filterReveal );
- }
- listview._refreshCorners();
- })
- .appendTo( wrapper )
- .textinput();
- if ( listview.options.inset ) {
- wrapper.addClass( "ui-listview-filter-inset" );
- }
- wrapper.bind( "submit", function() {
- return false;
- })
- .insertBefore( $(this) );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement