JSFiddle - React, Tailwind, and code Playground
by Jude Duran
HTML
<div id="GlobalDialogBox"></div>
<button>CLICK</button>
JavaScript
function globalCustomModal(message, dialogType, fn1, fn2) {
//fn = fn.split(",");
var buttonSet = {};
var dialogIcon = "";
$("#GlobalDialogBox").text(message);
switch (dialogType) {
case "success":
buttonSet = {
"OK": function () {
$(this).dialog('close');
}
};
dialogIcon = "success.png";
break;
case "error":
buttonSet = {
"OK": function () {
$(this).dialog('close');
}
};
dialogIcon = "error.png";
break;
case "yesno":
buttonSet = {
"Yes": function () {
fn1();
},
"No": function () {
fn2();
}
};
dialogIcon = "error.png";
break;
default:
//if dialogType is 'warning'
buttonSet = {
"OK": function () {
$(this).dialog('close');
}
};
dialogIcon = "warning.png";
break;
}
$("#GlobalDialogBox").dialog({
resizable: false,
height: 140,
modal: true,
buttons: buttonSet
});
}
$("button").click(function () {
globalCustomModal("This is an alert", "yesno", fn1, fn2);
});
var fn1 = function () {
alert("function 1");
};
var fn2 = function (e) {
alert(e)
};