From 8709cb94761099e91b480781b64323b169130d3a Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Mon, 25 Jan 2016 17:14:11 -0500 Subject: [PATCH] preview in iframe, load_html method --- editor.coffee | 14 ++++++++++++-- editor_tests.coffee | 10 +++++++--- editor_tests_coffee.html | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/editor.coffee b/editor.coffee index f4b7845..4805550 100644 --- a/editor.coffee +++ b/editor.coffee @@ -76,8 +76,18 @@ wysiwyg = (el, options = {}) -> parser_opts = {} if opt_fragment parser_opts.fragment = 'body' - editor_instance = dom: wheic_parser.parse(el.value, parser_opts) - # el.value = dom_to_html dom + editor_instance = { + dom: wheic_parser.parse el.value, parser_opts + iframe: document.createElement('iframe') + load_html: (html) -> + @dom = wheic_parser.parse el.value, parser_opts + } + idoc = editor_instance.iframe.contentDocument + if options.stylesheet # TODO test this + istyle = idoc.createElement 'style' + istyle.setAttribute 'src', options.stylesheet + idoc.head.appendChild istyle + el.parentNode.appendChild editor_instance.iframe return editor_instance window.wheic = { diff --git a/editor_tests.coffee b/editor_tests.coffee index 4b995bb..5777244 100644 --- a/editor_tests.coffee +++ b/editor_tests.coffee @@ -1,9 +1,13 @@ in_el = document.getElementById 'in' out_el = document.getElementById 'out' button = document.getElementById 'button' -button.onclick = -> - editor = wheic.wysiwyg in_el - out_el.value = wheic.dom_to_html editor.dom +editor = null +button.onclick = in_el.onchange = in_el.onkeyup = -> + if editor? + editor.load_html in_el + else + editor = wheic.wysiwyg in_el + editor.iframe.contentDocument.body.innerHTML = out_el.value = wheic.dom_to_html editor.dom return false button.value="Cleanup" button.removeAttribute 'disabled' diff --git a/editor_tests_coffee.html b/editor_tests_coffee.html index b1c00fc..25bb3fc 100644 --- a/editor_tests_coffee.html +++ b/editor_tests_coffee.html @@ -17,7 +17,7 @@

In:

-

Out:

+

Cleaned Up:

-- 1.7.10.4