+ editor_instance = {
+ dom: []
+ iframe: document.createElement('iframe')
+ load_html: (html) ->
+ @dom = peach_parser.parse html, parser_opts
+ as_html = peach.dom_to_html @dom
+ as_html = as_html.substr(0, 5) + '<span class="peach_editor_cursor"></span>' + as_html.substr(5)
+ @iframe.contentDocument.body.innerHTML = as_html
+ }
+ el.parentNode.appendChild editor_instance.iframe
+ idoc = editor_instance.iframe.contentDocument
+ ignore_key_codes =
+ '18': true # alt
+ '20': true # capslock
+ '17': true # ctrl
+ '144': true # numlock
+ '16': true # shift
+ '91': true # windows "start" key
+ control_key_codes = # we react to these, but they aren't typing
+ '37': KEY_LEFT
+ '38': KEY_UP
+ '39': KEY_RIGHT
+ '40': KEY_DOWN
+ '35': KEY_END
+ '8': KEY_BACKSPACE
+ '46': KEY_DELETE
+ '13': KEY_ENTER
+ '27': KEY_ESCAPE
+ '36': KEY_HOME
+ '45': KEY_INSERT
+ '33': KEY_PAGE_UP
+ '34': KEY_PAGE_DOWN
+ '9': KEY_TAB
+
+ idoc.body.onkeyup = (e) ->
+ return false if ignore_key_codes[e.keyCode]?
+ return false if control_key_codes[e.keyCode]?
+ idoc.body.onkeydown = (e) ->
+ return false if ignore_key_codes[e.keyCode]?
+ return false if control_key_codes[e.keyCode]?
+ idoc.body.onkeypress = (e) ->
+ return if e.ctrlKey
+ return false if ignore_key_codes[e.keyCode]?
+ # in firefox, keyCode is only set for non-typing keys
+ if e.keyCode isnt KEY_BACKSPACE # so this is fine
+ return false if control_key_codes[e.keyCode]?
+ char = e.charCode ? e.keyCode
+ el.value += String.fromCharCode char
+ editor_instance.load_html el.value
+ return false
+ if options.stylesheet # TODO test this
+ istyle = idoc.createElement 'style'
+ istyle.setAttribute 'src', options.stylesheet
+ idoc.head.appendChild istyle
+ icss = idoc.createElement 'style'
+ icss.appendChild idoc.createTextNode css
+ idoc.head.appendChild icss
+ editor_instance.load_html el.value