-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandtext.js
More file actions
70 lines (55 loc) · 1.67 KB
/
Copy pathsandtext.js
File metadata and controls
70 lines (55 loc) · 1.67 KB
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
//CODEMIRROR
//CARET FINDER
/*CODEMIRROR START*/
var delay;
var editor = CodeMirror.fromTextArea(document.getElementById('myTextarea'), {
lineNumbers: true,
autofocus: true,
mode: 'text/html',
autoCloseTags: true,
lineWrapping: true,
matchTags: { bothTags: true },
matchBrackets: true,
lineWiseCopyCut: false,
autoCloseBrackets: true
});
//timeout delay
editor.on("change", function () {
let onInputButton = document.getElementById('onInputButton');
if (onInputButton.checked) {
//reload_message_frame(); //<-- enable to clear javascript in cache, though it gives a flashing update if used to quickly
clearTimeout(delay);
delay = setTimeout(updatePreview, 1);
}
});
//update preview
function updatePreview() {
var previewFrame = document.getElementById('myIframe');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
preview.write(editor.getValue());
preview.close();
}
setTimeout(updatePreview, 1);
/*CODEMIRROR END*/
document.addEventListener('keydown', function (ev) {
if ((ev.ctrlKey === true || ev.metaKey === true) && ev.key === 'Enter') {
ev.preventDefault();
updatePreview();
}
})
/*CARET FINDER START*/
function insertStringInTemplate(str) {
// If there's a selection, replace the selection.
if (editor.somethingSelected()) {
editor.replaceSelection(str);
return;
}
// Otherwise, we insert at the cursor position.
var cursor = editor.getCursor();
editor.replaceRange(str, cursor);
}
/*CARET FINDER END*/
/*INLET START*/
var inlet = Inlet(editor);
/*INLET END*/