Skip to content

Instantly share code, notes, and snippets.

@rbdcti
Forked from yuribossa/gist:716577
Created August 2, 2011 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rbdcti/1120342 to your computer and use it in GitHub Desktop.
Save rbdcti/1120342 to your computer and use it in GitHub Desktop.
Simple Popup Message based on jQuery Mobile - supports modal windows optionally (requires jqModal)
function jqmSimpleMessageRemove(dialogID) {
/* optionally call this function to destroy a window made with jqmSimpleMessage
* especially useful if your timeout val is long and the window is shown modally
*/
var dialog = $('#' + dialogID);
if(!dialog)
return;
if(dialog.attr('_type') == 'modal') {
clearTimeout(dialog.attr('_timerID'));
//^ the timer may not exist anymore, but just in case...
dialog.fadeOut(400, function() { $(this).jqmHide().remove(); });
} else {
dialog.fadeOut(400, function(){ $(this).remove(); });
}
}
function jqmSimpleMessage(message, showLengthMS, modal) {
/* Creates a simple message dialog.
* Specify true for the modal param for the window to be created modally (no user input allowed)
* NOTE: jqModal is required if modal is set to true
*/
if(showLengthMS == undefined)
showLengthMS = 800;
if(modal == undefined)
modal = false;
//generate an ID for the dialog so we can do things like hide or remove it later
var dialogID = 'dialog_' + new Date().getTime();
$("<div id='" + dialogID + "' class='ui-loader ui-overlay-shadow ui-body-b ui-corner-all'><h1>" + message + "</h1></div>")
.css({
display: "none",
opacity: 0.96,
top: window.pageYOffset + 100
}).attr('_type', modal ? 'modal' : 'nonmodal').appendTo("body");
var dialog = $('#' + dialogID);
if(modal) {
var t = setTimeout(function() { jqmSimpleMessageRemove(dialogID); }, showLengthMS);
dialog.attr('_timerID', t);
dialog.jqm({ modal: true}).jqmShow();
} else {
dialog.show().delay(showLengthMS).fadeOut(400, function(){ $(this).remove(); });
}
return dialogID;
}
@woleakeju
Copy link

Hello, am a newbie, how to i use this function, pls illustrate or give a sample demo, tnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment