Skip to content

Commit

Permalink
Fix for issue jquery-archive#1617: Nested lists with same parent text…
Browse files Browse the repository at this point in the history
… resolve to the same sub-page.
  • Loading branch information
Ghislain Seguin committed Jun 3, 2011
1 parent f3b46da commit 8373105
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions js/jquery.mobile.listview.js
Expand Up @@ -5,6 +5,10 @@
* http://jquery.org/license
*/
(function($, undefined ) {
//Keeps track of the number of lists per page UID
//This allows support for multiple nested list in the same page
//https://github.com/jquery/jquery-mobile/issues/1617
var listCountPerPage = {};

$.widget( "mobile.listview", $.mobile.widget, {
options: {
Expand Down Expand Up @@ -189,23 +193,31 @@ $.widget( "mobile.listview", $.mobile.widget, {
_idStringEscape: function( str ){
return str.replace(/[^a-zA-Z0-9]/g, '-');
},

_createSubPages: function() {
var parentList = this.element,
parentPage = parentList.closest( ".ui-page" ),
parentId = parentPage.jqmData( "url" ),
parentUrl = parentPage.jqmData( "url" ),
parentId = parentUrl || parentPage[ 0 ][ $.expando ],
parentListId = parentList.attr( "id" ),
o = this.options,
dns = "data-" + $.mobile.ns,
self = this,
persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" );

if ( typeof( listCountPerPage[ parentId ] ) === 'undefined' ) {
listCountPerPage[ parentId ] = -1;
}
parentListId = parentListId || ++listCountPerPage[ parentId ];

$( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) {
var list = $( this ),
listId = list.attr( "id" ) || parentListId + "-" + i,
parent = list.parent(),
nodeEls = $( list.prevAll().toArray().reverse() ),
nodeEls = nodeEls.length ? nodeEls : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
title = nodeEls.first().text(),//url limits to first 30 chars of text
id = parentId + "&" + $.mobile.subPageUrlKey + "=" + self._idStringEscape(title + " " + i),
id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId;
theme = list.jqmData( "theme" ) || o.theme,
countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme,
newPage = list.detach()
Expand Down

0 comments on commit 8373105

Please sign in to comment.