|
5 | 5 | * http://jquery.org/license |
6 | 6 | */ |
7 | 7 | (function($, undefined ) { |
| 8 | +//Keeps track of the number of lists per page UID |
| 9 | +//This allows support for multiple nested list in the same page |
| 10 | +//https://github.com/jquery/jquery-mobile/issues/1617 |
| 11 | +var listCountPerPage = {}; |
8 | 12 |
|
9 | 13 | $.widget( "mobile.listview", $.mobile.widget, { |
10 | 14 | options: { |
@@ -189,23 +193,31 @@ $.widget( "mobile.listview", $.mobile.widget, { |
189 | 193 | _idStringEscape: function( str ){ |
190 | 194 | return str.replace(/[^a-zA-Z0-9]/g, '-'); |
191 | 195 | }, |
192 | | - |
| 196 | + |
193 | 197 | _createSubPages: function() { |
194 | 198 | var parentList = this.element, |
195 | 199 | parentPage = parentList.closest( ".ui-page" ), |
196 | | - parentId = parentPage.jqmData( "url" ), |
| 200 | + parentUrl = parentPage.jqmData( "url" ), |
| 201 | + parentId = parentUrl || parentPage[ 0 ][ $.expando ], |
| 202 | + parentListId = parentList.attr( "id" ), |
197 | 203 | o = this.options, |
198 | 204 | dns = "data-" + $.mobile.ns, |
199 | 205 | self = this, |
200 | 206 | persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" ); |
201 | 207 |
|
| 208 | + if ( typeof( listCountPerPage[ parentId ] ) === 'undefined' ) { |
| 209 | + listCountPerPage[ parentId ] = -1; |
| 210 | + } |
| 211 | + parentListId = parentListId || ++listCountPerPage[ parentId ]; |
| 212 | + |
202 | 213 | $( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) { |
203 | 214 | var list = $( this ), |
| 215 | + listId = list.attr( "id" ) || parentListId + "-" + i, |
204 | 216 | parent = list.parent(), |
205 | 217 | nodeEls = $( list.prevAll().toArray().reverse() ), |
206 | 218 | nodeEls = nodeEls.length ? nodeEls : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ), |
207 | 219 | title = nodeEls.first().text(),//url limits to first 30 chars of text |
208 | | - id = parentId + "&" + $.mobile.subPageUrlKey + "=" + self._idStringEscape(title + " " + i), |
| 220 | + id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId; |
209 | 221 | theme = list.jqmData( "theme" ) || o.theme, |
210 | 222 | countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme, |
211 | 223 | newPage = list.detach() |
|
0 commit comments