1 (function( $, window, undefined ) {
2 var $html = $( "html" ),
4 $window = $.mobile.$window;
6 //remove initial build class (only present on first pageshow)
7 function hideRenderingClass() {
8 $html.removeClass( "ui-mobile-rendering" );
11 // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
12 $( window.document ).trigger( "mobileinit" );
15 // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
16 // otherwise, proceed with the enhancements
17 if ( !$.mobile.gradeA() ) {
21 // override ajaxEnabled on platforms that have known conflicts with hash history updates
22 // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
23 if ( $.mobile.ajaxBlacklist ) {
24 $.mobile.ajaxEnabled = false;
27 // Add mobile, initial load "rendering" classes to docEl
28 $html.addClass( "ui-mobile ui-mobile-rendering" );
30 // This is a fallback. If anything goes wrong (JS errors, etc), or events don't fire,
31 // this ensures the rendering class is removed after 5 seconds, so content is visible and accessible
32 setTimeout( hideRenderingClass, 5000 );
35 addEventBlocker: function () {
36 $html.addClass( "ui-blocker" );
37 $html.bind( "touchstart touchend vclick mousedown mouseup click", function () {
42 removeEventBlocker: function () {
43 $html.removeClass( "ui-blocker" );
44 $html.unbind( "touchstart touchend vclick mousedown mouseup click" );
47 // find and enhance the pages in the dom and transition to the first page.
48 initializePage: function() {
50 var $pages = $( ":jqmData(role='page'), :jqmData(role='dialog')" ),
51 hash = $.mobile.path.parseLocation().hash.replace("#", ""),
52 hashPage = document.getElementById( hash );
54 // if no pages are found, create one with body's inner html
55 if ( !$pages.length ) {
56 $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
59 // add dialogs, set data-url attrs
60 $pages.each(function() {
61 var $this = $( this );
63 // unless the data url is already set set it to the pathname
64 if ( !$this[0].getAttribute( "data-" + $.mobile.ns + "url" ) ) {
65 $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
69 // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
70 $.mobile.firstPage = $pages.first();
72 // define page container
73 $.mobile.pageContainer = $.mobile.firstPage.parent().addClass( "ui-mobile-viewport" );
75 // alert listeners that the pagecontainer has been determined for binding
76 // to events triggered on it
77 $window.trigger( "pagecontainercreate" );
79 // cue page loading message
80 $.mobile.showPageLoadingMsg();
81 $.mobile.addEventBlocker();
83 //remove initial build class (only present on first pageshow)
86 // if hashchange listening is disabled, there's no hash deeplink,
87 // the hash is not valid (contains more than one # or does not start with #)
88 // or there is no page with that hash, change to the first page in the DOM
89 // Remember, however, that the hash can also be a path!
90 if ( ! ( $.mobile.hashListeningEnabled &&
91 $.mobile.path.isHashValid( location.hash ) &&
92 ( $( hashPage ).is( ':jqmData(role="page")' ) ||
93 $.mobile.path.isPath( hash ) ||
94 hash === $.mobile.dialogHashKey ) ) ) {
96 // Store the initial destination
97 if ( $.mobile.path.isHashValid( location.hash ) ) {
98 $.mobile.urlHistory.initialDst = hash.replace( "#", "" );
100 $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
102 // otherwise, trigger a hashchange to load a deeplink
104 $window.trigger( "hashchange", [ true ] );
109 // initialize events now, after mobileinit has occurred
110 $.mobile.navreadyDeferred.resolve();
112 // check which scrollTop value should be used by scrolling to 1 immediately at domready
113 // then check what the scroll top is. Android will report 0... others 1
114 // note that this initial scroll won't hide the address bar. It's just for the check.
116 window.scrollTo( 0, 1 );
118 // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
119 // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
120 // so if it's 1, use 0 from now on
121 $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $.mobile.$window.scrollTop() === 1 ) ? 0 : 1;
124 // TODO: Implement a proper registration mechanism with dependency handling in order to not have exceptions like the one below
125 //auto self-init widgets for those widgets that have a soft dependency on others
126 if ( $.fn.controlgroup ) {
127 $.mobile.$document.bind( "pagecreate create", function( e ) {
128 $( ":jqmData(role='controlgroup')", e.target )
130 .controlgroup({ excludeInvisible: false });
135 if ( $.mobile.autoInitializePage ) {
136 $.mobile.initializePage();
140 // hide iOS browser chrome on load
141 $window.load( $.mobile.silentScroll );
143 if ( !$.support.cssPointerEvents ) {
144 // IE and Opera don't support CSS pointer-events: none that we use to disable link-based buttons
145 // by adding the 'ui-disabled' class to them. Using a JavaScript workaround for those browser.
146 // https://github.com/jquery/jquery-mobile/issues/3558
148 $.mobile.$document.delegate( ".ui-disabled", "vclick",
151 e.stopImmediatePropagation();