Created
February 21, 2012 21:20
-
-
Save tcaddy/1879026 to your computer and use it in GitHub Desktop.
Use jQuery Mobile $.mobile.showPageLoadingMsg() for other messages/notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var default_msg = $.mobile.loadingMessage; // set this outside function scope so we can access it later | |
// you must provide a msg argument. The delay and theme arguments are optional. | |
function show_hide_message = function(msg,delay,theme) { | |
if (typeof(delay)==='undefined') { | |
var delay = 3500; // in milliseconds | |
} | |
if (typeof(theme)==='undefined') { | |
var theme = 'a'; // default theme; setting this to 'e' is nice for error messages | |
} | |
var css_class = ''; | |
if (theme==='e') { | |
css_class = 'ui-body-e'; | |
} | |
$.mobile.loadingMessage = msg; | |
$.mobile.showPageLoadingMsg(); | |
$(".ui-loader").addClass(css_class).find(".spin:visible").hide(); // hide the spinner graphic | |
setTimeout( | |
function() { | |
$(".ui-loader").removeClass(css_class).find(".spin:hidden").show(); // show the spinner graphic when we are done | |
$.mobile.hidePageLoadingMsg(); | |
$.mobile.loadingMessage = default_msg; // reset back to default message | |
}, | |
delay | |
); | |
} |
I thought that,too, after I had been away from computer.
Thanks for the feedback!
UPDATE:
I removed UnderScore.js dependency and used setTimeout().
I also forgot to include code to set default page loading message so we can set it back to default when we are done.
Is there anywhere a link to an adequate RoR example which uses this function?
Here is a link to see it in action: http://singapore.highpoint.edu/tix/login
You can simulate a bad login by entering '123' in the barcode field.
You will briefly see the familiar ajax busy dialog for jQuerymobile.
Then you will get an error message about a login failure -- the sort of message that is typical for flash[:notice].
The error message is the ajax busy dialog w/ an alternate message, alternate theme, and with the animated GIF hidden.
Hi tcaddy,
I'm a little bit a rails newbie ...
Can you please provide a rails code snippet to call or include thesample above js function in my controller or view. thx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the only reason you need underscore.js is to provide
delay()
support thenwindow.setTimeout(fn, delay);
will do the same as you don't have any extra parameters to pass