From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Fri, 27 Jan 2012 12:05:17 -0800
Subject: Merged old FileIO
---
imports/codemirror/lib/util/dialog.js | 63 +++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100755 imports/codemirror/lib/util/dialog.js
(limited to 'imports/codemirror/lib/util/dialog.js')
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 @@
+// Open simple dialogs on top of an editor. Relies on dialog.css.
+
+(function() {
+ function dialogDiv(cm, template) {
+ var wrap = cm.getWrapperElement();
+ var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild);
+ dialog.className = "CodeMirror-dialog";
+ dialog.innerHTML = '
' + template + '
';
+ return dialog;
+ }
+
+ CodeMirror.defineExtension("openDialog", function(template, callback) {
+ var dialog = dialogDiv(this, template);
+ var closed = false, me = this;
+ function close() {
+ if (closed) return;
+ closed = true;
+ dialog.parentNode.removeChild(dialog);
+ }
+ var inp = dialog.getElementsByTagName("input")[0];
+ if (inp) {
+ CodeMirror.connect(inp, "keydown", function(e) {
+ if (e.keyCode == 13 || e.keyCode == 27) {
+ CodeMirror.e_stop(e);
+ close();
+ me.focus();
+ if (e.keyCode == 13) callback(inp.value);
+ }
+ });
+ inp.focus();
+ CodeMirror.connect(inp, "blur", close);
+ }
+ return close;
+ });
+
+ CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
+ var dialog = dialogDiv(this, template);
+ var buttons = dialog.getElementsByTagName("button");
+ var closed = false, me = this, blurring = 1;
+ function close() {
+ if (closed) return;
+ closed = true;
+ dialog.parentNode.removeChild(dialog);
+ me.focus();
+ }
+ buttons[0].focus();
+ for (var i = 0; i < buttons.length; ++i) {
+ var b = buttons[i];
+ (function(callback) {
+ CodeMirror.connect(b, "click", function(e) {
+ CodeMirror.e_preventDefault(e);
+ close();
+ if (callback) callback(me);
+ });
+ })(callbacks[i]);
+ CodeMirror.connect(b, "blur", function() {
+ --blurring;
+ setTimeout(function() { if (blurring <= 0) close(); }, 200);
+ });
+ CodeMirror.connect(b, "focus", function() { ++blurring; });
+ }
+ });
+})();
\ No newline at end of file
--
cgit v1.2.3