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 = {
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'
<form action="#" method="get">
<p>In:<br><textarea rows="9" cols="22" name="in" id="in"><p>Normal <strong>Bold <em> Italic+Bold</strong> Italic</em> Normal</p></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>