From 6434227dbe7d36e1d15ad01f149422a0f301e90b Mon Sep 17 00:00:00 2001 From: Richard Stutfield Date: Thu, 18 Nov 2010 21:19:02 +0000 Subject: [PATCH] Listview: Extended nested list implementation to support nested content of any type using data-role="subpage" attribute Also includes data-role="subpagetitle" that can specify the title content and caters for more complex parent list layouts --- js/jquery.mobile.listview.js | 46 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/js/jquery.mobile.listview.js b/js/jquery.mobile.listview.js index 3e5200b0368..de221c4e651 100644 --- a/js/jquery.mobile.listview.js +++ b/js/jquery.mobile.listview.js @@ -277,31 +277,35 @@ $.widget( "mobile.listview", $.mobile.widget, { o = this.options, persistentFooterID = parentPage.find( "[data-role='footer']" ).data( "id" ); - $( parentList.find( "ul, ol" ).toArray().reverse() ).each(function( i ) { - var list = $( this ), - parent = list.parent(), - title = parent.contents()[ 0 ].nodeValue.split("\n")[0], + $( parentList.find( "ul, ol,[data-role='subpage']" ).not("[data-role='subpage'] *").toArray().reverse() ).each(function( i ) { + var content = $( this ), + parent = content.parent(), + titleElement = parent.children("[data-role='subpagetitle']").eq(0).wrapInner(""), + title = titleElement.length ? titleElement.text() : parent.contents()[ 0 ].nodeValue.split("\n")[0], id = parentId + "&" + $.mobile.subPageUrlKey + "=" + $.mobile.idStringEscape(title + " " + i), - theme = list.data( "theme" ) || o.theme, - countTheme = list.data( "counttheme" ) || parentList.data( "counttheme" ) || o.countTheme, - newPage = list.wrap( "
" ) + theme = content.data( "theme" ) || o.theme, + countTheme = content.data( "counttheme" ) || parentList.data( "counttheme" ) || o.countTheme, + newPage = (content.is("[data-role='subpage']") ? content.attr('data-role','content') : $("
").append(content)) + .wrap( "
" ) + .before( "
" + title + "
" ) + .after( persistentFooterID ? $( "
", { "data-role": "footer", "data-id": persistentFooterID, "class": "ui-footer-duplicate" } ) : "" ) .parent() - .before( "
" + title + "
" ) - .after( persistentFooterID ? $( "
", { "data-role": "footer", "data-id": persistentFooterID, "class": "ui-footer-duplicate" } ) : "" ) - .parent() - .attr({ - id: id, - "data-theme": theme, - "data-count-theme": countTheme - }) - .appendTo( $.pageContainer ); + .attr({ + id: id, + "data-theme": theme, + "data-count-theme": countTheme + }) + .appendTo( $.pageContainer ); - - - newPage.page(); + newPage.page(); + + if(titleElement.length==0) { + parent.html("" + title + ""); + } + + parent.find("a:eq(0)").attr("href","#" + id); - parent.html( "" + title + "" ); - }).listview(); + }).filter("ul,ol").listview(); } });