implement alertify without alertify
This commit is contained in:
parent
a302ee5d25
commit
32e8c8ef4b
@ -86,12 +86,12 @@ define([
|
|||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog.okButton = function () {
|
dialog.okButton = function (content) {
|
||||||
return h('button.ok', { tabindex: '2', }, Messages.okButton);
|
return h('button.ok', { tabindex: '2', }, content || Messages.okButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog.cancelButton = function () {
|
dialog.cancelButton = function (content) {
|
||||||
return h('button.cancel', { tabindex: '1'}, Messages.cancelButton);
|
return h('button.cancel', { tabindex: '1'}, content || Messages.cancelButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog.message = function (text) {
|
dialog.message = function (text) {
|
||||||
@ -99,11 +99,11 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
dialog.textInput = function (opt) {
|
dialog.textInput = function (opt) {
|
||||||
return h('input', opt || {
|
var attrs = merge({
|
||||||
placeholder: '',
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
'class': 'cp-text-input',
|
'class': 'cp-text-input',
|
||||||
});
|
}, opt);
|
||||||
|
return h('input', attrs);
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog.nav = function (content) {
|
dialog.nav = function (content) {
|
||||||
@ -236,92 +236,102 @@ define([
|
|||||||
document.body.appendChild(frame);
|
document.body.appendChild(frame);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$ok.focus();
|
$ok.focus();
|
||||||
if (typeof(UI.notify) === 'function') {
|
UI.notify();
|
||||||
UI.notify();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
UI.prompt = function (msg, def, cb, opt, force) {
|
UI.prompt = function (msg, def, cb, opt, force) {
|
||||||
opt = opt || {};
|
|
||||||
cb = cb || function () {};
|
cb = cb || function () {};
|
||||||
if (force !== true) { msg = Util.fixHTML(msg); }
|
opt = opt || {};
|
||||||
|
|
||||||
var keyHandler = listenForKeys(function () { // yes
|
var input = dialog.textInput();
|
||||||
findOKButton().click();
|
input.value = typeof(def) === 'string'? def: '';
|
||||||
}, function () { // no
|
|
||||||
findCancelButton().click();
|
var message;
|
||||||
|
if (typeof(msg) === 'string') {
|
||||||
|
if (!force) { msg = Util.fixHTML(msg); }
|
||||||
|
message = dialog.message();
|
||||||
|
message.innerHTML = msg;
|
||||||
|
} else {
|
||||||
|
message = dialog.message(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ok = dialog.okButton(opt.ok);
|
||||||
|
var cancel = dialog.cancelButton(opt.cancel);
|
||||||
|
var frame = dialog.frame([
|
||||||
|
message,
|
||||||
|
input,
|
||||||
|
dialog.nav([ cancel, ok, ]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
var listener;
|
||||||
|
var close = Util.once(function () {
|
||||||
|
$(frame).fadeOut(150, function () { $(this).remove(); });
|
||||||
|
stopListening(listener);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()"
|
var $ok = $(ok).click(function (ev) { cb(input.value, ev); });
|
||||||
// in the callback
|
var $cancel = $(cancel).click(function (ev) { cb(null, ev); });
|
||||||
var isClicked = false;
|
listener = listenForKeys(function () { // yes
|
||||||
|
close(); $ok.click();
|
||||||
|
}, function () { // no
|
||||||
|
close(); $cancel.click();
|
||||||
|
});
|
||||||
|
|
||||||
Alertify
|
document.body.appendChild(frame);
|
||||||
.defaultValue(def || '')
|
setTimeout(function () {
|
||||||
.okBtn(opt.ok || Messages.okButton || 'OK')
|
input.select().focus();
|
||||||
.cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel')
|
|
||||||
.prompt(msg, function (val, ev) {
|
|
||||||
if (isClicked) { return; }
|
|
||||||
isClicked = true;
|
|
||||||
cb(val, ev);
|
|
||||||
stopListening(keyHandler);
|
|
||||||
}, function (ev) {
|
|
||||||
if (isClicked) { return; }
|
|
||||||
isClicked = true;
|
|
||||||
cb(null, ev);
|
|
||||||
stopListening(keyHandler);
|
|
||||||
});
|
|
||||||
if (typeof(UI.notify) === 'function') {
|
|
||||||
UI.notify();
|
UI.notify();
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
UI.confirm = function (msg, cb, opt, force, styleCB) {
|
UI.confirm = function (msg, cb, opt, force, styleCB) {
|
||||||
opt = opt || {};
|
|
||||||
cb = cb || function () {};
|
cb = cb || function () {};
|
||||||
if (force !== true) { msg = Util.fixHTML(msg); }
|
opt = opt || {};
|
||||||
|
|
||||||
var keyHandler = listenForKeys(function () {
|
var message;
|
||||||
findOKButton().click();
|
if (typeof(msg) === 'string') {
|
||||||
}, function () {
|
if (!force) { msg = Util.fixHTML(msg); }
|
||||||
findCancelButton().click();
|
message = dialog.message();
|
||||||
|
message.innerHTML = msg;
|
||||||
|
} else {
|
||||||
|
message = dialog.message(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ok = dialog.okButton(opt.ok);
|
||||||
|
var cancel = dialog.cancelButton(opt.cancel);
|
||||||
|
|
||||||
|
var frame = dialog.frame([
|
||||||
|
message,
|
||||||
|
dialog.nav(opt.reverseOrder?
|
||||||
|
[ok, cancel]: [cancel, ok]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
var listener;
|
||||||
|
var close = Util.once(function () {
|
||||||
|
$(frame).fadeOut(150, function () { $(this).remove(); });
|
||||||
|
stopListening(listener);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure we don't call both the "yes" and "no" handlers if we use "findOKButton().click()"
|
var $ok = $(ok).click(function (ev) { close(); cb(true, ev); });
|
||||||
// in the callback
|
var $cancel = $(cancel).click(function (ev) { close(); cb(false, ev); });
|
||||||
var isClicked = false;
|
|
||||||
|
|
||||||
Alertify
|
if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); }
|
||||||
.okBtn(opt.ok || Messages.okButton || 'OK')
|
if (opt.okClass) { $ok.addClass(opt.okClass); }
|
||||||
.cancelBtn(opt.cancel || Messages.cancelButton || 'Cancel')
|
|
||||||
.confirm(msg, function () {
|
|
||||||
if (isClicked) { return; }
|
|
||||||
isClicked = true;
|
|
||||||
cb(true);
|
|
||||||
stopListening(keyHandler);
|
|
||||||
}, function () {
|
|
||||||
if (isClicked) { return; }
|
|
||||||
isClicked = true;
|
|
||||||
cb(false);
|
|
||||||
stopListening(keyHandler);
|
|
||||||
});
|
|
||||||
|
|
||||||
window.setTimeout(function () {
|
listener = listenForKeys(function () {
|
||||||
var $ok = findOKButton();
|
$ok.click();
|
||||||
var $cancel = findCancelButton();
|
}, function () {
|
||||||
if (opt.okClass) { $ok.addClass(opt.okClass); }
|
$cancel.click();
|
||||||
if (opt.cancelClass) { $cancel.addClass(opt.cancelClass); }
|
});
|
||||||
if (opt.reverseOrder) {
|
|
||||||
$ok.insertBefore($ok.prev());
|
document.body.appendChild(frame);
|
||||||
}
|
setTimeout(function () {
|
||||||
|
UI.notify();
|
||||||
if (typeof(styleCB) === 'function') {
|
if (typeof(styleCB) === 'function') {
|
||||||
styleCB($ok.closest('.dialog'));
|
styleCB($ok.closest('.dialog'));
|
||||||
}
|
}
|
||||||
}, 0);
|
});
|
||||||
if (typeof(UI.notify) === 'function') {
|
|
||||||
UI.notify();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
UI.log = function (msg) {
|
UI.log = function (msg) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user