]>
git.r.bdr.sh - rbdr/dotfiles/blob - 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.
4 function dialogDiv(cm
, template
, bottom
) {
5 var wrap
= cm
.getWrapperElement();
7 dialog
= wrap
.appendChild(document
.createElement("div"));
9 dialog
.className
= "CodeMirror-dialog CodeMirror-dialog-bottom";
11 dialog
.className
= "CodeMirror-dialog CodeMirror-dialog-top";
13 dialog
.innerHTML
= template
;
17 CodeMirror
.defineExtension("openDialog", function(template
, callback
, options
) {
18 var dialog
= dialogDiv(this, template
, options
&& options
.bottom
);
19 var closed
= false, me
= this;
23 dialog
.parentNode
.removeChild(dialog
);
25 var inp
= dialog
.getElementsByTagName("input")[0], button
;
27 CodeMirror
.on(inp
, "keydown", function(e
) {
28 if (e
.keyCode
== 13 || e
.keyCode
== 27) {
32 if (e
.keyCode
== 13) callback(inp
.value
);
36 CodeMirror
.on(inp
, "blur", close
);
37 } else if (button
= dialog
.getElementsByTagName("button")[0]) {
38 CodeMirror
.on(button
, "click", function() {
43 CodeMirror
.on(button
, "blur", close
);
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;
55 dialog
.parentNode
.removeChild(dialog
);
59 for (var i
= 0; i
< buttons
.length
; ++i
) {
62 CodeMirror
.on(b
, "click", function(e
) {
63 CodeMirror
.e_preventDefault(e
);
65 if (callback
) callback(me
);
68 CodeMirror
.on(b
, "blur", function() {
70 setTimeout(function() { if (blurring
<= 0) close(); }, 200);
72 CodeMirror
.on(b
, "focus", function() { ++blurring
; });