-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (79 loc) · 2.46 KB
/
index.js
File metadata and controls
89 lines (79 loc) · 2.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// We need to create a new iframe on every update, so that the JS state does not stick around. Example of a problem that would cause: When defining a variable in the top scope with "let", the second update fails.
function update()
{
if (document.querySelector('#layout').value === 'edit only') return;
let newIframe = document.createElement('iframe');
document.body.replaceChild(
newIframe,
document.querySelector('#resultframe'),
);
newIframe.id='resultframe';
let outty = newIframe.contentWindow.document;
outty.open();
let inny=document.getElementById("data");
outty.write(inny.value);
outty.close();
};
function goFullscreen()
{
let outWin = window.open()
outWin.focus();
let outty = outWin.document;
outty.open();
let inny = document.getElementById("data");
outty.write(inny.value);
outty.close();
}
function realtime()
{
if (!document.querySelector("#realtime").checked) return;
update();
}
function render() {
let outWin = window.open()
outWin.focus();
_render(outWin);
}
function clearData() {
document.querySelector('#data').value = '';
update();
}
function changeFontSize() {
var fontSizeInput = document.getElementById("fontSize");
var newSize = parseInt(fontSizeInput.value);
if(isNaN(newSize)) {
newSize = 14;
}
var textArea = document.getElementById("data");
textArea.style.fontSize = newSize + "px";
}
function printFrame() {
const iframe = document.getElementById('resultframe');
const iframeWindow = iframe.contentWindow;
iframeWindow.focus();
iframeWindow.print();
}
function updateLayout() {
let layout = document.querySelector('#layout').value;
if (layout === 'horizontal') {
document.body.classList.add("horizontal");
document.body.classList.remove("edit_only");
} else if (layout === 'edit only') {
document.body.classList.add("edit_only");
document.body.classList.remove("horizontal");
} else {
document.body.classList.remove("horizontal");
document.body.classList.remove("edit_only");
}
}
async function _render(outWin) {
let inny = document.querySelector("iframe").contentDocument.body;
let dataUrl = await domtoimage.toPng(inny);
let img = document.createElement('img');
img.src = dataUrl;
outWin.document.body.appendChild(img);
}
let dataArea = document.getElementById("data");
dataArea.onkeyup = realtime;
update();
changeFontSize();