|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | (function( $, window, undefined ) { |
| 11 | + |
11 | 12 | //jQuery.mobile configurable options |
12 | 13 | $.extend( $.mobile, { |
| 14 | + |
| 15 | + //namespace used framework-wide for data-attrs, widget naming, and CSS classes |
| 16 | + ns: "jq-", |
13 | 17 |
|
14 | 18 | //define the url parameter used for referencing widget-generated sub-pages. |
15 | 19 | //Translates to to example.html&ui-page=subpageIdentifier |
|
89 | 93 | TAB: 9, |
90 | 94 | UP: 38, |
91 | 95 | WINDOWS: 91 // COMMAND |
| 96 | + } |
| 97 | + }); |
| 98 | + |
| 99 | + |
| 100 | + //trigger mobileinit event - useful hook for configuring $.mobile settings before they're used |
| 101 | + $( window.document ).trigger( "mobileinit" ); |
| 102 | + |
| 103 | + |
| 104 | + //support conditions |
| 105 | + //if device support condition(s) aren't met, leave things as they are -> a basic, usable experience, |
| 106 | + //otherwise, proceed with the enhancements |
| 107 | + if ( !$.mobile.gradeA() ) { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + //extend data() to treat namespaced data-attrs the same as non-namespaced ones |
| 112 | + var jqd = $.fn.data; |
| 113 | + |
| 114 | + $.fn.data = function( prop, value ){ |
| 115 | + if( !value && !this.attr( "[data-" + prop + "]" ) && this.attr( "[data-" $.mobile.ns + prop + "]" ) ){ |
| 116 | + prop = $.mobile.ns + prop; |
| 117 | + return jqd.call( this, prop ); |
| 118 | + } |
| 119 | + }; |
| 120 | + |
| 121 | + //define vars for interal use |
| 122 | + var $window = $(window), |
| 123 | + $html = $( "html" ), |
| 124 | + $head = $( "head" ), |
| 125 | + |
| 126 | + //loading div which appears during Ajax requests |
| 127 | + //will not appear if $.mobile.loadingMessage is false |
| 128 | + $loader = $.mobile.loadingMessage ? |
| 129 | + $( "<div class='ui-loader ui-body-a ui-corner-all'>" + |
| 130 | + "<span class='ui-icon ui-icon-loading spin'></span>" + |
| 131 | + "<h1>" + $.mobile.loadingMessage + "</h1>" + |
| 132 | + "</div>" ) |
| 133 | + : undefined; |
| 134 | + |
| 135 | + |
| 136 | + //add mobile, initial load "rendering" classes to docEl |
| 137 | + $html.addClass( "ui-mobile ui-mobile-rendering" ); |
| 138 | + |
| 139 | + |
| 140 | + //define & prepend meta viewport tag, if content is defined |
| 141 | + $.mobile.metaViewportContent ? $( "<meta>", { name: "viewport", content: $.mobile.metaViewportContent}).prependTo( $head ) : undefined; |
| 142 | + |
| 143 | + |
| 144 | + //expose some core utilities |
| 145 | + $.extend($.mobile, { |
| 146 | + |
| 147 | + // turn on/off page loading message. |
| 148 | + pageLoading: function ( done ) { |
| 149 | + if ( done ) { |
| 150 | + $html.removeClass( "ui-loading" ); |
| 151 | + } else { |
| 152 | + if( $.mobile.loadingMessage ){ |
| 153 | + var activeBtn =$( "." + $.mobile.activeBtnClass ).first(); |
| 154 | + |
| 155 | + $loader |
| 156 | + .appendTo( $.mobile.pageContainer ) |
| 157 | + //position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top |
| 158 | + .css( { |
| 159 | + top: $.support.scrollTop && $(window).scrollTop() + $(window).height() / 2 || |
| 160 | + activeBtn.length && activeBtn.offset().top || 100 |
| 161 | + } ); |
| 162 | + } |
| 163 | + |
| 164 | + $html.addClass( "ui-loading" ); |
| 165 | + } |
92 | 166 | }, |
93 | 167 |
|
| 168 | + //scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value |
94 | 169 | silentScroll: function( ypos ) { |
95 | 170 | ypos = ypos || 0; |
96 | 171 | // prevent scrollstart and scrollstop events |
|
104 | 179 | setTimeout(function() { |
105 | 180 | $.event.special.scrollstart.enabled = true; |
106 | 181 | }, 150 ); |
| 182 | + }, |
| 183 | + |
| 184 | + // find and enhance the pages in the dom and transition to the first page. |
| 185 | + initializePage: function(){ |
| 186 | + //find present pages |
| 187 | + var $pages = $( "[data-" + $.mobile.ns + "role='page']" ); |
| 188 | + |
| 189 | + //add dialogs, set data-url attrs |
| 190 | + $pages.add( "[data-" + $.mobile.ns + "role='dialog']" ).each(function(){ |
| 191 | + $(this).attr( "data-" + $.mobile.ns + "url", $(this).attr( "id" )); |
| 192 | + }); |
| 193 | + |
| 194 | + //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback) |
| 195 | + $.mobile.firstPage = $pages.first(); |
| 196 | + |
| 197 | + //define page container |
| 198 | + $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" ); |
| 199 | + |
| 200 | + //cue page loading message |
| 201 | + $.mobile.pageLoading(); |
| 202 | + |
| 203 | + // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM |
| 204 | + if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){ |
| 205 | + $.mobile.changePage( $.mobile.firstPage, false, true, false, true ); |
| 206 | + } |
| 207 | + // otherwise, trigger a hashchange to load a deeplink |
| 208 | + else { |
| 209 | + $window.trigger( "hashchange", [ true ] ); |
| 210 | + } |
107 | 211 | } |
108 | 212 | }); |
| 213 | + |
| 214 | + //dom-ready inits |
| 215 | + $($.mobile.initializePage); |
| 216 | + |
| 217 | + //window load event |
| 218 | + //hide iOS browser chrome on load |
| 219 | + $window.load( $.mobile.silentScroll ); |
109 | 220 | })( jQuery, this ); |
0 commit comments