2 (function( $, window ) {
4 // NOTE global mobile object settings
6 // DEPRECATED Should the text be visble in the loading message?
7 loadingMessageTextVisible: undefined,
9 // DEPRECATED When the text is visible, what theme does the loading box use?
10 loadingMessageTheme: undefined,
12 // DEPRECATED default message setting
13 loadingMessage: undefined,
16 // Turn on/off page loading message. Theme doubles as an object argument
17 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
18 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
19 showPageLoadingMsg: function( theme, msgText, textonly ) {
20 $.mobile.loading( 'show', theme, msgText, textonly );
24 hidePageLoadingMsg: function() {
25 $.mobile.loading( 'hide' );
29 this.loaderWidget.loader.apply( this.loaderWidget, arguments );
33 // TODO move loader class down into the widget settings
34 var loaderClass = "ui-loader", $html = $( "html" ), $window = $.mobile.$window;
36 $.widget( "mobile.loader", {
37 // NOTE if the global config settings are defined they will override these
40 // the theme for the loading message
43 // whether the text in the loading message is shown
46 // custom html for the inner content of the loading message
49 // the text to be displayed when the popup is shown
53 defaultHtml: "<div class='" + loaderClass + "'>" +
54 "<span class='ui-icon ui-icon-loading'></span>" +
58 // For non-fixed supportin browsers. Position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
59 fakeFixLoader: function() {
60 var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
64 top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
65 activeBtn.length && activeBtn.offset().top || 100
69 // check position of loader to see if it appears to be "fixed" to center
70 // if not, use abs positioning
71 checkLoaderPosition: function() {
72 var offset = this.element.offset(),
73 scrollTop = $window.scrollTop(),
74 screenHeight = $.mobile.getScreenHeight();
76 if ( offset.top < scrollTop || ( offset.top - scrollTop ) > screenHeight ) {
77 this.element.addClass( "ui-loader-fakefix" );
80 .unbind( "scroll", this.checkLoaderPosition )
81 .bind( "scroll", this.fakeFixLoader );
85 resetHtml: function() {
86 this.element.html( $( this.defaultHtml ).html() );
89 // Turn on/off page loading message. Theme doubles as an object argument
90 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
91 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
92 // TODO sweet jesus we need to break some of this out
93 show: function( theme, msgText, textonly ) {
94 var textVisible, message, $header, loadSettings;
98 // use the prototype options so that people can set them globally at
99 // mobile init. Consistency, it's what's for dinner
100 if ( $.type(theme) === "object" ) {
101 loadSettings = $.extend( {}, this.options, theme );
103 // prefer object property from the param then the old theme setting
104 theme = loadSettings.theme || $.mobile.loadingMessageTheme;
106 loadSettings = this.options;
108 // here we prefer the them value passed as a string argument, then
109 // we prefer the global option because we can't use undefined default
110 // prototype options, then the prototype option
111 theme = theme || $.mobile.loadingMessageTheme || loadSettings.theme;
114 // set the message text, prefer the param, then the settings object
115 // then loading message
116 message = msgText || $.mobile.loadingMessage || loadSettings.text;
119 $html.addClass( "ui-loading" );
121 if ( $.mobile.loadingMessage !== false || loadSettings.html ) {
122 // boolean values require a bit more work :P, supports object properties
124 if ( $.mobile.loadingMessageTextVisible !== undefined ) {
125 textVisible = $.mobile.loadingMessageTextVisible;
127 textVisible = loadSettings.textVisible;
130 // add the proper css given the options (theme, text, etc)
131 // Force text visibility if the second argument was supplied, or
132 // if the text was explicitly set in the object args
133 this.element.attr("class", loaderClass +
134 " ui-corner-all ui-body-" + theme +
135 " ui-loader-" + ( textVisible || msgText || theme.text ? "verbose" : "default" ) +
136 ( loadSettings.textonly || textonly ? " ui-loader-textonly" : "" ) );
138 // TODO verify that jquery.fn.html is ok to use in both cases here
139 // this might be overly defensive in preventing unknowing xss
140 // if the html attribute is defined on the loading settings, use that
141 // otherwise use the fallbacks from above
142 if ( loadSettings.html ) {
143 this.element.html( loadSettings.html );
145 this.element.find( "h1" ).text( message );
148 // attach the loader to the DOM
149 this.element.appendTo( $.mobile.pageContainer );
151 // check that the loader is visible
152 this.checkLoaderPosition();
154 // on scroll check the loader position
155 $window.bind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
160 $html.removeClass( "ui-loading" );
162 if ( $.mobile.loadingMessage ) {
163 this.element.removeClass( "ui-loader-fakefix" );
166 $.mobile.$window.unbind( "scroll", $.proxy( this.fakeFixLoader, this) );
167 $.mobile.$window.unbind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
171 $window.bind( 'pagecontainercreate', function() {
172 $.mobile.loaderWidget = $.mobile.loaderWidget || $( $.mobile.loader.prototype.defaultHtml ).loader();