diff --git a/js/jquery.mobile.init.js b/js/jquery.mobile.init.js index 0118bd61..500f52b5 100644 --- a/js/jquery.mobile.init.js +++ b/js/jquery.mobile.init.js @@ -9,36 +9,39 @@ (function( $, window, undefined ) { var $html = $( "html" ), - $head = $( "head" ); + $head = $( "head" ), + $window = $( window ); - // find and enhance the pages in the dom and transition to the first page. - $.mobile.initializePage = function(){ - //find present pages - var $pages = $( "[data-role='page']" ); + $.extend($.mobile, { + // find and enhance the pages in the dom and transition to the first page. + initializePage: function(){ + //find present pages + var $pages = $( "[data-role='page']" ); - //add dialogs, set data-url attrs - $pages.add( "[data-role='dialog']" ).each(function(){ - $(this).attr( "data-url", $(this).attr( "id" )); - }); + //add dialogs, set data-url attrs + $pages.add( "[data-role='dialog']" ).each(function(){ + $(this).attr( "data-url", $(this).attr( "id" )); + }); - //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback) - $.mobile.firstPage = $pages.first(); + //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback) + $.mobile.firstPage = $pages.first(); - //define page container - $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" ); + //define page container + $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" ); - //cue page loading message - $.mobile.pageLoading(); + //cue page loading message + $.mobile.pageLoading(); - // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM - if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){ - $.mobile.changePage( $.mobile.firstPage, false, true, false, true ); + // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM + if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){ + $.mobile.changePage( $.mobile.firstPage, false, true, false, true ); + } + // otherwise, trigger a hashchange to load a deeplink + else { + $window.trigger( "hashchange", [ true ] ); + } } - // otherwise, trigger a hashchange to load a deeplink - else { - $window.trigger( "hashchange", [ true ] ); - } - }; + }); //trigger mobileinit event - useful hook for configuring $.mobile settings before they're used $( window.document ).trigger( "mobileinit" ); diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 9a4f0aba..05034a5e 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -8,15 +8,11 @@ extendFn = $.extend; module(libName, { - setup: function(){ - // NOTE reset for gradeA tests - $('html').removeClass('ui-mobile'); + teardown: function(){ + $.extend = extendFn; // NOTE reset for pageLoading tests $('.ui-loader').remove(); - }, - teardown: function(){ - $.extend = extendFn; } }); @@ -31,32 +27,6 @@ ok($.mobile.gradeA()); }); - test( "loading the core library triggers mobilinit on the document", function(){ - expect( 1 ); - - $(window.document).bind('mobileinit', function(event){ - ok(true); - }); - - $.testHelper.reloadLib(libName); - }); - - test( "enhancments are skipped when the browser is not grade A", function(){ - setGradeA(false); - $.testHelper.reloadLib(libName); - - //NOTE easiest way to check for enhancements, not the most obvious - ok(!$("html").hasClass("ui-mobile")); - }); - - test( "enhancments are added when the browser is grade A", function(){ - setGradeA(true); - $.testHelper.reloadLib(libName); - - ok($("html").hasClass("ui-mobile")); - }); - - //TODO lots of duplication test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){ $.testHelper.alterExtend({loadingMessage: false}); @@ -81,69 +51,6 @@ $.testHelper.reloadLib(libName); $.mobile.pageLoading(false); ok($(".ui-loader").length); - }); - - var metaViewportSelector = "head meta[name=viewport]", - setViewPortContent = function(value){ - $(metaViewportSelector).remove(); - $.testHelper.alterExtend({metaViewportContent: value}); - $.testHelper.reloadLib(libName); - }; - - test( "meta view port element is added to head when defined on mobile", function(){ - setViewPortContent("width=device-width"); - same($(metaViewportSelector).length, 1); - }); - - test( "meta view port element not added to head when not defined on mobile", function(){ - setViewPortContent(false); - same($(metaViewportSelector).length, 0); - }); - - var findFirstPage = function() { - return $("[data-role='page']").first(); - }; - - test( "active page and start page should be set to the fist page in the selected set", function(){ - var firstPage = findFirstPage(); - $.testHelper.reloadLib(libName); - - same($.mobile.firstPage, firstPage); - same($.mobile.activePage, firstPage); - }); - - test( "mobile viewport class is defined on the first page's parent", function(){ - var firstPage = findFirstPage(); - $.testHelper.reloadLib(libName); - - ok(firstPage.parent().hasClass('ui-mobile-viewport')); - }); - - test( "mobile page container is the first page's parent", function(){ - var firstPage = findFirstPage(); - $.testHelper.reloadLib(libName); - - same($.mobile.pageContainer, firstPage.parent()); - }); - - test( "page loading is called on document ready", function(){ - $.testHelper.alterExtend({ pageLoading: function(){ - start(); - ok("called"); - }}); - - stop(); - $.testHelper.reloadLib(libName); - }); - - test( "hashchange triggered on document ready with single argument: true", function(){ - $(window).bind("hashchange", function(ev, arg){ - same(arg, true); - start(); - }); - - stop(); - $.testHelper.reloadLib(libName); }); }); })(jQuery); \ No newline at end of file diff --git a/tests/unit/core/core_mobileinit.js b/tests/unit/core/core_mobileinit.js deleted file mode 100644 index 3a4b9506..00000000 --- a/tests/unit/core/core_mobileinit.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * mobile core unit tests - */ - -(function($){ - var mobilePage = undefined; - module('jquery.mobile.core.js'); - - // NOTE important to use $.fn.one here to make sure library reloads don't fire - // the event before the test check below - $(document).one("mobileinit", function(){ - mobilePage = $.mobile.page; - }); - - test( "mobile.page is available when mobile init is fired", function(){ - ok(mobilePage !== undefined, "$.mobile.page is defined"); - }); -})(jQuery); diff --git a/tests/unit/core/index.html b/tests/unit/core/index.html index 60aeb509..c346223b 100644 --- a/tests/unit/core/index.html +++ b/tests/unit/core/index.html @@ -6,8 +6,8 @@ - + diff --git a/tests/unit/init/index.html b/tests/unit/init/index.html new file mode 100644 index 00000000..27001694 --- /dev/null +++ b/tests/unit/init/index.html @@ -0,0 +1,32 @@ + + +
+ +