diff --git a/js/jQuery.mobile.listview.js b/js/jQuery.mobile.listview.js index b8bfa16d..de2ea38c 100644 --- a/js/jQuery.mobile.listview.js +++ b/js/jQuery.mobile.listview.js @@ -17,39 +17,9 @@ $.widget( "mobile.listview", $.mobile.widget, { }, _create: function() { - var parentID = this.element.closest( ".ui-page" ).attr( "id" ), - o = this.options; + var o = this.options; - //if it's a nested list, chunk it into ui-page items, recurse through them and call listview on each individual ul - $( this.element.find( "ul,ol" ).get().reverse() ).each(function( i ) { - var list = $( this ), - id = parentID + "&" + jQuery.mobile.subPageUrlKey + "=listview-" + i, - parent = list.parent(), - title = parent.contents()[ 0 ].nodeValue, - theme = list.data( "theme" ) || o.theme, - countTheme = list.data( "count-theme" ) || o.countTheme; - - list.wrap( "
" ) - .parent() - .before( "

" + - title + "

Back
" ) - .parent() - .attr({ - id: id, - "data-theme": theme, - "data-count-theme": countTheme - }) - .appendTo( "body" ) - .fixHeaderFooter() - .find( ".ui-header a.ui-back" ) - .buttonMarkup() - .click(function() { - history.go(-1); - return false; - }); - - parent.html( "" + title + "" ); - }).listview(); + this._createSubPages(); //create listview markup this.element @@ -146,23 +116,8 @@ $.widget( "mobile.listview", $.mobile.widget, { .end() .find( "p,ul,dl" ) .addClass( "ui-li-desc" ); - - // JS fallback for auto-numbering for OL elements - if( !$.support.cssPseudoElement && this.element.is('ol') ){ - var counter = 1; - this.element.find('li').each(function(){ - if( $(this).is('.ui-li-grouping') ){ - //reset counter when a grouping heading is encountered - counter = 1; - } - else { - $(this) - .find('.ui-link-inherit:first') - .addClass('ui-li-jsnumbering') - .prepend('' + counter++ + '. '); - } - }); - } + + this._numberItems(); //tapping the whole LI triggers ajaxClick on the first link this.element.find( "li:has(a)" ).live( "tap", function(event) { @@ -171,6 +126,60 @@ $.widget( "mobile.listview", $.mobile.widget, { return false; } }); + }, + + _createSubPages: function() { + var parentId = this.element.closest( ".ui-page" ).attr( "id" ), + o = this.options; + $( this.element.find( "ul,ol" ).get().reverse() ).each(function( i ) { + var list = $( this ), + id = parentId + "&" + $.mobile.subPageUrlKey + "=listview-" + i, + parent = list.parent(), + title = parent.contents()[ 0 ].nodeValue, + theme = list.data( "theme" ) || o.theme, + countTheme = list.data( "count-theme" ) || o.countTheme; + + list.wrap( "
" ) + .parent() + .before( "

" + + title + "

Back
" ) + .parent() + .attr({ + id: id, + "data-theme": theme, + "data-count-theme": countTheme + }) + .appendTo( "body" ) + .fixHeaderFooter() + .find( ".ui-header a.ui-back" ) + .buttonMarkup() + .click(function() { + history.go(-1); + return false; + }); + + parent.html( "" + title + "" ); + }).listview(); + }, + + // JS fallback for auto-numbering for OL elements + _numberItems: function() { + if ( $.support.cssPseudoElement || !this.element.is( "ol" ) ) { + return; + } + var counter = 1; + this.element.find( ".ui-li-dec" ).remove(); + this.element.find( "li:visible" ).each(function() { + if( $( this ).is( ".ui-li-grouping" ) ) { + //reset counter when a grouping heading is encountered + counter = 1; + } else { + $( this ) + .find( ".ui-link-inherit:first" ) + .addClass( "ui-li-jsnumbering" ) + .prepend( "" + (counter++) + ". " ); + } + }); } }); diff --git a/js/jquery.mobile.listview.filter.js b/js/jquery.mobile.listview.filter.js index 028fcf3f..bb49660e 100644 --- a/js/jquery.mobile.listview.filter.js +++ b/js/jquery.mobile.listview.filter.js @@ -3,26 +3,31 @@ $.mobile.listview.prototype.options.filter = false; $( ":mobile-listview" ).live( "listviewcreate", function() { - var list = $( this ); - if ( !list.data( "listview" ).options.filter ) { + var list = $( this ), + listview = list.data( "listview" ); + if ( !listview.options.filter ) { return; } - var wrapper = $( "
", { 'class': "ui-listview-filter ui-bar-c"} ), + var wrapper = $( "", { "class": "ui-listview-filter ui-bar-c" } ), - search = $( "", { placeholder: "Filter results...", "data-type": "search" }) - .bind('keyup change', function() { - var val = this.value; + search = $( "", { + placeholder: "Filter results...", + "data-type": "search" + }) + .bind( "keyup change", function() { + var val = this.value.toLowerCase();; list.children().show(); if ( val ) { list.children().filter(function() { - return $( this ).text().indexOf( val ) === -1; + return $( this ).text().toLowerCase().indexOf( val ) === -1; }).hide(); } + + listview._numberItems(); }) .appendTo( wrapper ) .customTextInput(); - wrapper.insertBefore( list ); });