Skip to content
This repository
Browse code

use the first dialog in a document as a page when no pages exist Fixes

  • Loading branch information...
commit 26c1d8e56e4cc692533ba55da9c89548504a8309 1 parent 0f62e96
John Bender authored January 13, 2012

Showing 1 changed file with 17 additions and 3 deletions. Show diff stats Hide diff stats

  1. 20  js/jquery.mobile.init.js
20  js/jquery.mobile.init.js
@@ -58,13 +58,27 @@
58 58
 		// find and enhance the pages in the dom and transition to the first page.
59 59
 		initializePage: function() {
60 60
 			// find present pages
61  
-			var $pages = $( ":jqmData(role='page')" );
  61
+			var $dialogs, $pages = $( ":jqmData(role='page')" );
62 62
 
63  
-			// if no pages are found, create one with body's inner html
  63
+			// if no pages are found, check for dialogs or create one with body's inner html
64 64
 			if ( !$pages.length ) {
65  
-				$pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
  65
+				$dialogs = $( ":jqmData(role='dialog')" );
  66
+
  67
+				// if there are no pages but a dialog is present, load it as a page
  68
+				if( $dialogs.length ) {
  69
+					// alter the attribute so it will be treated as a page unpon enhancement
  70
+					// TODO allow for the loading of a dialog as the first page (many considerations)
  71
+					$dialogs.first().attr( "data-" + $.mobile.ns + "role", "page" );
  72
+
  73
+					// remove the first dialog from the set of dialogs since it's now a page
  74
+					// add it to the empty set of pages to be loaded by the initial changepage
  75
+					$pages = $pages.add( $dialogs.get().shift() );
  76
+				} else {
  77
+					$pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
  78
+				}
66 79
 			}
67 80
 
  81
+
68 82
 			// add dialogs, set data-url attrs
69 83
 			$pages.add( ":jqmData(role='dialog')" ).each(function() {
70 84
 				var $this = $(this);

0 notes on commit 26c1d8e

Please sign in to comment.
Something went wrong with that request. Please try again.