codemirror-rails 2.36 → 3.00

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/lib/codemirror/rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/codemirror.js +3727 -2345
  3. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +2226 -825
  4. data/vendor/assets/javascripts/codemirror/modes/clike.js +23 -8
  5. data/vendor/assets/javascripts/codemirror/modes/clojure.js +4 -4
  6. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +1 -1
  7. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +1 -1
  8. data/vendor/assets/javascripts/codemirror/modes/css.js +20 -3
  9. data/vendor/assets/javascripts/codemirror/modes/diff.js +2 -2
  10. data/vendor/assets/javascripts/codemirror/modes/ecl.js +192 -203
  11. data/vendor/assets/javascripts/codemirror/modes/erlang.js +1 -1
  12. data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -1
  13. data/vendor/assets/javascripts/codemirror/modes/go.js +1 -6
  14. data/vendor/assets/javascripts/codemirror/modes/groovy.js +1 -1
  15. data/vendor/assets/javascripts/codemirror/modes/haskell.js +1 -1
  16. data/vendor/assets/javascripts/codemirror/modes/haxe.js +13 -13
  17. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +3 -3
  18. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +1 -1
  19. data/vendor/assets/javascripts/codemirror/modes/http.js +98 -0
  20. data/vendor/assets/javascripts/codemirror/modes/javascript.js +1 -1
  21. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +1 -1
  22. data/vendor/assets/javascripts/codemirror/modes/markdown.js +7 -14
  23. data/vendor/assets/javascripts/codemirror/modes/mysql.js +2 -2
  24. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +0 -2
  25. data/vendor/assets/javascripts/codemirror/modes/ocaml.js +1 -2
  26. data/vendor/assets/javascripts/codemirror/modes/pascal.js +2 -2
  27. data/vendor/assets/javascripts/codemirror/modes/perl.js +1 -1
  28. data/vendor/assets/javascripts/codemirror/modes/php.js +5 -4
  29. data/vendor/assets/javascripts/codemirror/modes/pig.js +3 -4
  30. data/vendor/assets/javascripts/codemirror/modes/plsql.js +3 -4
  31. data/vendor/assets/javascripts/codemirror/modes/python.js +1 -1
  32. data/vendor/assets/javascripts/codemirror/modes/r.js +1 -1
  33. data/vendor/assets/javascripts/codemirror/modes/rpm-changes.js +1 -1
  34. data/vendor/assets/javascripts/codemirror/modes/rpm-spec.js +1 -1
  35. data/vendor/assets/javascripts/codemirror/modes/rst.js +1 -13
  36. data/vendor/assets/javascripts/codemirror/modes/ruby.js +1 -1
  37. data/vendor/assets/javascripts/codemirror/modes/rust.js +3 -3
  38. data/vendor/assets/javascripts/codemirror/modes/scheme.js +4 -4
  39. data/vendor/assets/javascripts/codemirror/modes/shell.js +1 -1
  40. data/vendor/assets/javascripts/codemirror/modes/sieve.js +1 -1
  41. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +2 -2
  42. data/vendor/assets/javascripts/codemirror/modes/smarty.js +1 -1
  43. data/vendor/assets/javascripts/codemirror/modes/sparql.js +2 -2
  44. data/vendor/assets/javascripts/codemirror/modes/stex.js +6 -13
  45. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +6 -37
  46. data/vendor/assets/javascripts/codemirror/modes/tiki.js +3 -3
  47. data/vendor/assets/javascripts/codemirror/modes/vb.js +3 -3
  48. data/vendor/assets/javascripts/codemirror/modes/velocity.js +2 -4
  49. data/vendor/assets/javascripts/codemirror/modes/verilog.js +182 -194
  50. data/vendor/assets/javascripts/codemirror/modes/xml.js +9 -5
  51. data/vendor/assets/javascripts/codemirror/modes/xquery.js +3 -4
  52. data/vendor/assets/javascripts/codemirror/utils/closetag.js +85 -164
  53. data/vendor/assets/javascripts/codemirror/utils/colorize.js +29 -0
  54. data/vendor/assets/javascripts/codemirror/utils/continuecomment.js +1 -1
  55. data/vendor/assets/javascripts/codemirror/utils/continuelist.js +28 -0
  56. data/vendor/assets/javascripts/codemirror/utils/dialog.js +21 -16
  57. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +59 -73
  58. data/vendor/assets/javascripts/codemirror/utils/formatting.js +43 -131
  59. data/vendor/assets/javascripts/codemirror/utils/javascript-hint.js +22 -19
  60. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +5 -3
  61. data/vendor/assets/javascripts/codemirror/utils/matchbrackets.js +63 -0
  62. data/vendor/assets/javascripts/codemirror/utils/multiplex.js +18 -0
  63. data/vendor/assets/javascripts/codemirror/utils/pig-hint.js +3 -9
  64. data/vendor/assets/javascripts/codemirror/utils/runmode.js +19 -20
  65. data/vendor/assets/javascripts/codemirror/utils/search.js +6 -5
  66. data/vendor/assets/javascripts/codemirror/utils/searchcursor.js +1 -1
  67. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +10 -10
  68. data/vendor/assets/javascripts/codemirror/utils/xml-hint.js +2 -2
  69. data/vendor/assets/stylesheets/codemirror.css +169 -104
  70. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +1 -1
  71. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +7 -12
  72. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +3 -3
  73. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +3 -3
  74. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +3 -3
  75. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +4 -4
  76. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +3 -3
  77. data/vendor/assets/stylesheets/codemirror/themes/night.css +3 -3
  78. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +3 -3
  79. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +207 -0
  80. data/vendor/assets/stylesheets/codemirror/themes/twilight.css +4 -4
  81. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +3 -3
  82. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +3 -3
  83. data/vendor/assets/stylesheets/codemirror/utils/dialog.css +12 -7
  84. metadata +16 -11
