-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMNotepad.html
executable file
·457 lines (452 loc) · 19.6 KB
/
CMNotepad.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<html>
<head>
<title>CodeMirror Notepad app</title>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.css"
type="text/css"
/>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.js"
type="text/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/localStorage/2.0.1/localStorage.min.js"
type="text/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/mode/loadmode.min.js"
type="text/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/mode/meta.min.js"
type="text/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/addon/display/placeholder.min.js"
type="text/javascript"
></script>
<style type="text/css">
html,
body {
background: #fcfcfc;
color: #444;
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
overflow: hidden;
position: relative;
}
#notepad {
height: 100%;
width: 100%;
padding: 1%;
font-size: 100%;
line-height: 125%;
font-family: san-serif;
box-sizing: border-box;
}
.CodeMirror {
height: 100vh;
width: 100vw;
}
::selection {
background: #7d7;
}
::-moz-selection {
background: #7d7;
}
#config {
background: #111;
color: #ccc;
font-family: sans-serif;
margin:1rem;
padding:1rem;
}
label {
display: block;
padding: 0.5rem;
}
label[for="settings"] {
position: absolute;
padding: 0;
top: 0.5em;
right: 0.5em;
z-index: 9999;
}
#settings {
position:absolute;
left: -9999px;
}
#settings ~ #config {
display: none;
z-index: -1111;
}
#settings:checked ~ #config {
display:inline-block;
position: absolute;
top: 0;
right: 0;
z-index: 8888;
}
#save {
display: inline-block;
position: absolute;
top: 0;
right: 2rem;
border: none;
background: transparent;
}
</style>
</head>
<body>
<input type="checkbox" id="settings" name="settings">
<label for="settings"><img src="http://icons.iconarchive.com/icons/google/noto-emoji-objects/16/62971-gear-icon.png" alt="settings"/></label>
<a id="save"><img src="http://icons.iconarchive.com/icons/wefunction/woofunction/32/save-download-icon.png" alt="save" /></a>
<form id="config">
<label>Theme
<select id="theme">
<option value="default">none</option>
<option value="3024-day">3024 day</option>
<option value="3024-night">3024 night</option>
<option value="abcdef">Abcdef</option>
<option value="ambiance-mobile">Ambiance mobile</option>
<option value="ambiance">Ambiance</option>
<option value="base16-dark">Base16 dark</option>
<option value="base16-light">Base16 light</option>
<option value="bespin">Bespin</option>
<option value="blackboard">Blackboard</option>
<option value="cobalt">Cobalt</option>
<option value="colorforth">Colorforth</option>
<option value="darcula">Darcula</option>
<option value="dracula">Dracula</option>
<option value="duotone-dark">Duotone dark</option>
<option value="duotone-light">Duotone light</option>
<option value="eclipse">Eclipse</option>
<option value="elegant">Elegant</option>
<option value="erlang-dark">Erlang dark</option>
<option value="gruvbox-dark">Gruvbox dark</option>
<option value="hopscotch">Hopscotch</option>
<option value="icecoder">Icecoder</option>
<option value="idea">Idea</option>
<option value="isotope">Isotope</option>
<option value="lesser-dark">Lesser dark</option>
<option value="liquibyte">Liquibyte</option>
<option value="lucario">Lucario</option>
<option value="material">Material</option>
<option value="mbo">Mbo</option>
<option value="mdn-like">Mdn like</option>
<option value="midnight">Midnight</option>
<option value="monokai">Monokai</option>
<option value="neat">Neat</option>
<option value="neo">Neo</option>
<option value="night">Night</option>
<option value="nord">Nord</option>
<option value="oceanic-next">Oceanic next</option>
<option value="panda-syntax">Panda syntax</option>
<option value="paraiso-dark">Paraiso dark</option>
<option value="paraiso-light">Paraiso light</option>
<option value="pastel-on-dark">Pastel on dark</option>
<option value="railscasts">Railscasts</option>
<option value="rubyblue">Rubyblue</option>
<option value="seti">Seti</option>
<option value="shadowfox">Shadowfox</option>
<option value="solarized">Solarized</option>
<option value="ssms">Ssms</option>
<option value="the-matrix">The matrix</option>
<option value="tomorrow-night-bright">Tomorrow night bright</option>
<option value="tomorrow-night-eighties">Tomorrow night eighties</option>
<option value="ttcn">Ttcn</option>
<option value="twilight">Twilight</option>
<option value="vibrant-ink">Vibrant ink</option>
<option value="xq-dark">Xq dark</option>
<option value="xq-light">Xq light</option>
<option value="yeti">Yeti</option>
<option value="yonce">Yonce</option>
<option value="zenburn">Zenburn</option>
</select>
</label>
<label>Mode
<select id="mode">
<option value="text/plain">Plain Text</option>
<option value="text/apl">APL</option>
<option value="undefined">PGP</option>
<option value="text/x-ttcn-asn">ASN.1</option>
<option value="text/x-asterisk">Asterisk</option>
<option value="text/x-brainfuck">Brainfuck</option>
<option value="text/x-csrc">C</option>
<option value="text/x-c++src">C++</option>
<option value="text/x-cobol">Cobol</option>
<option value="text/x-csharp">C#</option>
<option value="text/x-clojure">Clojure</option>
<option value="text/x-clojurescript">ClojureScript</option>
<option value="text/x-gss">Closure Stylesheets (GSS)</option>
<option value="text/x-cmake">CMake</option>
<option value="undefined">CoffeeScript</option>
<option value="text/x-common-lisp">Common Lisp</option>
<option value="application/x-cypher-query">Cypher</option>
<option value="text/x-cython">Cython</option>
<option value="text/x-crystal">Crystal</option>
<option value="text/css">CSS</option>
<option value="text/x-cassandra">CQL</option>
<option value="text/x-d">D</option>
<option value="undefined">Dart</option>
<option value="text/x-diff">diff</option>
<option value="text/x-django">Django</option>
<option value="text/x-dockerfile">Dockerfile</option>
<option value="application/xml-dtd">DTD</option>
<option value="text/x-dylan">Dylan</option>
<option value="text/x-ebnf">EBNF</option>
<option value="text/x-ecl">ECL</option>
<option value="application/edn">edn</option>
<option value="text/x-eiffel">Eiffel</option>
<option value="text/x-elm">Elm</option>
<option value="application/x-ejs">Embedded Javascript</option>
<option value="application/x-erb">Embedded Ruby</option>
<option value="text/x-erlang">Erlang</option>
<option value="text/x-esper">Esper</option>
<option value="text/x-factor">Factor</option>
<option value="text/x-fcl">FCL</option>
<option value="text/x-forth">Forth</option>
<option value="text/x-fortran">Fortran</option>
<option value="text/x-fsharp">F#</option>
<option value="text/x-gas">Gas</option>
<option value="text/x-feature">Gherkin</option>
<option value="text/x-gfm">GitHub Flavored Markdown</option>
<option value="text/x-go">Go</option>
<option value="text/x-groovy">Groovy</option>
<option value="text/x-haml">HAML</option>
<option value="text/x-haskell">Haskell</option>
<option value="text/x-literate-haskell">Haskell (Literate)</option>
<option value="text/x-haxe">Haxe</option>
<option value="text/x-hxml">HXML</option>
<option value="application/x-aspx">ASP.NET</option>
<option value="text/html">HTML</option>
<option value="message/http">HTTP</option>
<option value="text/x-idl">IDL</option>
<option value="text/x-pug">Pug</option>
<option value="text/x-java">Java</option>
<option value="application/x-jsp">Java Server Pages</option>
<option value="undefined">JavaScript</option>
<option value="undefined">JSON</option>
<option value="application/ld+json">JSON-LD</option>
<option value="text/jsx">JSX</option>
<option value="text/jinja2">Jinja2</option>
<option value="text/x-julia">Julia</option>
<option value="text/x-kotlin">Kotlin</option>
<option value="text/x-less">LESS</option>
<option value="text/x-livescript">LiveScript</option>
<option value="text/x-lua">Lua</option>
<option value="text/x-markdown">Markdown</option>
<option value="text/mirc">mIRC</option>
<option value="text/x-mariadb">MariaDB SQL</option>
<option value="text/x-mathematica">Mathematica</option>
<option value="text/x-modelica">Modelica</option>
<option value="text/x-mumps">MUMPS</option>
<option value="text/x-mssql">MS SQL</option>
<option value="application/mbox">mbox</option>
<option value="text/x-mysql">MySQL</option>
<option value="text/x-nginx-conf">Nginx</option>
<option value="text/x-nsis">NSIS</option>
<option value="undefined">NTriples</option>
<option value="text/x-objectivec">Objective-C</option>
<option value="text/x-ocaml">OCaml</option>
<option value="text/x-octave">Octave</option>
<option value="text/x-oz">Oz</option>
<option value="text/x-pascal">Pascal</option>
<option value="null">PEG.js</option>
<option value="text/x-perl">Perl</option>
<option value="undefined">PHP</option>
<option value="text/x-pig">Pig</option>
<option value="text/x-plsql">PLSQL</option>
<option value="text/x-pgsql">PostgreSQL</option>
<option value="application/x-powershell">PowerShell</option>
<option value="text/x-properties">Properties files</option>
<option value="text/x-protobuf">ProtoBuf</option>
<option value="text/x-python">Python</option>
<option value="text/x-puppet">Puppet</option>
<option value="text/x-q">Q</option>
<option value="text/x-rsrc">R</option>
<option value="text/x-rst">reStructuredText</option>
<option value="text/x-rpm-changes">RPM Changes</option>
<option value="text/x-rpm-spec">RPM Spec</option>
<option value="text/x-ruby">Ruby</option>
<option value="text/x-rustsrc">Rust</option>
<option value="text/x-sas">SAS</option>
<option value="text/x-sass">Sass</option>
<option value="text/x-scala">Scala</option>
<option value="text/x-scheme">Scheme</option>
<option value="text/x-scss">SCSS</option>
<option value="undefined">Shell</option>
<option value="application/sieve">Sieve</option>
<option value="undefined">Slim</option>
<option value="text/x-stsrc">Smalltalk</option>
<option value="text/x-smarty">Smarty</option>
<option value="text/x-solr">Solr</option>
<option value="text/x-sml">SML</option>
<option value="text/x-soy">Soy</option>
<option value="application/sparql-query">SPARQL</option>
<option value="text/x-spreadsheet">Spreadsheet</option>
<option value="text/x-sql">SQL</option>
<option value="text/x-sqlite">SQLite</option>
<option value="text/x-squirrel">Squirrel</option>
<option value="text/x-styl">Stylus</option>
<option value="text/x-swift">Swift</option>
<option value="text/x-stex">sTeX</option>
<option value="text/x-latex">LaTeX</option>
<option value="text/x-systemverilog">SystemVerilog</option>
<option value="text/x-tcl">Tcl</option>
<option value="text/x-textile">Textile</option>
<option value="text/x-tiddlywiki">TiddlyWiki </option>
<option value="text/tiki">Tiki wiki</option>
<option value="text/x-toml">TOML</option>
<option value="text/x-tornado">Tornado</option>
<option value="text/troff">troff</option>
<option value="text/x-ttcn">TTCN</option>
<option value="text/x-ttcn-cfg">TTCN_CFG</option>
<option value="text/turtle">Turtle</option>
<option value="application/typescript">TypeScript</option>
<option value="text/typescript-jsx">TypeScript-JSX</option>
<option value="text/x-twig">Twig</option>
<option value="text/x-webidl">Web IDL</option>
<option value="text/x-vb">VB.NET</option>
<option value="text/vbscript">VBScript</option>
<option value="text/velocity">Velocity</option>
<option value="text/x-verilog">Verilog</option>
<option value="text/x-vhdl">VHDL</option>
<option value="undefined">Vue.js Component</option>
<option value="undefined">XML</option>
<option value="application/xquery">XQuery</option>
<option value="text/x-yacas">Yacas</option>
<option value="undefined">YAML</option>
<option value="text/x-z80">Z80</option>
<option value="text/x-mscgen">mscgen</option>
<option value="text/x-xu">xu</option>
<option value="text/x-msgenny">msgenny</option>
</select>
</label>
<label>Keymap
<select id="keyMap">
<option>none</option>
<option value="emacs">Emacs</option>
<option value="vim">Vim</option>
<option value="sublime">Sublime</option>
</select>
</label>
<label>Line numbers
<input type="checkbox" id="lineNumbers"/>
</label>
<input type="submit" value="save">
</form>
<script type="text/javascript">
/* initialize CodeMirror */
var CM = CodeMirror(document.body, {
value: localStorage.getItem("CMNotepad") || "Type it here, see it here.",
autofocus: true,
placeholder: "Type it here, see it here. Check out settings over there =>",
viewportMargin: Infinity
});
/* handle settings */
document.getElementById("config").addEventListener("submit", function (event) {
event.preventDefault();
// loop through everything in this form
let configOptions =
[].slice.call(event.target).map(function(data) { // create a 2d array of key/value pairs
if (data.id) {
if (data.type === "checkbox") {
return [data.id, data.checked];
} else {
return [data.id, data.value];
}
} else {
return null;
}
}).filter(function (data) { return data !== null }); // remove null(s)
console.log(configOptions);
// save options
localStorage.setItem("CMNotepadOptions", JSON.stringify(configOptions));
// apply options
setCMOptions(configOptions);
// hide form
document.getElementById("settings").checked = false;
return false;
});
/* themes */
function setTheme(theme) {
// clear previous theme
var oldLink = document.getElementById(theme);
if (oldLink) {
oldLink.parentNode.removeChild(oldLink);
}
// apply theme
var link = document.createElement('link');
link.onload = function(){
CM.setOption("theme", theme);
};
link.rel = "stylesheet";
link.media = "all";
link.id = theme;
link.href = "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/theme/"+theme+".css";
document.getElementsByTagName('head')[0].appendChild(link);
}
/* keymaps */
function setKeymap(keymap) {
// clear previous keymap
var oldscript = document.getElementById(keymap);
if (oldscript) {
oldscript.parentNode.removeChild(oldscript);
}
// apply keymap
var script = document.createElement('script');
script.onload = function(){
CM.setOption("keyMap", keymap);
};
script.id = keymap;
script.src = "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.48.4/keymap/"+keymap+".min.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
/* apply & load settings */
function setCMOptions (opts) {
if (opts) {
opts.forEach(function(opt) {
if (opt[0] === "theme") {
setTheme(opt[1]);
} else if (opt[0] === "keyMap") {
setKeymap(opt[1]);
} else if (opt[0] === "mode") {
CodeMirror.autoLoadMode(CM, CodeMirror.findModeByMIME(opt[1] || "text/plain"));
} else {
CM.setOption(opt[0], opt[1]);
}
var el = document.getElementById(opt[0]);
if (el.type == "checkbox") {
el.checked = opt[1];
} else {
el.value = opt[1];
}
});
}
}
setCMOptions(JSON.parse(localStorage.getItem("CMNotepadOptions")));
/* save */
var saveFile = function(evt){
var mode = CM.findModeByMIME(CM.getMode());
var file = new Blob(CM.getValue(), { type: mode.mime });
evt.target.href = URL.createObjectURL(file);
evt.target.download = "CMnotepad." + (mode.ext[mode.ext.length - 1] || "txt");
}
document.getElementById("save").addEventListener("click", saveFile);
var save = function() {
localStorage.setItem("CMNotepad", CM.getValue());
};
/* autosave onchange and when you close the window */
CM.on("change", save);
window.onunload = save();
</script>
</body>
</html>