PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.4
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.4
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / assets / lib / codemirror / addon / dialog / dialog.js

dialog.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.4, at assets/lib/codemirror/addon/dialog/dialog.js

81 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
29 if (e.keyCode == 13 || e.keyCode == 27) {
30 CodeMirror.e_stop(e);
31 close();
32 me.focus();
33 if (e.keyCode == 13) callback(inp.value);
34 }
35 });
36 if (options && options.onKeyUp) {
37 CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
38 }
39 if (options && options.value) inp.value = options.value;
40 inp.focus();
41 CodeMirror.on(inp, "blur", close);
42 } else if (button = dialog.getElementsByTagName("button")[0]) {
43 CodeMirror.on(button, "click", function() {
44 close();
45 me.focus();
46 });
47 button.focus();
48 CodeMirror.on(button, "blur", close);
49 }
50 return close;
51 });
52
53 CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
54 var dialog = dialogDiv(this, template, options && options.bottom);
55 var buttons = dialog.getElementsByTagName("button");
56 var closed = false, me = this, blurring = 1;
57 function close() {
58 if (closed) return;
59 closed = true;
60 dialog.parentNode.removeChild(dialog);
61 me.focus();
62 }
63 buttons[0].focus();
64 for (var i = 0; i < buttons.length; ++i) {
65 var b = buttons[i];
66 (function(callback) {
67 CodeMirror.on(b, "click", function(e) {
68 CodeMirror.e_preventDefault(e);
69 close();
70 if (callback) callback(me);
71 });
72 })(callbacks[i]);
73 CodeMirror.on(b, "blur", function() {
74 --blurring;
75 setTimeout(function() { if (blurring <= 0) close(); }, 200);
76 });
77 CodeMirror.on(b, "focus", function() { ++blurring; });
78 }
79 });
80 })();
81