1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Base file for jQuery Mobile
6 //>>css: ../css/structure/jquery.mobile.core.css
8 define( [ "jquery", "../external/requirejs/text!../version.txt", "./jquery.mobile.widget" ], 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 // Show loading message during Ajax requests
62 // if false, message will not appear, but loading classes will still be toggled on html el
63 loadingMessage: "loading",
65 // Error response message - appears when an Ajax page request fails
66 pageLoadErrorMessage: "Error Loading Page",
68 // Should the text be visble in the loading message?
69 loadingMessageTextVisible: false,
71 // When the text is visible, what theme does the loading box use?
72 loadingMessageTheme: "a",
74 // For error messages, which theme does the box uses?
75 pageLoadErrorMessageTheme: "e",
77 //automatically initialize the DOM when it's ready
78 autoInitializePage: true,
80 pushStateEnabled: true,
82 // allows users to opt in to ignoring content by marking a parent element as
84 ignoreContentEnabled: false,
86 // turn of binding to the native orientationchange due to android orientation behavior
87 orientationChangeEnabled: true,
93 // TODO might be useful upstream in jquery itself ?
100 COMMAND_LEFT: 91, // COMMAND
111 MENU: 93, // COMMAND_RIGHT
116 NUMPAD_MULTIPLY: 106,
117 NUMPAD_SUBTRACT: 109,
126 WINDOWS: 91 // COMMAND
129 // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
130 silentScroll: function( ypos ) {
131 if ( $.type( ypos ) !== "number" ) {
132 ypos = $.mobile.defaultHomeScroll;
135 // prevent scrollstart and scrollstop events
136 $.event.special.scrollstart.enabled = false;
138 setTimeout(function() {
139 window.scrollTo( 0, ypos );
140 $( document ).trigger( "silentscroll", { x: 0, y: ypos });
143 setTimeout(function() {
144 $.event.special.scrollstart.enabled = true;
148 // Expose our cache for testing purposes.
149 nsNormalizeDict: nsNormalizeDict,
151 // Take a data attribute property, prepend the namespace
152 // and then camel case the attribute string. Add the result
153 // to our nsNormalizeDict so we don't have to do this again.
154 nsNormalize: function( prop ) {
159 return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
162 getInheritedTheme: function( el, defaultTheme ) {
164 // Find the closest parent with a theme class on it. Note that
165 // we are not using $.fn.closest() on purpose here because this
166 // method gets called quite a bit and we need it to be as fast
171 re = /ui-(bar|body|overlay)-([a-z])\b/,
175 var c = e.className || "";
176 if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
177 // We found a parent with a theme class
178 // on it so bail from this loop.
184 // Return the theme letter we found, if none, return the
185 // specified default.
187 return ltr || defaultTheme || "a";
190 // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
192 // Find the closest javascript page element to gather settings data jsperf test
193 // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
194 // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
195 // the page and dialog selector is negligable. This could probably be speed up by
196 // doing a similar parent node traversal to the one found in the inherited theme code above
197 closestPageData: function( $target ) {
199 .closest(':jqmData(role="page"), :jqmData(role="dialog")')
203 enhanceable: function( $set ) {
204 return this.haveParents( $set, "enhance" );
207 hijackable: function( $set ) {
208 return this.haveParents( $set, "ajax" );
211 haveParents: function( $set, attr ) {
212 if( !$.mobile.ignoreContentEnabled ){
216 var count = $set.length,
218 e, $element, excluded;
220 for ( var i = 0; i < count; i++ ) {
221 $element = $set.eq( i );
226 var c = e.getAttribute ? e.getAttribute( "data-" + $.mobile.ns + attr ) : "";
228 if ( c === "false" ) {
237 $newSet = $newSet.add( $element );
245 // Mobile version of data and removeData and hasData methods
246 // ensures all data is set and retrieved using jQuery Mobile's data namespace
247 $.fn.jqmData = function( prop, value ) {
249 if ( typeof prop != "undefined" ) {
251 prop = $.mobile.nsNormalize( prop );
253 result = this.data.apply( this, arguments.length < 2 ? [ prop ] : [ prop, value ] );
258 $.jqmData = function( elem, prop, value ) {
260 if ( typeof prop != "undefined" ) {
261 result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
266 $.fn.jqmRemoveData = function( prop ) {
267 return this.removeData( $.mobile.nsNormalize( prop ) );
270 $.jqmRemoveData = function( elem, prop ) {
271 return $.removeData( elem, $.mobile.nsNormalize( prop ) );
274 $.fn.removeWithDependents = function() {
275 $.removeWithDependents( this );
278 $.removeWithDependents = function( elem ) {
279 var $elem = $( elem );
281 ( $elem.jqmData('dependents') || $() ).remove();
285 $.fn.addDependents = function( newDependents ) {
286 $.addDependents( $(this), newDependents );
289 $.addDependents = function( elem, newDependents ) {
290 var dependents = $(elem).jqmData( 'dependents' ) || $();
292 $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
295 // note that this helper doesn't attempt to handle the callback
296 // or setting of an html elements text, its only purpose is
297 // to return the html encoded version of the text in all cases. (thus the name)
298 $.fn.getEncodedText = function() {
299 return $( "<div/>" ).text( $(this).text() ).html();
302 // fluent helper function for the mobile namespaced equivalent
303 $.fn.jqmEnhanceable = function() {
304 return $.mobile.enhanceable( this );
307 $.fn.jqmHijackable = function() {
308 return $.mobile.hijackable( this );
311 // Monkey-patching Sizzle to filter the :jqmData selector
312 var oldFind = $.find,
313 jqmDataRE = /:jqmData\(([^)]*)\)/g;
315 $.find = function( selector, context, ret, extra ) {
316 selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
318 return oldFind.call( this, selector, context, ret, extra );
321 $.extend( $.find, oldFind );
323 $.find.matches = function( expr, set ) {
324 return $.find( expr, null, null, set );
327 $.find.matchesSelector = function( node, expr ) {
328 return $.find( expr, null, null, [ node ] ).length > 0;
331 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
333 //>>excludeEnd("jqmBuildExclude");