1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: packaged loading message functionality
3 //>>label: loading message
6 define( [ "jquery", "../jquery.mobile.core", "../jquery.mobile.widget" ], function( $ ) {
7 //>>excludeEnd("jqmBuildExclude");
9 (function( $, window ) {
11 // NOTE global mobile object settings
13 // DEPRECATED Should the text be visble in the loading message?
14 loadingMessageTextVisible: undefined,
16 // DEPRECATED When the text is visible, what theme does the loading box use?
17 loadingMessageTheme: undefined,
19 // DEPRECATED default message setting
20 loadingMessage: undefined,
23 // Turn on/off page loading message. Theme doubles as an object argument
24 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
25 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
26 showPageLoadingMsg: function( theme, msgText, textonly ) {
27 $.mobile.loading( 'show', theme, msgText, textonly );
31 hidePageLoadingMsg: function() {
32 $.mobile.loading( 'hide' );
36 this.loaderWidget.loader.apply( this.loaderWidget, arguments );
40 // TODO move loader class down into the widget settings
41 var loaderClass = "ui-loader", $html = $( "html" ), $window = $( window );
43 $.widget( "mobile.loader", {
44 // NOTE if the global config settings are defined they will override these
47 // the theme for the loading message
50 // whether the text in the loading message is shown
53 // custom html for the inner content of the loading message
56 // the text to be displayed when the popup is shown
60 defaultHtml: "<div class='" + loaderClass + "'>" +
61 "<span class='ui-icon ui-icon-loading'></span>" +
65 // For non-fixed supportin browsers. Position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
66 fakeFixLoader: function() {
67 var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
71 top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
72 activeBtn.length && activeBtn.offset().top || 100
76 // check position of loader to see if it appears to be "fixed" to center
77 // if not, use abs positioning
78 checkLoaderPosition: function() {
79 var offset = this.element.offset(),
80 scrollTop = $window.scrollTop(),
81 screenHeight = $.mobile.getScreenHeight();
83 if ( offset.top < scrollTop || ( offset.top - scrollTop ) > screenHeight ) {
84 this.element.addClass( "ui-loader-fakefix" );
87 .unbind( "scroll", this.checkLoaderPosition )
88 .bind( "scroll", this.fakeFixLoader );
92 resetHtml: function() {
93 this.element.html( $( this.defaultHtml ).html() );
96 // Turn on/off page loading message. Theme doubles as an object argument
97 // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
98 // NOTE that the $.mobile.loading* settings and params past the first are deprecated
99 // TODO sweet jesus we need to break some of this out
100 show: function( theme, msgText, textonly ) {
101 var textVisible, message, $header, loadSettings;
105 // use the prototype options so that people can set them globally at
106 // mobile init. Consistency, it's what's for dinner
107 if ( $.type(theme) === "object" ) {
108 loadSettings = $.extend( {}, this.options, theme );
110 // prefer object property from the param then the old theme setting
111 theme = loadSettings.theme || $.mobile.loadingMessageTheme;
113 loadSettings = this.options;
115 // here we prefer the them value passed as a string argument, then
116 // we prefer the global option because we can't use undefined default
117 // prototype options, then the prototype option
118 theme = theme || $.mobile.loadingMessageTheme || loadSettings.theme;
121 // set the message text, prefer the param, then the settings object
122 // then loading message
123 message = msgText || $.mobile.loadingMessage || loadSettings.text;
126 $html.addClass( "ui-loading" );
128 if ( $.mobile.loadingMessage !== false || loadSettings.html ) {
129 // boolean values require a bit more work :P, supports object properties
131 if ( $.mobile.loadingMessageTextVisible !== undefined ) {
132 textVisible = $.mobile.loadingMessageTextVisible;
134 textVisible = loadSettings.textVisible;
137 // add the proper css given the options (theme, text, etc)
138 // Force text visibility if the second argument was supplied, or
139 // if the text was explicitly set in the object args
140 this.element.attr("class", loaderClass +
141 " ui-corner-all ui-body-" + theme +
142 " ui-loader-" + ( textVisible || msgText || theme.text ? "verbose" : "default" ) +
143 ( loadSettings.textonly || textonly ? " ui-loader-textonly" : "" ) );
145 // TODO verify that jquery.fn.html is ok to use in both cases here
146 // this might be overly defensive in preventing unknowing xss
147 // if the html attribute is defined on the loading settings, use that
148 // otherwise use the fallbacks from above
149 if ( loadSettings.html ) {
150 this.element.html( loadSettings.html );
152 this.element.find( "h1" ).text( message );
155 // attach the loader to the DOM
156 this.element.appendTo( $.mobile.pageContainer );
158 // check that the loader is visible
159 this.checkLoaderPosition();
161 // on scroll check the loader position
162 $window.bind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
167 $html.removeClass( "ui-loading" );
169 if ( $.mobile.loadingMessage ) {
170 this.element.removeClass( "ui-loader-fakefix" );
173 $( window ).unbind( "scroll", $.proxy( this.fakeFixLoader, this) );
174 $( window ).unbind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
178 $window.bind( 'pagecontainercreate', function() {
179 $.mobile.loaderWidget = $.mobile.loaderWidget || $( $.mobile.loader.prototype.defaultHtml ).loader();
183 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
185 //>>excludeEnd("jqmBuildExclude");