|
1 | 1 | // object for editor state |
2 | 2 | var editor = { |
3 | | - changed: false, |
4 | | - submit_clicked: false, |
| 3 | + changed: false, |
| 4 | + submit_clicked: false, |
5 | 5 | }; |
6 | 6 |
|
7 | | -if (silicon_editor === 'codemirror') { |
8 | | - var cm_instance; |
| 7 | +if (silicon_editor === "codemirror") { |
| 8 | + var cm_instance; |
9 | 9 | } |
10 | 10 |
|
11 | 11 | function usurp_unload(e) { |
12 | | - e.preventDefault(); |
13 | | - e.returnValue = ''; |
| 12 | + e.preventDefault(); |
| 13 | + e.returnValue = ""; |
14 | 14 | } |
15 | 15 |
|
16 | | -window.addEventListener("load", function() { |
17 | | - // load CodeMirror instance |
18 | | - if (silicon_editor === 'codemirror') { |
19 | | - require.config({ |
20 | | - baseUrl: js_modules_root |
21 | | - }); |
22 | | - |
23 | | - require([ |
24 | | - "lib/codemirror", |
25 | | - "mode/markdown/markdown", |
26 | | - "mode/clike/clike", |
27 | | - "mode/css/css", |
28 | | - "mode/diff/diff", |
29 | | - "mode/dockerfile/dockerfile", |
30 | | - "mode/gfm/gfm", |
31 | | - "mode/htmlmixed/htmlmixed", |
32 | | - "mode/jinja2/jinja2", |
33 | | - "mode/python/python", |
34 | | - "mode/shell/shell", |
35 | | - "mode/sql/sql", |
36 | | - "mode/yaml/yaml", |
37 | | - "addon/display/fullscreen", |
38 | | - "addon/display/panel", |
39 | | - ].map(x => `codemirror/${x}`), function(CodeMirror) { |
40 | | - cm_instance = CodeMirror.fromTextArea(document.querySelector('#body-text'), { |
41 | | - mode: { |
42 | | - name: 'gfm', |
43 | | - gitHubSpice: false, |
44 | | - }, |
45 | | - lineSeparator: '\n', |
46 | | - lineWrapping: true, |
47 | | - extraKeys: { |
48 | | - // home/end shouldn't go to the beginning/end of paragraphs |
49 | | - Home: 'goLineLeft', |
50 | | - End: 'goLineRight', |
51 | | - // do not redefine the browser history navigation keys |
52 | | - 'Alt-Left': false, |
53 | | - 'Alt-Right': false |
54 | | - }, |
55 | | - autofocus: true, |
56 | | - // appears to do nothing |
57 | | - spellcheck: true, |
58 | | - viewportMargin: Infinity, |
59 | | - }); |
60 | | - }); |
61 | | - } |
| 16 | +window.addEventListener("load", function () { |
| 17 | + // load CodeMirror instance |
| 18 | + if (silicon_editor === "codemirror") { |
| 19 | + require.config({ |
| 20 | + baseUrl: js_modules_root, |
| 21 | + }); |
62 | 22 |
|
63 | | - // mark the editor as changed if there is an alert shown |
64 | | - // (implies there was an error saving) |
65 | | - if (document.querySelector('#alerts') !== null) { |
66 | | - editor.changed = true; |
67 | | - }; |
| 23 | + require([ |
| 24 | + "lib/codemirror", |
| 25 | + "mode/markdown/markdown", |
| 26 | + "mode/clike/clike", |
| 27 | + "mode/css/css", |
| 28 | + "mode/diff/diff", |
| 29 | + "mode/dockerfile/dockerfile", |
| 30 | + "mode/gfm/gfm", |
| 31 | + "mode/htmlmixed/htmlmixed", |
| 32 | + "mode/jinja2/jinja2", |
| 33 | + "mode/python/python", |
| 34 | + "mode/shell/shell", |
| 35 | + "mode/sql/sql", |
| 36 | + "mode/yaml/yaml", |
| 37 | + "addon/display/fullscreen", |
| 38 | + "addon/display/panel", |
| 39 | + ].map((x) => `codemirror/${x}`), function (CodeMirror) { |
| 40 | + cm_instance = CodeMirror.fromTextArea( |
| 41 | + document.querySelector("#body-text"), |
| 42 | + { |
| 43 | + mode: { |
| 44 | + name: "gfm", |
| 45 | + gitHubSpice: false, |
| 46 | + }, |
| 47 | + lineSeparator: "\n", |
| 48 | + lineWrapping: true, |
| 49 | + extraKeys: { |
| 50 | + // home/end shouldn't go to the beginning/end of paragraphs |
| 51 | + Home: "goLineLeft", |
| 52 | + End: "goLineRight", |
| 53 | + // do not redefine the browser history navigation keys |
| 54 | + "Alt-Left": false, |
| 55 | + "Alt-Right": false, |
| 56 | + }, |
| 57 | + autofocus: true, |
| 58 | + // appears to do nothing |
| 59 | + spellcheck: true, |
| 60 | + viewportMargin: Infinity, |
| 61 | + } |
| 62 | + ); |
| 63 | + }); |
| 64 | + } |
68 | 65 |
|
69 | | - // mark the editor as changed if the textarea has changed |
70 | | - document.querySelector('#body-text') |
71 | | - .addEventListener('input', (event) => editor.changed = true); |
| 66 | + // mark the editor as changed if there is an alert shown |
| 67 | + // (implies there was an error saving) |
| 68 | + if (document.querySelector("#alerts") !== null) { |
| 69 | + editor.changed = true; |
| 70 | + } |
72 | 71 |
|
73 | | - // don't nag if the Submit button was clicked |
74 | | - document.querySelector('#page-form').onsubmit = function() { |
75 | | - editor.submit_clicked = true; |
76 | | - }; |
| 72 | + // mark the editor as changed if the textarea has changed |
| 73 | + document |
| 74 | + .querySelector("#body-text") |
| 75 | + .addEventListener("input", (event) => (editor.changed = true)); |
77 | 76 |
|
78 | | - window.addEventListener('beforeunload', function (e) { |
79 | | - if (silicon_editor === 'codemirror') { |
80 | | - // alert on changed codemirror |
81 | | - if ((! cm_instance.isClean() && ! editor.submit_clicked)) { |
82 | | - usurp_unload(e); |
83 | | - } |
84 | | - } else { |
85 | | - // alert on changed textarea |
86 | | - if ((editor.changed && ! editor.submit_clicked)) { |
87 | | - usurp_unload(e); |
88 | | - }; |
89 | | - } |
90 | | - }); |
| 77 | + // don't nag if the Submit button was clicked |
| 78 | + document.querySelector("#page-form").onsubmit = function () { |
| 79 | + editor.submit_clicked = true; |
| 80 | + }; |
91 | 81 |
|
| 82 | + window.addEventListener("beforeunload", function (e) { |
| 83 | + if (silicon_editor === "codemirror") { |
| 84 | + // alert on changed codemirror |
| 85 | + if (!cm_instance.isClean() && !editor.submit_clicked) { |
| 86 | + usurp_unload(e); |
| 87 | + } |
| 88 | + } else { |
| 89 | + // alert on changed textarea |
| 90 | + if (editor.changed && !editor.submit_clicked) { |
| 91 | + usurp_unload(e); |
| 92 | + } |
| 93 | + } |
| 94 | + }); |
92 | 95 | }); |
0 commit comments