是否可以将取消按钮调用的操作与 alertify.js 的 onclose 调用的操作分开
Is it possible to separate the actions called by the cancel button and the onclose for alertify.js
我目前有这个:
$('form#uwbhandler').on('click', function(e){
e.preventDefault();
alertify.confirm("Mode 1",
function(){
alertify.success('Sent: Success Something');
socket.emit('send command', {data: 'acommand'});
},
function(){
alertify.success('Sent: Something');
socket.emit('send command', {data: 'bcommand'});
}).setHeader('<em>Select Mode</em> ').setting('labels',{'ok':'Mode 1', 'cancel': 'Mode 2'}).set({onshow:null, onclose:function(){ alertify.message('confirm was closed.')}});;
});
主要取自 alertify.js 页面上的示例。但是,我想自定义与 onclose 按钮分开的取消按钮操作。但是,使用对话框的 "x" 按钮关闭会在设置单独的 onclose 函数后触发取消事件事件。
我建议使用 Dialog Factory 创建自定义对话框。
The confirm dialog definition is set to invoke the cancel action upon
closing the dialog.
但是,一个快速的解决方案是继承现有的 confirm 对话框并更新其 setup
以禁用 invokeOnClose
:
alertify.dialog('myCustomDialog', function() {
return {
setup: function() {
return {
buttons: [{
text: 'Mode 1',
key: 13 /*keys.ENTER*/ ,
className: alertify.defaults.theme.ok,
}, {
text: 'Mode 2',
key: 27 /*keys.ESC*/ ,
invokeOnClose: false, // <== closing won't invoke this
className: alertify.defaults.theme.cancel,
}],
focus: {
element: 0,
select: false
},
options: {
title: '<em>Select Mode</em> ',
maximizable: false,
resizable: false
},
};
}
}
}, false, 'confirm');
然后用一个局部变量来决定是否执行onclose
回调里面的逻辑:
function demo() {
var modeSelected = false;
alertify.myCustomDialog("Which mode will it be?",
function() {
modeSelected = true;
alertify.success('Mode 1');
},
function() {
modeSelected = true;
alertify.success('Mode 2');
}
)
.set({
onshow: null,
onclose: function(arg) {
if (!modeSelected) {
alertify.message('confirm was closed.');
}
modeSelected = false;
}
});
}
我目前有这个:
$('form#uwbhandler').on('click', function(e){
e.preventDefault();
alertify.confirm("Mode 1",
function(){
alertify.success('Sent: Success Something');
socket.emit('send command', {data: 'acommand'});
},
function(){
alertify.success('Sent: Something');
socket.emit('send command', {data: 'bcommand'});
}).setHeader('<em>Select Mode</em> ').setting('labels',{'ok':'Mode 1', 'cancel': 'Mode 2'}).set({onshow:null, onclose:function(){ alertify.message('confirm was closed.')}});;
});
主要取自 alertify.js 页面上的示例。但是,我想自定义与 onclose 按钮分开的取消按钮操作。但是,使用对话框的 "x" 按钮关闭会在设置单独的 onclose 函数后触发取消事件事件。
我建议使用 Dialog Factory 创建自定义对话框。
The confirm dialog definition is set to invoke the cancel action upon closing the dialog.
但是,一个快速的解决方案是继承现有的 confirm 对话框并更新其 setup
以禁用 invokeOnClose
:
alertify.dialog('myCustomDialog', function() {
return {
setup: function() {
return {
buttons: [{
text: 'Mode 1',
key: 13 /*keys.ENTER*/ ,
className: alertify.defaults.theme.ok,
}, {
text: 'Mode 2',
key: 27 /*keys.ESC*/ ,
invokeOnClose: false, // <== closing won't invoke this
className: alertify.defaults.theme.cancel,
}],
focus: {
element: 0,
select: false
},
options: {
title: '<em>Select Mode</em> ',
maximizable: false,
resizable: false
},
};
}
}
}, false, 'confirm');
然后用一个局部变量来决定是否执行onclose
回调里面的逻辑:
function demo() {
var modeSelected = false;
alertify.myCustomDialog("Which mode will it be?",
function() {
modeSelected = true;
alertify.success('Mode 1');
},
function() {
modeSelected = true;
alertify.success('Mode 2');
}
)
.set({
onshow: null,
onclose: function(arg) {
if (!modeSelected) {
alertify.message('confirm was closed.');
}
modeSelected = false;
}
});
}