-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathindex.html
86 lines (76 loc) · 2.27 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Trix</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="csp-nonce" content="topsecret">
<link rel="icon" href="data:,">
<link rel="stylesheet" type="text/css" href="trix.css">
<style type="text/css">
* {
box-sizing: border-box;
}
main {
margin: 20px auto;
max-width: 700px;
}
trix-editor:invalid {
border: solid 1px red;
}
#output {
margin: 1rem 0 0;
}
#output textarea {
width: 100%;
height: 6rem;
resize: vertical;
font-family: monospace;
border-radius: 5px;
border: solid 1px #444;
padding: 10px;
}
</style>
<script type="module" src="trix.esm.js"></script>
<script type="module" src="inspector.js"></script>
<script type="module">
Trix.config.attachments.preview.caption.name = true
Trix.config.attachments.preview.caption.size = false
document.addEventListener("trix-initialize", function(event) {
Trix.Inspector.install(event.target);
});
document.addEventListener("trix-attachment-add", function(event) {
var attachment = event.attachment;
if (attachment.file) {
var xhr = new XMLHttpRequest;
xhr.open("POST", "/attachments", true);
xhr.upload.onprogress = function(event) {
var progress = event.loaded / event.total * 100;
attachment.setUploadProgress(progress);
};
xhr.onload = function() {
if (xhr.status === 201) {
setTimeout(function() {
var url = xhr.responseText;
attachment.setAttributes({ url: url, href: url });
}, 30)
}
};
attachment.setUploadProgress(10);
setTimeout(function() {
xhr.send(attachment.file);
}, 30)
}
});
</script>
</head>
<body>
<main>
<trix-editor autofocus class="trix-content" input="input"></trix-editor>
<details id="output">
<summary>Output</summary>
<textarea readonly id="input"></textarea>
</details>
</main>
</body>
</html>