1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 01:34:31 +02:00

Add "Cancel" JS callback to ProcessWire.confirm(message, funcOk, funcCancel) per PR #108

This commit is contained in:
Ryan Cramer
2018-05-11 08:20:26 -04:00
parent 717c1d2961
commit 63cba339e4
2 changed files with 30 additions and 6 deletions

View File

@@ -444,16 +444,40 @@ var ProcessWireAdmin = {
};
if(typeof ProcessWire != "undefined") {
ProcessWire.confirm = function(message, func) {
if(typeof vex != "undefined" && typeof func != "undefined") {
/**
* Confirmation dialog
*
* ~~~~~
* if(ProcessWire.confirm('Send this message now?', function() {
* // user clicked Ok
* }, function() {
* // user clicked Cancel
* });
* ~~~~~
*
* @param message Message to display (or question to ask)
* @param funcOk Callback called on "Ok"
* @param funcCancel Callback called on "Cancel" (optional)
*
*/
ProcessWire.confirm = function(message, funcOk, funcCancel) {
if(typeof vex != "undefined" && typeof funcOk != "undefined") {
vex.dialog.confirm({
message: message,
callback: function(v) {
if(v) func();
if(v) {
funcOk();
} else if(typeof funcCancel != "undefined") {
funcCancel();
}
}
});
} else if(typeof func != "undefined") {
if(confirm(message)) func();
} else if(typeof funcOk != "undefined") {
if(confirm(message)) {
funcOk();
} else if(typeof funcCancel != "undefined") {
funcCancel();
}
} else {
// regular JS confirm behavior
return confirm(message);

File diff suppressed because one or more lines are too long