-
-
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)
This file contains 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, am a newbie, how to i use this function, pls illustrate or give a sample demo, tnx