2 * "init" - Initialize the framework
5 (function( $, window, undefined ) {
6 var $html = $( "html" ),
10 // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
11 $( window.document ).trigger( "mobileinit" );
14 // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
15 // otherwise, proceed with the enhancements
16 if ( !$.mobile.gradeA() ) {
20 // override ajaxEnabled on platforms that have known conflicts with hash history updates
21 // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
22 if ( $.mobile.ajaxBlacklist ) {
23 $.mobile.ajaxEnabled = false;
26 // add mobile, initial load "rendering" classes to docEl
27 $html.addClass( "ui-mobile ui-mobile-rendering" );
29 // loading div which appears during Ajax requests
30 // will not appear if $.mobile.loadingMessage is false
31 var $loader = $( "<div class='ui-loader ui-body-a ui-corner-all'><span class='ui-icon ui-icon-loading spin'></span><h1></h1></div>" );
34 // turn on/off page loading message.
35 showPageLoadingMsg: function() {
36 if ( $.mobile.loadingMessage ) {
37 var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
41 .text( $.mobile.loadingMessage )
43 .appendTo( $.mobile.pageContainer )
44 // position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
46 top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
47 activeBtn.length && activeBtn.offset().top || 100
51 $html.addClass( "ui-loading" );
54 hidePageLoadingMsg: function() {
55 $html.removeClass( "ui-loading" );
58 // find and enhance the pages in the dom and transition to the first page.
59 initializePage: function() {
61 var $pages = $( ":jqmData(role='page')" );
63 // if no pages are found, create one with body's inner html
64 if ( !$pages.length ) {
65 $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
68 // add dialogs, set data-url attrs
69 $pages.add( ":jqmData(role='dialog')" ).each(function() {
72 // unless the data url is already set set it to the pathname
73 if ( !$this.jqmData("url") ) {
74 $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
78 // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
79 $.mobile.firstPage = $pages.first();
81 // define page container
82 $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
84 // alert listeners that the pagecontainer has been determined for binding
85 // to events triggered on it
86 $window.trigger( "pagecontainercreate" );
88 // cue page loading message
89 $.mobile.showPageLoadingMsg();
91 // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
92 if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ) {
93 $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
95 // otherwise, trigger a hashchange to load a deeplink
97 $window.trigger( "hashchange", [ true ] );
102 // This function injects a meta viewport tag to prevent scaling. Off by default, on by default when touchOverflow scrolling is enabled
103 function disableZoom() {
104 var cont = "user-scalable=no",
105 meta = $( "meta[name='viewport']" );
108 meta.attr( "content", meta.attr( "content" ) + ", " + cont );
111 $( "head" ).prepend( "<meta>", { "name": "viewport", "content": cont } );
115 // if touch-overflow is enabled, disable user scaling, as it creates usability issues
116 if( $.support.touchOverflow && $.mobile.touchOverflowEnabled && !$.mobile.touchOverflowZoomEnabled ){
120 // initialize events now, after mobileinit has occurred
121 $.mobile._registerInternalEvents();
123 // check which scrollTop value should be used by scrolling to 1 immediately at domready
124 // then check what the scroll top is. Android will report 0... others 1
125 // note that this initial scroll won't hide the address bar. It's just for the check.
127 window.scrollTo( 0, 1 );
129 // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
130 // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
131 // so if it's 1, use 0 from now on
132 $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;
135 if( $.mobile.autoInitializePage ){
136 $.mobile.initializePage();
140 // hide iOS browser chrome on load
141 $window.load( $.mobile.silentScroll );