@@ -211,14 +211,16 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
211
211
  }
212
212
  function endtag(startOfLine) {
213
213
  return function(type) {
214
+ var tagName = curState.tagName;
215
+ curState.tagName = null;
214
216
  if (type == "selfcloseTag" ||
215
- (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) {
216
- maybePopContext(curState.tagName.toLowerCase());
217
+ (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
218
+ maybePopContext(tagName.toLowerCase());
217
219
  return cont();
218
220
  }
219
221
  if (type == "endTag") {
220
- maybePopContext(curState.tagName.toLowerCase());
221
- pushContext(curState.tagName, startOfLine);
222
+ maybePopContext(tagName.toLowerCase());
223
+ pushContext(tagName, startOfLine);
222
224
  return cont();
223
225
  }
224
226
  return cont();
@@ -310,7 +312,9 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
310
312
  else return 0;
311
313
  },
312
314
 
313
- electricChars: "/"
315
+ electricChars: "/",
316
+
317
+ configuration: parserConfig.htmlMode ? "html" : "xml"
314
318
  };
315
319
  });
316
320
 
@@ -20,7 +20,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
22
22
  */
23
- CodeMirror.defineMode("xquery", function(config, parserConfig) {
23
+ CodeMirror.defineMode("xquery", function() {
24
24
 
25
25
  // The keywords object is set to the result of this self executing
26
26
  // function. Each keyword is a property of the keywords object whose
@@ -401,7 +401,6 @@ CodeMirror.defineMode("xquery", function(config, parserConfig) {
401
401
  // functions to test the current context of the state
402
402
  function isInXmlBlock(state) { return isIn(state, "tag"); }
403
403
  function isInXmlAttributeBlock(state) { return isIn(state, "attribute"); }
404
- function isInCodeBlock(state) { return isIn(state, "codeblock"); }
405
404
  function isInXmlConstructor(state) { return isIn(state, "xmlconstructor"); }
406
405
  function isInString(state) { return isIn(state, "string"); }
407
406
 
@@ -424,14 +423,14 @@ CodeMirror.defineMode("xquery", function(config, parserConfig) {
424
423
  }
425
424
 
426
425
  function popStateStack(state) {
427
- var popped = state.stack.pop();
426
+ state.stack.pop();
428
427
  var reinstateTokenize = state.stack.length && state.stack[state.stack.length-1].tokenize;
429
428
  state.tokenize = reinstateTokenize || tokenBase;
430
429
  }
431
430
 
432
431
  // the interface for the mode API
433
432
  return {
434
- startState: function(basecolumn) {
433
+ startState: function() {
435
434
  return {
436
435
  tokenize: tokenBase,
437
436
  cc: [],
@@ -1,164 +1,85 @@
1
- /**
2
- * Tag-closer extension for CodeMirror.
3
- *
4
- * This extension adds a "closeTag" utility function that can be used with key bindings to
5
- * insert a matching end tag after the ">" character of a start tag has been typed. It can
6
- * also complete "</" if a matching start tag is found. It will correctly ignore signal
7
- * characters for empty tags, comments, CDATA, etc.
8
- *
9
- * The function depends on internal parser state to identify tags. It is compatible with the
10
- * following CodeMirror modes and will ignore all others:
11
- * - htmlmixed
12
- * - xml
13
- *
14
- * See demos/closetag.html for a usage example.
15
- *
16
- * @author Nathan Williams <nathan@nlwillia.net>
17
- * Contributed under the same license terms as CodeMirror.
18
- */
19
- (function() {
20
- /** Option that allows tag closing behavior to be toggled. Default is true. */
21
- CodeMirror.defaults['closeTagEnabled'] = true;
22
-
23
- /** Array of tag names to add indentation after the start tag for. Default is the list of block-level html tags. */
24
- CodeMirror.defaults['closeTagIndent'] = ['applet', 'blockquote', 'body', 'button', 'div', 'dl', 'fieldset', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', 'iframe', 'layer', 'legend', 'object', 'ol', 'p', 'select', 'table', 'ul'];
25
-
26
- /** Array of tag names where an end tag is forbidden. */
27
- CodeMirror.defaults['closeTagVoid'] = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
28
-
29
- function innerState(cm, state) {
30
- return CodeMirror.innerMode(cm.getMode(), state).state;
31
- }
32
-
33
-
34
- /**
35
- * Call during key processing to close tags. Handles the key event if the tag is closed, otherwise throws CodeMirror.Pass.
36
- * - cm: The editor instance.
37
- * - ch: The character being processed.
38
- * - indent: Optional. An array of tag names to indent when closing. Omit or pass true to use the default indentation tag list defined in the 'closeTagIndent' option.
39
- * Pass false to disable indentation. Pass an array to override the default list of tag names.
40
- * - vd: Optional. An array of tag names that should not be closed. Omit to use the default void (end tag forbidden) tag list defined in the 'closeTagVoid' option. Ignored in xml mode.
41
- */
42
- CodeMirror.defineExtension("closeTag", function(cm, ch, indent, vd) {
43
- if (!cm.getOption('closeTagEnabled')) {
44
- throw CodeMirror.Pass;
45
- }
46
-
47
- /*
48
- * Relevant structure of token:
49
- *
50
- * htmlmixed
51
- * className
52
- * state
53
- * htmlState
54
- * type
55
- * tagName
56
- * context
57
- * tagName
58
- * mode
59
- *
60
- * xml
61
- * className
62
- * state
63
- * tagName
64
- * type
65
- */
66
-
67
- var pos = cm.getCursor();
68
- var tok = cm.getTokenAt(pos);
69
- var state = innerState(cm, tok.state);
70
-
71
- if (state) {
72
-
73
- if (ch == '>') {
74
- var type = state.type;
75
-
76
- if (tok.className == 'tag' && type == 'closeTag') {
77
- throw CodeMirror.Pass; // Don't process the '>' at the end of an end-tag.
78
- }
79
-
80
- cm.replaceSelection('>'); // Mode state won't update until we finish the tag.
81
- pos = {line: pos.line, ch: pos.ch + 1};
82
- cm.setCursor(pos);
83
-
84
- tok = cm.getTokenAt(cm.getCursor());
85
- state = innerState(cm, tok.state);
86
- if (!state) throw CodeMirror.Pass;
87
- var type = state.type;
88
-
89
- if (tok.className == 'tag' && type != 'selfcloseTag') {
90
- var tagName = state.tagName;
91
- if (tagName.length > 0 && shouldClose(cm, vd, tagName)) {
92
- insertEndTag(cm, indent, pos, tagName);
93
- }
94
- return;
95
- }
96
-
97
- // Undo the '>' insert and allow cm to handle the key instead.
98
- cm.setSelection({line: pos.line, ch: pos.ch - 1}, pos);
99
- cm.replaceSelection("");
100
-
101
- } else if (ch == '/') {
102
- if (tok.className == 'tag' && tok.string == '<') {
103
- var ctx = state.context, tagName = ctx ? ctx.tagName : '';
104
- if (tagName.length > 0) {
105
- completeEndTag(cm, pos, tagName);
106
- return;
107
- }
108
- }
109
- }
110
-
111
- }
112
-
113
- throw CodeMirror.Pass; // Bubble if not handled
114
- });
115
-
116
- function insertEndTag(cm, indent, pos, tagName) {
117
- if (shouldIndent(cm, indent, tagName)) {
118
- cm.replaceSelection('\n\n</' + tagName + '>', 'end');
119
- cm.indentLine(pos.line + 1);
120
- cm.indentLine(pos.line + 2);
121
- cm.setCursor({line: pos.line + 1, ch: cm.getLine(pos.line + 1).length});
122
- } else {
123
- cm.replaceSelection('</' + tagName + '>');
124
- cm.setCursor(pos);
125
- }
126
- }
127
-
128
- function shouldIndent(cm, indent, tagName) {
129
- if (typeof indent == 'undefined' || indent == null || indent == true) {
130
- indent = cm.getOption('closeTagIndent');
131
- }
132
- if (!indent) {
133
- indent = [];
134
- }
135
- return indexOf(indent, tagName.toLowerCase()) != -1;
136
- }
137
-
138
- function shouldClose(cm, vd, tagName) {
139
- if (cm.getOption('mode') == 'xml') {
140
- return true; // always close xml tags
141
- }
142
- if (typeof vd == 'undefined' || vd == null) {
143
- vd = cm.getOption('closeTagVoid');
144
- }
145
- if (!vd) {
146
- vd = [];
147
- }
148
- return indexOf(vd, tagName.toLowerCase()) == -1;
149
- }
150
-
151
- // C&P from codemirror.js...would be nice if this were visible to utilities.
152
- function indexOf(collection, elt) {
153
- if (collection.indexOf) return collection.indexOf(elt);
154
- for (var i = 0, e = collection.length; i < e; ++i)
155
- if (collection[i] == elt) return i;
156
- return -1;
157
- }
158
-
159
- function completeEndTag(cm, pos, tagName) {
160
- cm.replaceSelection('/' + tagName + '>');
161
- cm.setCursor({line: pos.line, ch: pos.ch + tagName.length + 2 });
162
- }
163
-
164
- })();
1
+ /**
2
+ * Tag-closer extension for CodeMirror.
3
+ *
4
+ * This extension adds an "autoCloseTags" option that can be set to
5
+ * either true to get the default behavior, or an object to further
6
+ * configure its behavior.
7
+ *
8
+ * These are supported options:
9
+ *
10
+ * `whenClosing` (default true)
11
+ * Whether to autoclose when the '/' of a closing tag is typed.
12
+ * `whenOpening` (default true)
13
+ * Whether to autoclose the tag when the final '>' of an opening
14
+ * tag is typed.
15
+ * `dontCloseTags` (default is empty tags for HTML, none for XML)
16
+ * An array of tag names that should not be autoclosed.
17
+ * `indentTags` (default is block tags for HTML, none for XML)
18
+ * An array of tag names that should, when opened, cause a
19
+ * blank line to be added inside the tag, and the blank line and
20
+ * closing line to be indented.
21
+ *
22
+ * See demos/closetag.html for a usage example.
23
+ */
24
+
25
+ (function() {
26
+ CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
27
+ if (val && (old == CodeMirror.Init || !old)) {
28
+ var map = {name: "autoCloseTags"};
29
+ if (typeof val != "object" || val.whenClosing)
30
+ map["'/'"] = function(cm) { autoCloseTag(cm, '/'); };
31
+ if (typeof val != "object" || val.whenOpening)
32
+ map["'>'"] = function(cm) { autoCloseTag(cm, '>'); };
33
+ cm.addKeyMap(map);
34
+ } else if (!val && (old != CodeMirror.Init && old)) {
35
+ cm.removeKeyMap("autoCloseTags");
36
+ }
37
+ });
38
+
39
+ var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
40
+ "source", "track", "wbr"];
41
+ var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
42
+ "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
43
+
44
+ function autoCloseTag(cm, ch) {
45
+ var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
46
+ var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
47
+ if (inner.mode.name != "xml") throw CodeMirror.Pass;
48
+
49
+ var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
50
+ var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
51
+ var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
52
+
53
+ if (ch == ">" && state.tagName) {
54
+ var tagName = state.tagName;
55
+ if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
56
+ var lowerTagName = tagName.toLowerCase();
57
+ // Don't process the '>' at the end of an end-tag or self-closing tag
58
+ if (tok.type == "tag" && state.type == "closeTag" ||
59
+ /\/\s*$/.test(tok.string) ||
60
+ dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1)
61
+ throw CodeMirror.Pass;
62
+
63
+ var doIndent = indentTags && indexOf(indentTags, lowerTagName) > -1;
64
+ cm.replaceSelection(">" + (doIndent ? "\n\n" : "") + "</" + tagName + ">",
65
+ doIndent ? {line: pos.line + 1, ch: 0} : {line: pos.line, ch: pos.ch + 1});
66
+ if (doIndent) {
67
+ cm.indentLine(pos.line + 1);
68
+ cm.indentLine(pos.line + 2);
69
+ }
70
+ return;
71
+ } else if (ch == "/" && tok.type == "tag" && tok.string == "<") {
72
+ var tagName = state.context && state.context.tagName;
73
+ if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
74
+ return;
75
+ }
76
+ throw CodeMirror.Pass;
77
+ }
78
+
79
+ function indexOf(collection, elt) {
80
+ if (collection.indexOf) return collection.indexOf(elt);
81
+ for (var i = 0, e = collection.length; i < e; ++i)
82
+ if (collection[i] == elt) return i;
83
+ return -1;
84
+ }
85
+ })();
@@ -0,0 +1,29 @@
1
+ CodeMirror.colorize = (function() {
2
+
3
+ var isBlock = /^(p|li|div|h\\d|pre|blockquote|td)$/;
4
+
5
+ function textContent(node, out) {
6
+ if (node.nodeType == 3) return out.push(node.nodeValue);
7
+ for (var ch = node.firstChild; ch; ch = ch.nextSibling) {
8
+ textContent(ch, out);
9
+ if (isBlock.test(node.nodeType)) out.push("\n");
10
+ }
11
+ }
12
+
13
+ return function(collection, defaultMode) {
14
+ if (!collection) collection = document.body.getElementsByTagName("pre");
15
+
16
+ for (var i = 0; i < collection.length; ++i) {
17
+ var node = collection[i];
18
+ var mode = node.getAttribute("data-lang") || defaultMode;
19
+ if (!mode) continue;
20
+
21
+ var text = [];
22
+ textContent(node, text);
23
+ node.innerHTML = "";
24
+ CodeMirror.runMode(text.join(""), mode, node);
25
+
26
+ node.className += " cm-s-default";
27
+ }
28
+ };
29
+ })();
@@ -10,7 +10,7 @@
10
10
  var mode = CodeMirror.innerMode(cm.getMode(), token.state).mode;
11
11
  var space;
12
12
 
13
- if (token.className == "comment" && mode.blockCommentStart) {
13
+ if (token.type == "comment" && mode.blockCommentStart) {
14
14
  var end = token.string.indexOf(mode.blockCommentEnd);
15
15
  var full = cm.getRange({line: pos.line, ch: 0}, {line: pos.line, ch: token.end}), found;
16
16
  if (end != -1 && end == token.string.length - mode.blockCommentEnd.length) {
@@ -0,0 +1,28 @@
1
+ (function() {
2
+ CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
3
+ var pos = cm.getCursor(), token = cm.getTokenAt(pos);
4
+ var space;
5
+ if (token.className == "string") {
6
+ var full = cm.getRange({line: pos.line, ch: 0}, {line: pos.line, ch: token.end});
7
+ var listStart = /\*|\d+\./, listContinue;
8
+ if (token.string.search(listStart) == 0) {
9
+ var reg = /^[\W]*(\d+)\./g;
10
+ var matches = reg.exec(full);
11
+ if(matches)
12
+ listContinue = (parseInt(matches[1]) + 1) + ". ";
13
+ else
14
+ listContinue = "* ";
15
+ space = full.slice(0, token.start);
16
+ if (!/^\s*$/.test(space)) {
17
+ space = "";
18
+ for (var i = 0; i < token.start; ++i) space += " ";
19
+ }
20
+ }
21
+ }
22
+
23
+ if (space != null)
24
+ cm.replaceSelection("\n" + space + listContinue, "end");
25
+ else
26
+ cm.execCommand("newlineAndIndent");
27
+ };
28
+ })();
@@ -1,16 +1,21 @@
1
1
  // Open simple dialogs on top of an editor. Relies on dialog.css.
2
2
 
3
3
  (function() {
4
- function dialogDiv(cm, template) {
4
+ function dialogDiv(cm, template, bottom) {
5
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>';
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;
9
14
  return dialog;
10
15
  }
11
16
 
12
- CodeMirror.defineExtension("openDialog", function(template, callback) {
13
- var dialog = dialogDiv(this, template);
17
+ CodeMirror.defineExtension("openDialog", function(template, callback, options) {
18
+ var dialog = dialogDiv(this, template, options && options.bottom);
14
19
  var closed = false, me = this;
15
20
  function close() {
16
21
  if (closed) return;
@@ -19,7 +24,7 @@
19
24
  }
20
25
  var inp = dialog.getElementsByTagName("input")[0], button;
21
26
  if (inp) {
22
- CodeMirror.connect(inp, "keydown", function(e) {
27
+ CodeMirror.on(inp, "keydown", function(e) {
23
28
  if (e.keyCode == 13 || e.keyCode == 27) {
24
29
  CodeMirror.e_stop(e);
25
30
  close();
@@ -28,20 +33,20 @@
28
33
  }
29
34
  });
30
35
  inp.focus();
31
- CodeMirror.connect(inp, "blur", close);
36
+ CodeMirror.on(inp, "blur", close);
32
37
  } else if (button = dialog.getElementsByTagName("button")[0]) {
33
- CodeMirror.connect(button, "click", function() {
38
+ CodeMirror.on(button, "click", function() {
34
39
  close();
35
40
  me.focus();
36
41
  });
37
42
  button.focus();
38
- CodeMirror.connect(button, "blur", close);
43
+ CodeMirror.on(button, "blur", close);
39
44
  }
40
45
  return close;
41
46
  });
42
47
 
43
- CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
44
- var dialog = dialogDiv(this, template);
48
+ CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
49
+ var dialog = dialogDiv(this, template, options && options.bottom);
45
50
  var buttons = dialog.getElementsByTagName("button");
46
51
  var closed = false, me = this, blurring = 1;
47
52
  function close() {
@@ -54,17 +59,17 @@
54
59
  for (var i = 0; i < buttons.length; ++i) {
55
60
  var b = buttons[i];
56
61
  (function(callback) {
57
- CodeMirror.connect(b, "click", function(e) {
62
+ CodeMirror.on(b, "click", function(e) {
58
63
  CodeMirror.e_preventDefault(e);
59
64
  close();
60
65
  if (callback) callback(me);
61
66
  });
62
67
  })(callbacks[i]);
63
- CodeMirror.connect(b, "blur", function() {
68
+ CodeMirror.on(b, "blur", function() {
64
69
  --blurring;
65
70
  setTimeout(function() { if (blurring <= 0) close(); }, 200);
66
71
  });
67
- CodeMirror.connect(b, "focus", function() { ++blurring; });
72
+ CodeMirror.on(b, "focus", function() { ++blurring; });
68
73
  }
69
74
  });
70
- })();
75
+ })();