-
Notifications
You must be signed in to change notification settings - Fork 831
Expand file tree
/
Copy patheditable.js
More file actions
36 lines (30 loc) · 899 Bytes
/
editable.js
File metadata and controls
36 lines (30 loc) · 899 Bytes
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
var element = document.getElementById("example-element");
var input = document.getElementById("input");
var editor = document.getElementById("editor");
var editorContent = document.getElementById("editor-content");
var reset = document.getElementById("reset");
var cmOptions = {
mode: "css",
theme: "eclipse",
lineNumbers: true,
showCursorWhenSelecting: true
}
var cmEditor = CodeMirror.fromTextArea(editorContent, cmOptions);
cmEditor.setSize("100%", 50);
cmEditor.focus();
cmEditor.doc.setCursor({line:0, pos: -1});
function applyCode() {
element.style.cssText = cmEditor.doc.getValue();
}
reset.addEventListener("click", function() {
cmEditor.doc.setValue(cmInitContent);
applyCode();
reset.classList.add("hidden");
});
cmEditor.on("change", function() {
reset.classList.remove("hidden");
applyCode();
});
window.addEventListener("load", function() {
applyCode();
});