Configuring Defaults


Working with jQuery Mobile's Auto-initialization

Unlike other jQuery projects, such as jQuery and jQuery UI, jQuery Mobile automatically applies many markup enhancements as soon as it loads (long before the document.ready event fires). These enhancements are applied based on jQuery Mobile's default settings, which are designed to work with common scenarios. If changes to the settings are needed, they are easy to configure.

The mobileinit event

When jQuery Mobile starts, it triggers a mobileinit event on the document object. To override default settings, bind to mobileinit.

1
2
3
$( document ).on( "mobileinit", function() {
//apply overrides here
});

Because the mobileinit event is triggered immediately, you'll need to bind your event handler before jQuery Mobile is loaded. Link to your JavaScript files in the following order:

1
2
3
<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

You can override default settings by extending the $.mobile object using jQuery's $.extend method.

1
2
3
4
5
$( document ).on( "mobileinit", function() {
$.extend( $.mobile , {
foo: bar
});
});

Alternatively, you can set them using object property notation.

1
2
3
$( document ).on( "mobileinit", function() {
$.mobile.foo = bar;
});

Configurable options

The following defaults are configurable via the $.mobile object:

activeBtnClass string, default: "ui-btn-active"
The CSS class used for "active" button state.
Deprecated in 1.4 and will be removed in 1.5. The class "ui-btn-active" will continue to be applied to elements as before.

activePageClass string, default: "ui-page-active"
The CSS class used for the page currently in view or in a transition.
Deprecated in 1.4 and will be removed in 1.5. The class "ui-page-active" will continue to be applied to elements as before.

ajaxEnabled boolean, default: true
jQuery Mobile will automatically handle link clicks and form submissions through Ajax, when possible. If false, URL hash listening will be disabled as well, and URLs will load as ordinary HTTP requests.

allowCrossDomainPages boolean, default: false
When jQuery Mobile attempts to load an external page, the request runs through $.mobile.loadPage(). This will only allow cross-domain requests if $.mobile.allowCrossDomainPages is set to true. Because the jQuery Mobile framework tracks what page is being viewed within the browser's location hash, it is possible for a cross-site scripting (XSS) attack to occur if the XSS code in question can manipulate the hash and set it to a cross-domain URL of its choice. This is the main reason that the default setting for $.mobile.allowCrossDomainPages is set to false. In PhoneGap apps that must "phone home" by loading assets off a remote server, both the $.support.cors AND $.mobile.allowCrossDomainPages must be set to true.

autoInitializePage boolean, default: true
When the DOM is ready, the framework should automatically call $.mobile.initializePage. If false, the page will not initialize and will be visually hidden until $.mobile.initializePage is manually called.

buttonMarkup.hoverDelay integer, default: 200
Set the delay for touch devices to add the hover and down classes on touch interactions for buttons throughout the framework. Reducing the delay here results in a more responsive feeling ui, but will often result in the downstate being applied during page scrolling.
Deprecated in 1.4 - use $.mobile.hoverDelay instead.

defaultDialogTransition string, default: 'pop'
Set the default transition for dialog changes that use Ajax. Set to 'none' for no transitions.
Deprecated in 1.4.

When using pages styled as dialogs (data-role="page" data-dialog="true"), if you wish for them to have a different transition than regular pages, you must specify the transition on the link that opens them by adding the attribute data-transition="pop" to the link. "pop" is just an example. You may specify any transition you wish, such as "slide", "flip", or "none".

Similarly, when calling the pagecontainer's change() method, you must also specify the transition explicitly, if you wish it to be different from the $.mobile.defaultPageTransition:

1
2
$( ":mobile-pagecontainer" )
.pagecontainer( "change", "dialog.html", { transition: "pop" } );

$.mobile.defaultDialogTransition is deprecated.
defaultPageTransition string, default: 'fade'
Set the default transition for page changes that use Ajax. Note: default changed from 'slide' to 'fade' in 1.1. Set to 'none' for no transitions.

degradeInputs object
This setting influences the default behaviour of the function $.mobile.degradeInputsWithin(). It specifies how inputs are to be degraded. Each property is the name of an input type, and the property's value is either false, meaning to leave inputs of the given type untouched, or a string giving an alternative input type into which elements of the given input type should be converted. By default, only input elements of type "range" and of type "search" are degraded:
"color", default: false
The input type to which to convert input elements of type "color".
"date", default: false
The input type to which to convert input elements of type "date".
"datetime", default: false
The input type to which to convert input elements of type "datetime".
"datetime-local", default: false
The input type to which to convert input elements of type "datetime-local".
"email", default: false
The input type to which to convert input elements of type "email".
"month", default: false
The input type to which to convert input elements of type "month".
"number", default: false
The input type to which to convert input elements of type "number".
"range", default: "number"
The input type to which to convert input elements of type "range".
"search", default: "text"
The input type to which to convert input elements of type "search".
"tel", default: false
The input type to which to convert input elements of type "tel".
"time", default: false
The input type to which to convert input elements of type "time".
"url", default: false
The input type to which to convert input elements of type "url".
"week", default: false
The input type to which to convert input elements of type "week".

