Permalink
Browse files

Nested Listviews: Remove nested listviews depreceated in 1.3.0

  • Loading branch information...
arschmitz committed May 9, 2013
1 parent 8d61fb2 commit 923a83efe2d6abf62852936cf0255d413cb4c104
View
@@ -12,8 +12,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.buttonMarkup",
//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 = {},
- getAttr = $.mobile.getAttribute;
+var getAttr = $.mobile.getAttribute;
$.widget( "mobile.listview", $.mobile.widget, $.extend( {
@@ -98,7 +97,6 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
refresh: function( create ) {
this.parentPage = this.element.closest( ".ui-page" );
- this._createSubPages();
var o = this.options,
$list = this.element,
@@ -287,95 +285,6 @@ $.widget( "mobile.listview", $.mobile.widget, $.extend( {
//create a string for ID/subpage url creation
_idStringEscape: function( str ) {
return str.replace(/[^a-zA-Z0-9]/g, "-");
- },
-
- _createSubPages: function() {
- var parentList = this.element,
- parentPage = parentList.closest( ".ui-page" ),
- parentUrl = getAttr( parentPage[ 0 ], "url", true ),
- parentId = parentUrl || parentPage[ 0 ][ $.expando ],
- parentListId = parentList.attr( "id" ),
- o = this.options,
- dns = "data-" + $.mobile.ns,
- self = this,
- persistentFooter = parentPage.find( ":jqmData(role='footer')" ),
- persistentFooterID = ( persistentFooter.length > 0 ? getAttr( persistentFooter[ 0 ], "id", true ) : undefined ),
- hasSubPages,
- newRemove = function( e, ui ) {
- var nextPage = ui.nextPage, npURL,
- prEvent = new $.Event( "pageremove" );
-
- if ( ui.nextPage ) {
- npURL = getAttr( nextPage[ 0 ], "url", true );
- if ( npURL.indexOf( parentUrl + "&" + $.mobile.subPageUrlKey ) !== 0 ) {
- self.childPages().remove();
- parentPage.trigger( prEvent );
- if ( !prEvent.isDefaultPrevented() ) {
- parentPage.removeWithDependents();
- }
- }
- }
- };
-
- 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(),
- nodeElsFull = $( list.prevAll().toArray().reverse() ),
- nodeEls = nodeElsFull.length ? nodeElsFull : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
- title = nodeEls.first().getEncodedText(),//url limits to first 30 chars of text
- id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId,
- theme = getAttr( list[ 0 ], "theme", true ) || o.theme,
- countTheme = getAttr( list[ 0 ], "counttheme", true ) || getAttr( parentList[ 0 ], "counttheme", true ) || o.countTheme,
- newPage, anchor;
-
- //define hasSubPages for use in later removal
- hasSubPages = true;
-
- newPage = list.detach()
- .wrap( "<div " + dns + "role='page' " + dns + "url='" + id + "' " + dns + "theme='" + theme + "' " + dns + "count-theme='" + countTheme + "'><div " + dns + "role='content'></div></div>" )
- .parent()
- .before( "<div " + dns + "role='header' " + dns + "theme='" + o.headerTheme + "'><div class='ui-title'>" + title + "</div></div>" )
- .after( persistentFooterID ? $( "<div " + dns + "role='footer' " + dns + "id='"+ persistentFooterID +"'>" ) : "" )
- .parent()
- .appendTo( $.mobile.pageContainer );
-
- newPage.page();
-
- anchor = parent.find( "a:first" );
-
- if ( !anchor.length ) {
- anchor = $( "<a/>" ).html( nodeEls || title ).prependTo( parent.empty() );
- }
-
- anchor.attr( "href", "#" + id );
-
- }).listview();
-
- // on pagehide, remove any nested pages along with the parent page, as long as they aren't active
- // and aren't embedded
- if ( hasSubPages &&
- parentPage.is( ":jqmData(external-page='true')" ) &&
- parentPage.data( "mobile-page" ).options.domCache === false ) {
-
- // unbind the original page remove and replace with our specialized version
- parentPage
- .unbind( "pagehide.remove" )
- .bind( "pagehide.remove", newRemove);
- }
- },
-
- // TODO sort out a better way to track sub pages of the listview this is brittle
- childPages: function() {
- var parentUrl = this.parentPage.jqmData( "url" );
-
- return $( ":jqmData(url^='"+ parentUrl + "&" + $.mobile.subPageUrlKey + "')" );
}
}, $.mobile.behaviors.addFirstLastClasses ) );
@@ -855,137 +855,6 @@
module( "Cached Linked List" );
- var findNestedPages = function(selector){
- return $( selector + " #topmost" ).listview( 'childPages' );
- };
-
- asyncTest( "nested pages are removed from the dom by default", function(){
- $.testHelper.pageSequence([
- function(){
- //reset for relative url refs
- $.mobile.changePage( home );
- },
-
- function(){
- $.mobile.changePage( "cache-tests/uncached-nested.html" );
- },
-
- function(){
- ok( findNestedPages( "#uncached-nested-list" ).length > 0, "verify that there are nested pages" );
- $.mobile.changePage( home );
- },
-
- function() {
- $.mobile.changePage( "cache-tests/clear.html" );
- },
-
- function(){
- deepEqual( findNestedPages( "#uncached-nested-list" ).length, 0 );
- start();
- }
- ]);
- });
-
- asyncTest( "nested pages preserved when parent page is cached", function(){
-
- $.testHelper.pageSequence([
- function(){
- //reset for relative url refs
- $.mobile.changePage( home );
- },
-
- function(){
- $.mobile.changePage( "cache-tests/cached-nested.html" );
- },
-
- function(){
- ok( findNestedPages( "#cached-nested-list" ).length > 0, "verify that there are nested pages" );
- $.mobile.changePage( home );
- },
-
- function() {
- $.mobile.changePage( "cache-tests/clear.html" );
- },
-
- function(){
- ok( findNestedPages( "#cached-nested-list" ).length > 0, "nested pages remain" );
- start();
- }
- ]);
- });
-
- asyncTest( "parent page is not removed when visiting a sub page", function(){
- $.testHelper.pageSequence([
- function(){
- //reset for relative url refs
- $.mobile.changePage( home );
- },
-
- function(){
- $.mobile.changePage( "cache-tests/cached-nested.html" );
- },
-
- function(){
- deepEqual( $("#cached-nested-list").length, 1 );
- $.mobile.changePage( home );
- },
-
- function() {
- $.mobile.changePage( "cache-tests/clear.html" );
- },
-
- function(){
- deepEqual( $("#cached-nested-list").length, 1 );
- start();
- }
- ]);
- });
-
- asyncTest( "nested pages hash key is always in the hash (replaceState)", function(){
- $.testHelper.pageSequence([
- function(){
- //reset for relative url refs
- $.mobile.changePage( home );
- },
-
- function(){
- // https://github.com/jquery/jquery-mobile/issues/1617
- $.mobile.changePage("#nested-lists-test");
- },
-
- function(){
- // Click on the link of the third li element
- $('.ui-page-active li:eq(2) a:eq(0)').click();
- },
-
- function(){
- ok( location.hash.search($.mobile.subPageUrlKey) >= 0 );
- start();
- }
- ]);
- });
-
- asyncTest( "embedded listview page with nested pages is not removed from the dom", function() {
- $.testHelper.pageSequence([
- function() {
- // open the nested list page
- deepEqual( $("div#nested-list-test").length, 1 );
- $( "a#nested-list-test-anchor" ).click();
- },
-
- function() {
- // go back to the origin page
- window.history.back();
- },
-
- function() {
- // make sure the page is still in place
- deepEqual( $("div#nested-list-test").length, 1 );
- start();
- }
- ]);
- });
-
asyncTest( "list inherits theme from parent", function() {
$.testHelper.pageSequence([
@@ -1,103 +0,0 @@
-/*
- * mobile listview unit tests
- */
-(function($) {
- module('Nested List Test', {
- setup: function() {
- // ensure that the nested pages are generated
- stop();
- $.testHelper.pageSequence([
- function(){
- $.mobile.changePage("#nested-list-test");
- },
-
- function() {
- window.history.back();
- },
-
- start
- ]);
- }
- });
-
- asyncTest( "Changes page to nested list test and enhances", function() {
- $.testHelper.pageSequence([
- function(){
- $.mobile.changePage("#nested-list-test");
- },
-
- function(){
- ok($('#nested-list-test').hasClass('ui-page-active'), "makes nested list test page active");
- ok($(':jqmData(url="nested-list-test&ui-page=0-0")').length == 1, "Adds first UL to the page");
- ok($(':jqmData(url="nested-list-test&ui-page=0-1")').length == 1, "Adds second nested UL to the page");
- start();
- }
- ]);
- });
-
- asyncTest( "change to nested page when the li a is clicked", function() {
-
- $.testHelper.pageSequence([
- function(){
- $.mobile.changePage("#nested-list-test");
- },
-
- function(){
- $('.ui-page-active li:eq(1) a:eq(0)').click();
- },
-
- function(){
- var $new_page = $(':jqmData(url*="ui-page=0-0")');
-
- ok($new_page.hasClass('ui-page-active'), 'Makes the nested page the active page.');
- ok($('.ui-listview', $new_page).find(":contains('Rhumba of rattlesnakes')").length == 1, "The current page should have the proper text in the list.");
- ok($('.ui-listview', $new_page).find(":contains('Shoal of Bass')").length == 1, "The current page should have the proper text in the list.");
- start();
- }
- ]);
- });
-
- asyncTest( "should go back to top level when the back button is clicked", function() {
- $.testHelper.pageSequence([
- function(){
- $.mobile.changePage("#nested-list-test");
- },
-
- function(){
- $.mobile.changePage("#nested-list-test&ui-page=0-0");
- },
-
- function(){
- window.history.back();
- },
-
- function( timeout ){
- ok($.mobile.activePage.is('#nested-list-test'), 'Transitions back to the parent nested page');
- start();
- }
- ]);
- });
-
- test( "nested list title should use first text node, regardless of line breaks", function(){
- deepEqual($(":jqmData(url='nested-list-test&ui-page=0-0') .ui-title").text(), "More animals", 'Text should be "More animals"');
- });
-
- asyncTest( "Multiple nested lists on a page with same labels", function() {
- $.testHelper.pageSequence([
- function(){
- // https://github.com/jquery/jquery-mobile/issues/1617
- $.mobile.changePage("#nested-lists-test");
- },
-
- function(){
- // Click on the link of the third li element
- $('.ui-page-active li:eq(2) a:eq(0)').click();
- },
-
- function(){
- equal($('.ui-page-active .ui-content .ui-listview li').text(), "Item A-3-0Item A-3-1Item A-3-2", 'Text should be "Item A-3-0Item A-3-1Item A-3-2"');
- start();
- }
- ]);
- });
-})( jQuery );
Oops, something went wrong.

0 comments on commit 923a83e

Please sign in to comment.