|
@@ -1,8 +1,28 @@
|
1
|
|
-document.querySelector('[data-generate-button]').addEventListener('click',
|
2
|
|
- function (e) {
|
|
1
|
+document
|
|
2
|
+ .querySelector('[data-generate-button]')
|
|
3
|
+ .addEventListener('click', function(e) {
|
3
|
4
|
var r = confirm('Are you sure? This will overwrite any existing content.');
|
4
|
5
|
if (!r) {
|
5
|
6
|
e.preventDefault();
|
6
|
7
|
}
|
|
8
|
+ });
|
|
9
|
+
|
|
10
|
+var iframe = document.querySelector('iframe');
|
|
11
|
+var contentTextArea = document.querySelector('#content[name=content]');
|
|
12
|
+if (iframe && contentTextArea) {
|
|
13
|
+ var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
|
14
|
+ var styleNode = document.createElement('style');
|
|
15
|
+ styleNode.innerText = 'body { margin: 0; }';
|
|
16
|
+ iframeDocument.head.appendChild(styleNode);
|
|
17
|
+ var preview = iframeDocument.querySelector('body');
|
|
18
|
+ if (preview) {
|
|
19
|
+ var timeout;
|
|
20
|
+ preview.innerHTML = marked(contentTextArea.value);
|
|
21
|
+ contentTextArea.addEventListener('input', function(e) {
|
|
22
|
+ clearTimeout(timeout);
|
|
23
|
+ timeout = setTimeout(function() {
|
|
24
|
+ preview.innerHTML = marked(e.target.value);
|
|
25
|
+ }, 500);
|
|
26
|
+ });
|
7
|
27
|
}
|
8
|
|
-);
|
|
28
|
+}
|