aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/lib/util/dialog.js
diff options
context:
space:
mode:
authorEric Guzman2012-02-16 00:22:43 -0800
committerEric Guzman2012-02-16 00:22:43 -0800
commit82b1a273219f0ae3d119e156c7acccdbe478f441 (patch)
tree74c45e5e3afc6706b2f7a7918807f72c54cdcfc5 /imports/codemirror/lib/util/dialog.js
parentaf20ca9b11133dd5cefb9275dbe8fb101c3380d0 (diff)
parent966f0adaf1d4b7f2dd5a6e31643df58bff713884 (diff)
downloadninja-82b1a273219f0ae3d119e156c7acccdbe478f441.tar.gz
Merge branch 'refs/heads/TreeComponents' into PresetsPanel
Diffstat (limited to 'imports/codemirror/lib/util/dialog.js')
-rwxr-xr-ximports/codemirror/lib/util/dialog.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/imports/codemirror/lib/util/dialog.js b/imports/codemirror/lib/util/dialog.js
new file mode 100755
index 00000000..8950bf0c
--- /dev/null
+++ b/imports/codemirror/lib/util/dialog.js
@@ -0,0 +1,63 @@
1// Open simple dialogs on top of an editor. Relies on dialog.css.
2
3(function() {
4 function dialogDiv(cm, template) {
5 var wrap = cm.getWrapperElement();
6 var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild);
7 dialog.className = "CodeMirror-dialog";
8 dialog.innerHTML = '<div>' + template + '</div>';
9 return dialog;
10 }
11
12 CodeMirror.defineExtension("openDialog", function(template, callback) {
13 var dialog = dialogDiv(this, template);
14 var closed = false, me = this;
15 function close() {
16 if (closed) return;
17 closed = true;
18 dialog.parentNode.removeChild(dialog);
19 }
20 var inp = dialog.getElementsByTagName("input")[0];
21 if (inp) {
22 CodeMirror.connect(inp, "keydown", function(e) {
23 if (e.keyCode == 13 || e.keyCode == 27) {
24 CodeMirror.e_stop(e);
25 close();
26 me.focus();
27 if (e.keyCode == 13) callback(inp.value);
28 }
29 });
30 inp.focus();
31 CodeMirror.connect(inp, "blur", close);
32 }
33 return close;
34 });
35
36 CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
37 var dialog = dialogDiv(this, template);
38 var buttons = dialog.getElementsByTagName("button");
39 var closed = false, me = this, blurring = 1;
40 function close() {
41 if (closed) return;
42 closed = true;
43 dialog.parentNode.removeChild(dialog);
44 me.focus();
45 }
46 buttons[0].focus();
47 for (var i = 0; i < buttons.length; ++i) {
48 var b = buttons[i];
49 (function(callback) {
50 CodeMirror.connect(b, "click", function(e) {
51 CodeMirror.e_preventDefault(e);
52 close();
53 if (callback) callback(me);
54 });
55 })(callbacks[i]);
56 CodeMirror.connect(b, "blur", function() {
57 --blurring;
58 setTimeout(function() { if (blurring <= 0) close(); }, 200);
59 });
60 CodeMirror.connect(b, "focus", function() { ++blurring; });
61 }
62 });
63})(); \ No newline at end of file