2 * "core" - The base file for jQm
5 (function( $, window, undefined ) {
7 var nsNormalizeDict = {};
9 // jQuery.mobile configurable options
12 // Namespace used framework-wide for data-attrs. Default is no namespace
15 // Define the url parameter used for referencing widget-generated sub-pages.
16 // Translates to to example.html&ui-page=subpageIdentifier
17 // hash segment before &ui-page= is used to make Ajax request
18 subPageUrlKey: "ui-page",
20 // Class assigned to page currently in view, and during transitions
21 activePageClass: "ui-page-active",
23 // Class used for "active" button state, from CSS framework
24 activeBtnClass: "ui-btn-active",
26 // Automatically handle clicks and form submissions through Ajax, when same-domain
29 // Automatically load and show pages based on location.hash
30 hashListeningEnabled: true,
32 // disable to prevent jquery from bothering with links
33 linkBindingEnabled: true,
35 // Set default page transition - 'none' for no transitions
36 defaultPageTransition: "slide",
38 // Minimum scroll distance that will be remembered when returning to a page
41 // Set default dialog transition - 'none' for no transitions
42 defaultDialogTransition: "pop",
44 // Show loading message during Ajax requests
45 // if false, message will not appear, but loading classes will still be toggled on html el
46 loadingMessage: "loading",
48 // Error response message - appears when an Ajax page request fails
49 pageLoadErrorMessage: "Error Loading Page",
51 //automatically initialize the DOM when it's ready
52 autoInitializePage: true,
54 pushStateEnabled: true,
56 // turn of binding to the native orientationchange due to android orientation behavior
57 orientationChangeEnabled: true,
59 // Support conditions that must be met in order to proceed
60 // default enhanced qualifications are media query support OR IE 7+
62 return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
65 // TODO might be useful upstream in jquery itself ?
72 COMMAND_LEFT: 91, // COMMAND
83 MENU: 93, // COMMAND_RIGHT
98 WINDOWS: 91 // COMMAND
101 // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
102 silentScroll: function( ypos ) {
103 if ( $.type( ypos ) !== "number" ) {
104 ypos = $.mobile.defaultHomeScroll;
107 // prevent scrollstart and scrollstop events
108 $.event.special.scrollstart.enabled = false;
110 setTimeout(function() {
111 window.scrollTo( 0, ypos );
112 $( document ).trigger( "silentscroll", { x: 0, y: ypos });
115 setTimeout(function() {
116 $.event.special.scrollstart.enabled = true;
120 // Expose our cache for testing purposes.
121 nsNormalizeDict: nsNormalizeDict,
123 // Take a data attribute property, prepend the namespace
124 // and then camel case the attribute string. Add the result
125 // to our nsNormalizeDict so we don't have to do this again.
126 nsNormalize: function( prop ) {
131 return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
134 getInheritedTheme: function( el, defaultTheme ) {
136 // Find the closest parent with a theme class on it. Note that
137 // we are not using $.fn.closest() on purpose here because this
138 // method gets called quite a bit and we need it to be as fast
143 re = /ui-(bar|body)-([a-z])\b/,
147 var c = e.className || "";
148 if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
149 // We found a parent with a theme class
150 // on it so bail from this loop.
156 // Return the theme letter we found, if none, return the
157 // specified default.
159 return ltr || defaultTheme || "a";
163 // Mobile version of data and removeData and hasData methods
164 // ensures all data is set and retrieved using jQuery Mobile's data namespace
165 $.fn.jqmData = function( prop, value ) {
167 if ( typeof prop != "undefined" ) {
168 result = this.data( prop ? $.mobile.nsNormalize( prop ) : prop, value );
173 $.jqmData = function( elem, prop, value ) {
175 if ( typeof prop != "undefined" ) {
176 result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
181 $.fn.jqmRemoveData = function( prop ) {
182 return this.removeData( $.mobile.nsNormalize( prop ) );
185 $.jqmRemoveData = function( elem, prop ) {
186 return $.removeData( elem, $.mobile.nsNormalize( prop ) );
189 $.fn.removeWithDependents = function() {
190 $.removeWithDependents( this );
193 $.removeWithDependents = function( elem ) {
194 var $elem = $( elem );
196 ( $elem.jqmData('dependents') || $() ).remove();
200 $.fn.addDependents = function( newDependents ) {
201 $.addDependents( $(this), newDependents );
204 $.addDependents = function( elem, newDependents ) {
205 var dependents = $(elem).jqmData( 'dependents' ) || $();
207 $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
210 // note that this helper doesn't attempt to handle the callback
211 // or setting of an html elements text, its only purpose is
212 // to return the html encoded version of the text in all cases. (thus the name)
213 $.fn.getEncodedText = function() {
214 return $( "<div/>" ).text( $(this).text() ).html();
217 // Monkey-patching Sizzle to filter the :jqmData selector
218 var oldFind = $.find,
219 jqmDataRE = /:jqmData\(([^)]*)\)/g;
221 $.find = function( selector, context, ret, extra ) {
222 selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
224 return oldFind.call( this, selector, context, ret, extra );
227 $.extend( $.find, oldFind );
229 $.find.matches = function( expr, set ) {
230 return $.find( expr, null, null, set );
233 $.find.matchesSelector = function( node, expr ) {
234 return $.find( expr, null, null, [ node ] ).length > 0;