]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/vendor/codemirror/util/dialog.js
Remove mc config
[rbdr/dotfiles] / atom / packages / pretty-json / node_modules / jsonminify / report / assets / scripts / vendor / codemirror / util / dialog.js
1 // Open simple dialogs on top of an editor. Relies on dialog.css.
2
3 (function() {
4 function dialogDiv(cm, template, bottom) {
5 var wrap = cm.getWrapperElement();
6 var dialog;
7 dialog = wrap.appendChild(document.createElement("div"));
8 if (bottom) {
9 dialog.className = "CodeMirror-dialog CodeMirror-dialog-bottom";
10 } else {
11 dialog.className = "CodeMirror-dialog CodeMirror-dialog-top";
12 }
13 dialog.innerHTML = template;
14 return dialog;
15 }
16
17 CodeMirror.defineExtension("openDialog", function(template, callback, options) {
18 var dialog = dialogDiv(this, template, options && options.bottom);
19 var closed = false, me = this;
20 function close() {
21 if (closed) return;
22 closed = true;
23 dialog.parentNode.removeChild(dialog);
24 }
25 var inp = dialog.getElementsByTagName("input")[0], button;
26 if (inp) {
27 CodeMirror.on(inp, "keydown", function(e) {
28 if (e.keyCode == 13 || e.keyCode == 27) {
29 CodeMirror.e_stop(e);
30 close();
31 me.focus();
32 if (e.keyCode == 13) callback(inp.value);
33 }
34 });
35 inp.focus();
36 CodeMirror.on(inp, "blur", close);
37 } else if (button = dialog.getElementsByTagName("button")[0]) {
38 CodeMirror.on(button, "click", function() {
39 close();
40 me.focus();
41 });
42 button.focus();
43 CodeMirror.on(button, "blur", close);
44 }
45 return close;
46 });
47
48 CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
49 var dialog = dialogDiv(this, template, options && options.bottom);
50 var buttons = dialog.getElementsByTagName("button");
51 var closed = false, me = this, blurring = 1;
52 function close() {
53 if (closed) return;
54 closed = true;
55 dialog.parentNode.removeChild(dialog);
56 me.focus();
57 }
58 buttons[0].focus();
59 for (var i = 0; i < buttons.length; ++i) {
60 var b = buttons[i];
61 (function(callback) {
62 CodeMirror.on(b, "click", function(e) {
63 CodeMirror.e_preventDefault(e);
64 close();
65 if (callback) callback(me);
66 });
67 })(callbacks[i]);
68 CodeMirror.on(b, "blur", function() {
69 --blurring;
70 setTimeout(function() { if (blurring <= 0) close(); }, 200);
71 });
72 CodeMirror.on(b, "focus", function() { ++blurring; });
73 }
74 });
75 })();