JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
preview in iframe, load_html method
authorJason Woofenden <jason@jasonwoof.com>
Mon, 25 Jan 2016 22:14:11 +0000 (17:14 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 25 Jan 2016 22:14:11 +0000 (17:14 -0500)
editor.coffee
editor_tests.coffee
editor_tests_coffee.html

index f4b7845..4805550 100644 (file)
@@ -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 = {
index 4b995bb..5777244 100644 (file)
@@ -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'
index b1c00fc..25bb3fc 100644 (file)
@@ -17,7 +17,7 @@
        <form action="#" method="get">
        <p>In:<br><textarea rows="9" cols="22" name="in" id="in">&lt;p&gt;Normal &lt;strong&gt;Bold &lt;em&gt; Italic+Bold&lt;/strong&gt; Italic&lt;/em&gt; Normal&lt;/p&gt;</textarea></p>
        <p><input id="button" type="submit" value="loading..." disabled></p>
-       <p>Out:<br><textarea rows="9" cols="22" name="out" id="out" readonly></textarea></p>
+       <p>Cleaned Up:<br><textarea rows="9" cols="22" name="out" id="out" readonly></textarea></p>
                
        </form>
        <script src="parser.coffee" type="text/coffeescript"></script>