1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Base file for jQuery Mobile
5 //>>css.structure: ../css/structure/jquery.mobile.core.css
6 //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
8 define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, window, undefined ) {
12 var nsNormalizeDict = {};
14 // jQuery.mobile configurable options
15 $.mobile = $.extend( {}, {
17 // Version of the jQuery Mobile Framework
20 // Namespace used framework-wide for data-attrs. Default is no namespace
23 // Define the url parameter used for referencing widget-generated sub-pages.
24 // Translates to to example.html&ui-page=subpageIdentifier
25 // hash segment before &ui-page= is used to make Ajax request
26 subPageUrlKey: "ui-page",
28 // Class assigned to page currently in view, and during transitions
29 activePageClass: "ui-page-active",
31 // Class used for "active" button state, from CSS framework
32 activeBtnClass: "ui-btn-active",
34 // Class used for "focus" form element state, from CSS framework
35 focusClass: "ui-focus",
37 // Automatically handle clicks and form submissions through Ajax, when same-domain
40 // Automatically load and show pages based on location.hash
41 hashListeningEnabled: true,
43 // disable to prevent jquery from bothering with links
44 linkBindingEnabled: true,
46 // Set default page transition - 'none' for no transitions
47 defaultPageTransition: "fade",
49 // Set maximum window width for transitions to apply - 'false' for no limit
50 maxTransitionWidth: false,
52 // Minimum scroll distance that will be remembered when returning to a page
55 // DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
56 touchOverflowEnabled: false,
58 // Set default dialog transition - 'none' for no transitions
59 defaultDialogTransition: "pop",
61 // Error response message - appears when an Ajax page request fails
62 pageLoadErrorMessage: "Error Loading Page",
64 // For error messages, which theme does the box uses?
65 pageLoadErrorMessageTheme: "e",
67 // replace calls to window.history.back with phonegaps navigation helper
68 // where it is provided on the window object
69 phonegapNavigationEnabled: false,
71 //automatically initialize the DOM when it's ready
72 autoInitializePage: true,
74 pushStateEnabled: true,
76 // allows users to opt in to ignoring content by marking a parent element as
78 ignoreContentEnabled: false,
80 // turn of binding to the native orientationchange due to android orientation behavior
81 orientationChangeEnabled: true,
87 // TODO might be useful upstream in jquery itself ?
94 COMMAND_LEFT: 91, // COMMAND
105 MENU: 93, // COMMAND_RIGHT
110 NUMPAD_MULTIPLY: 106,
111 NUMPAD_SUBTRACT: 109,
120 WINDOWS: 91 // COMMAND
123 // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
124 silentScroll: function( ypos ) {
125 if ( $.type( ypos ) !== "number" ) {
126 ypos = $.mobile.defaultHomeScroll;
129 // prevent scrollstart and scrollstop events
130 $.event.special.scrollstart.enabled = false;
132 setTimeout( function() {
133 window.scrollTo( 0, ypos );
134 $( document ).trigger( "silentscroll", { x: 0, y: ypos });
137 setTimeout( function() {
138 $.event.special.scrollstart.enabled = true;
142 // Expose our cache for testing purposes.
143 nsNormalizeDict: nsNormalizeDict,
145 // Take a data attribute property, prepend the namespace
146 // and then camel case the attribute string. Add the result
147 // to our nsNormalizeDict so we don't have to do this again.
148 nsNormalize: function( prop ) {
153 return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
156 // Find the closest parent with a theme class on it. Note that
157 // we are not using $.fn.closest() on purpose here because this
158 // method gets called quite a bit and we need it to be as fast
160 getInheritedTheme: function( el, defaultTheme ) {
163 re = /ui-(bar|body|overlay)-([a-z])\b/,
167 c = e.className || "";
168 if ( c && ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
169 // We found a parent with a theme class
170 // on it so bail from this loop.
177 // Return the theme letter we found, if none, return the
178 // specified default.
180 return ltr || defaultTheme || "a";
183 // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
185 // Find the closest javascript page element to gather settings data jsperf test
186 // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
187 // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
188 // the page and dialog selector is negligable. This could probably be speed up by
189 // doing a similar parent node traversal to the one found in the inherited theme code above
190 closestPageData: function( $target ) {
192 .closest( ':jqmData(role="page"), :jqmData(role="dialog")' )
196 enhanceable: function( $set ) {
197 return this.haveParents( $set, "enhance" );
200 hijackable: function( $set ) {
201 return this.haveParents( $set, "ajax" );
204 haveParents: function( $set, attr ) {
205 if ( !$.mobile.ignoreContentEnabled ) {
209 var count = $set.length,
211 e, $element, excluded;
213 for ( var i = 0; i < count; i++ ) {
214 $element = $set.eq( i );
219 var c = e.getAttribute ? e.getAttribute( "data-" + $.mobile.ns + attr ) : "";
221 if ( c === "false" ) {
230 $newSet = $newSet.add( $element );
237 getScreenHeight: function() {
238 // Native innerHeight returns more accurate value for this across platforms,
239 // jQuery version is here as a normalized fallback for platforms like Symbian
240 return window.innerHeight || $( window ).height();
244 // Mobile version of data and removeData and hasData methods
245 // ensures all data is set and retrieved using jQuery Mobile's data namespace
246 $.fn.jqmData = function( prop, value ) {
248 if ( typeof prop !== "undefined" ) {
250 prop = $.mobile.nsNormalize( prop );
253 // undefined is permitted as an explicit input for the second param
254 // in this case it returns the value and does not set it to undefined
255 if( arguments.length < 2 || value === undefined ){
256 result = this.data( prop );
258 result = this.data( prop, value );
264 $.jqmData = function( elem, prop, value ) {
266 if ( typeof prop !== "undefined" ) {
267 result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
272 $.fn.jqmRemoveData = function( prop ) {
273 return this.removeData( $.mobile.nsNormalize( prop ) );
276 $.jqmRemoveData = function( elem, prop ) {
277 return $.removeData( elem, $.mobile.nsNormalize( prop ) );
280 $.fn.removeWithDependents = function() {
281 $.removeWithDependents( this );
284 $.removeWithDependents = function( elem ) {
285 var $elem = $( elem );
287 ( $elem.jqmData( 'dependents' ) || $() ).remove();
291 $.fn.addDependents = function( newDependents ) {
292 $.addDependents( $( this ), newDependents );
295 $.addDependents = function( elem, newDependents ) {
296 var dependents = $( elem ).jqmData( 'dependents' ) || $();
298 $( elem ).jqmData( 'dependents', $.merge( dependents, newDependents ) );
301 // note that this helper doesn't attempt to handle the callback
302 // or setting of an html elements text, its only purpose is
303 // to return the html encoded version of the text in all cases. (thus the name)
304 $.fn.getEncodedText = function() {
305 return $( "<div/>" ).text( $( this ).text() ).html();
308 // fluent helper function for the mobile namespaced equivalent
309 $.fn.jqmEnhanceable = function() {
310 return $.mobile.enhanceable( this );
313 $.fn.jqmHijackable = function() {
314 return $.mobile.hijackable( this );
317 // Monkey-patching Sizzle to filter the :jqmData selector
318 var oldFind = $.find,
319 jqmDataRE = /:jqmData\(([^)]*)\)/g;
321 $.find = function( selector, context, ret, extra ) {
322 selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
324 return oldFind.call( this, selector, context, ret, extra );
327 $.extend( $.find, oldFind );
329 $.find.matches = function( expr, set ) {
330 return $.find( expr, null, null, set );
333 $.find.matchesSelector = function( node, expr ) {
334 return $.find( expr, null, null, [ node ] ).length > 0;
337 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
339 //>>excludeEnd("jqmBuildExclude");