From 8124e108cb765411c5dbcc6ca295cae8efb54f0a Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 28 Jun 2011 11:34:04 -0400 Subject: [PATCH 1/2] Allow for a customizable class (or classes) to be used for the loading message div instead of, or in addition to, the default of "ui-body-a". Also, allow $.mobile.loadingMessage to be set to true, instead of a string, so that a spinner may appear with no associated loading message. --- js/jquery.mobile.core.js | 4 ++++ js/jquery.mobile.init.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/js/jquery.mobile.core.js b/js/jquery.mobile.core.js index f2107a00973..06763fec52d 100644 --- a/js/jquery.mobile.core.js +++ b/js/jquery.mobile.core.js @@ -52,8 +52,12 @@ //show loading message during Ajax requests //if false, message will not appear, but loading classes will still be toggled on html el + //if true, spinner will appear without message loadingMessage: "loading", + //class used for loading message + loadingMessageClass: "ui-body-a", + //error response message - appears when an Ajax page request fails pageLoadErrorMessage: "Error Loading Page", diff --git a/js/jquery.mobile.init.js b/js/jquery.mobile.init.js index 951a18fc377..88bab34e803 100644 --- a/js/jquery.mobile.init.js +++ b/js/jquery.mobile.init.js @@ -33,7 +33,12 @@ //loading div which appears during Ajax requests //will not appear if $.mobile.loadingMessage is false - var $loader = $.mobile.loadingMessage ? $( "
" + "" + "

" + $.mobile.loadingMessage + "

" + "
" ) : undefined; + //NOTE: interior h1 will not be added if $.mobile.loadingMessage == true instead of a string such as 'loading' + var $loader; + if ( $.mobile.loadingMessage ) + $loader = $( "
" + "" + ($.mobile.loadingMessage == true ? '' : "

" + $.mobile.loadingMessage + "

") + "
" ); + else + $loader = undefined; $.extend($.mobile, { // turn on/off page loading message. From a6de24b15ac8078673fd8c10825c576a00a16c33 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Tue, 28 Jun 2011 12:16:28 -0400 Subject: [PATCH 2/2] Extracted the error message logic into a new, reusable $.mobile.showMessage() function which can be used to display any message to the user. In addition to specifying a custom message, options such as delayTime, fadeTime, and wrapperClass can be specified. NOTE: the delayTime remains 800ms for page loading error messages for the sake of continuity, but the default delayTime has been increased to 2500ms, which seems more appropriate for messages of any length. --- js/jquery.mobile.navigation.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 8a53127fad5..dd73b7dbb92 100644 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -700,16 +700,8 @@ // Remove loading message. if ( settings.showLoadMsg ) { - $.mobile.hidePageLoadingMsg(); - //show error message - $( "

"+ $.mobile.pageLoadErrorMessage +"

" ) - .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 }) - .appendTo( settings.pageContainer ) - .delay( 800 ) - .fadeOut( 400, function() { - $( this ).remove(); - }); + $.mobile.showMessage( $.mobile.pageLoadErrorMessage, { pageContainer: settings.pageContainer, delayTime: 800 } ); } deferred.reject( absUrl, options ); @@ -728,6 +720,28 @@ pageContainer: undefined }; + // Show a custom message to the user (will be shown in the active page unless specified otherwise in options) + $.mobile.showMessage = function( message, options ) { + $.mobile.hidePageLoadingMsg(); + + var showMessageOptions = $.extend( {}, $.mobile.showMessage.defaults, options ); + $( "

"+ message +"

" ) + .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 }) + .appendTo( showMessageOptions.pageContainer == undefined ? $.mobile.activePage : showMessageOptions.pageContainer ) + .delay( showMessageOptions.delayTime ) + .fadeOut( showMessageOptions.fadeTime, function() { + $( this ).remove(); + }); + }; + + // Default options for showMessage() + $.mobile.showMessage.defaults = { + delayTime: 2500, + fadeTime: 400, + wrapperClass: 'ui-body-e', + pageContainer: undefined + }; + // Show a specific page in the page container. $.mobile.changePage = function( toPage, options ) { // XXX: REMOVE_BEFORE_SHIPPING_1.0