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.
When jQuery Mobile starts, it triggers a mobileinit
event on the document
object. To override default settings, bind to mobileinit
.
$( 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:
<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.
$( document ).on( "mobileinit", function() { $.extend( $.mobile , { foo: bar }); });
Alternatively, you can set them using object property notation.
$( document ).on( "mobileinit", function() { $.mobile.foo = bar; });
The following defaults are configurable via the $.mobile
object:
activeBtnClass
string, default: "ui-btn-active"activePageClass
string, default: "ui-page-active"ajaxEnabled
boolean, default: trueallowCrossDomainPages
boolean, default: false$.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$.mobile.initializePage
. If false, the page will not initialize and will be visually hidden until $.mobile.initializePage
is manually called.$.mobile.hoverDelay
instead.defaultDialogTransition
string, default: 'pop'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
:
$( ":mobile-pagecontainer" ) .pagecontainer( "change", "dialog.html", { transition: "pop" } );
defaultPageTransition
string, default: 'fade'degradeInputs
object
"color"
, default: false
input
elements of type "color"
."date"
, default: false
input
elements of type "date"
."datetime"
, default: false
input
elements of type "datetime"
."datetime-local"
, default: false
input
elements of type "datetime-local"
."email"
, default: false
input
elements of type "email"
."month"
, default: false
input
elements of type "month"
."number"
, default: false
input
elements of type "number"
."range"
, default: "number"
input
elements of type "range"
."search"
, default: "text"
input
elements of type "search"
."tel"
, default: false
input
elements of type "tel"
."time"
, default: false
input
elements of type "time"
."url"
, default: false
input
elements of type "url"
."week"
, default: false
input
elements of type "week"
.dynamicBaseEnabled
boolean, default: truefalse
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"getMaxScrollForTransition
function
gradeA
function that returns a boolean, default: a function returning the value of $.support.mediaqueryhashListeningEnabled
boolean, default: trueignoreContentEnabled
boolean, default: falsedata-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')"linkBindingEnabled
boolean, default: truemaxTransitionWidth
integer, boolean, default: falsefalse
. If a number value is set, transition "none" will be used if the window is wider than the specified value.minScrollBack
integer, default: 0ns
string, default: ""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:
.ui-mobile [data-mynamespace-role=page], .ui-mobile [data-mynamespace-role=dialog], .ui-page { ...
pageLoadErrorMessage
string, default: "Error Loading Page"pageLoadErrorMessageTheme
string, default: "e"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: truehistory.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"transitionFallbacks.[transition]
string, default: "fade"
© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquerymobile.com/global-config