dynamicBaseEnabled boolean, default: true
When this property is set to false the base tag value in browsers that support a dynamic base tag and URL prefixes in browsers that don't won't be updated to reflect where the page was loaded from. This means that resource references that are relative to the page on which they are defined may break. This option is available for web frameworks that operate under a universal base tag value where all links and assets are relative to a single base.

focusClass string, default: "ui-focus"
The CSS class used for "active" button state.
Deprecated in 1.4 and will be removed in 1.5. The class "ui-focus" will continue to be applied to elements as before.

getMaxScrollForTransition function
Set a scroll position breakpoint for transitions. If the scroll position is greater than the value returned by this function, transition "none" will be used. The default function returns three times the height of the window.

gradeA function that returns a boolean, default: a function returning the value of $.support.mediaquery
Any support conditions that must be met in order to proceed.

hashListeningEnabled boolean, default: true
jQuery Mobile will automatically listen and handle changes to the location.hash. Disabling this will prevent jQuery Mobile from handling hash changes, which allows you to handle them yourself or use simple deep-links within a document that scroll to a particular id.

ignoreContentEnabled boolean, default: false
Warning: Setting this property to true will cause performance degradation on enhancement. Once set, all automatic enhancements made by the framework to each enhanceable element of the user's markup will first check for a data-enhance=false parent node. If one is found the markup will be ignored. This setting and the accompanying data attribute provide a mechanism through which users can prevent enhancement over large sections of markup.

keepNative Selector, default: ":jqmData(role='none'), :jqmData(role='nojs')"
Elements matching the selector specified in this option will never be enhanced. This is different from ignoreContentEnabled because it does not affect the children of elements that match this selector.

linkBindingEnabled boolean, default: true
jQuery Mobile will automatically bind the clicks on anchor tags in your document. Setting this option to false will prevent all anchor click handling including the addition of active button state and alternate link bluring. This should only be used when attempting to delegate the click management to another library or custom code.

maxTransitionWidth integer, boolean, default: false
Set a max width for transitions. The option accepts any number representing a pixel width and its default value false. If a number value is set, transition "none" will be used if the window is wider than the specified value.

minScrollBack integer, default: 0
Minimum scroll distance that will be remembered when returning to a page.
Deprecated in 1.4 and will be removed in 1.5. Any and all scrolling will be remembered. This matches native behavior. The old default value of 250 has changed to 0 during the deprecation period.

ns string, default: ""
The namespace used in data attributes (e.g., data-role). Can be set to any string, including a blank string which is the default. When using, it's clearest if you include a trailing dash, such as "mynamespace-" which maps to data-mynamespace-foo="...".

If you use data- namespacing, you will need to update/override one selector in the theme CSS. The following data selectors should incorporate the namespace you're using:

1
.ui-mobile [data-mynamespace-role=page], .ui-mobile [data-mynamespace-role=dialog], .ui-page { ...


pageLoadErrorMessage string, default: "Error Loading Page"
Set the text that appears when a page fails to load through Ajax.

pageLoadErrorMessageTheme string, default: "e"
Set the theme that the error message box uses.

phonegapNavigationEnabled boolean, default: false
Replace calls to window.history.back with PhoneGap's navigation helper where it is available. This addresses navigation issues on page refresh in Android PhoneGap applications using jQuery Mobile.

pushStateEnabled boolean, default: true
Enhancement to use history.replaceState in supported browsers, to convert the hash-based Ajax URL into the full document path. Note that we recommend disabling this feature if Ajax is disabled or if external links are used extensively.

subPageUrlKey string, default: "ui-page"
The url parameter used for referencing widget-generated sub-pages (such as those generated by nested listviews). Translates to example.html&ui-page=subpageIdentifier. The hash segment before &ui-page= is used by the framework for making an Ajax request to the URL where the sub-page exists.
Deprecated in 1.4 and will be removed in 1.5.

transitionFallbacks.[transition] string, default: "fade"
Set the fallback transition for browsers that don't support 3D transforms for a specific transition type.