Update dialog.js

This commit is contained in:
Jabba 2020-10-11 23:00:13 +00:00 committed by GitHub
parent 631b24deac
commit e21efc2c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 10 deletions

View File

@ -41,7 +41,9 @@
closeNotification(this, null);
var dialog = dialogDiv(this, template, options.bottom);
var closed = false, me = this;
var closed = false,
me = this;
function close(newVal) {
if (typeof newVal == 'string') {
inp.value = newVal;
@ -56,7 +58,8 @@
}
}
var inp = dialog.getElementsByTagName("input")[0], button;
var inp = dialog.getElementsByTagName("input")[0],
button;
if (inp) {
inp.focus();
@ -68,12 +71,18 @@
}
if (options.onInput)
CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});
CodeMirror.on(inp, "input", function(e) {
options.onInput(e, inp.value, close);
});
if (options.onKeyUp)
CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
CodeMirror.on(inp, "keyup", function(e) {
options.onKeyUp(e, inp.value, close);
});
CodeMirror.on(inp, "keydown", function(e) {
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) {
return;
}
if (e.keyCode == 27 || (options.closeOnEnter !== false && e.keyCode == 13)) {
inp.blur();
CodeMirror.e_stop(e);
@ -82,7 +91,7 @@
if (e.keyCode == 13) callback(inp.value, e);
});
if (options.closeOnBlur !== false) CodeMirror.on(dialog, "focusout", function (evt) {
if (options.closeOnBlur !== false) CodeMirror.on(dialog, "focusout", function(evt) {
if (evt.relatedTarget !== null) close();
});
} else if (button = dialog.getElementsByTagName("button")[0]) {
@ -102,7 +111,10 @@
closeNotification(this, null);
var dialog = dialogDiv(this, template, options && options.bottom);
var buttons = dialog.getElementsByTagName("button");
var closed = false, me = this, blurring = 1;
var closed = false,
me = this,
blurring = 1;
function close() {
if (closed) return;
closed = true;
@ -122,9 +134,13 @@
})(callbacks[i]);
CodeMirror.on(b, "blur", function() {
--blurring;
setTimeout(function() { if (blurring <= 0) close(); }, 200);
setTimeout(function() {
if (blurring <= 0) close();
}, 200);
});
CodeMirror.on(b, "focus", function() {
++blurring;
});
CodeMirror.on(b, "focus", function() { ++blurring; });
}
});
@ -139,7 +155,8 @@
CodeMirror.defineExtension("openNotification", function(template, options) {
closeNotification(this, close);
var dialog = dialogDiv(this, template, options && options.bottom);
var closed = false, doneTimer;
var closed = false,
doneTimer;
var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
function close() {