-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml-preview-page.js
35 lines (30 loc) · 1004 Bytes
/
html-preview-page.js
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
(function() {
function init() {
var html = ko.observable().extend({ rateLimit: 500 });
var css = ko.observable().extend({ rateLimit: 500 });
var viewModel = {
updateHtml: ko.computed({
read: function() {},
write: function(t) { html(t); }
}),
updateCss: ko.computed({
read: function() {},
write: function(t) { css(t); }
})
};
ko.computed(function() {
var iframe = document.getElementsByTagName("iframe")[0];
var h = html();
if (h) {
iframe.contentDocument.body.innerHTML = h;
}
var c = css();
if (c) {
var style = iframe.contentDocument.getElementsByTagName("style")[0];
style.innerText = c;
}
});
ko.applyBindings(viewModel);
}
document.addEventListener("DOMContentLoaded", init);
})();