1 # Copyright 2015 Jason Woofenden
2 # This file implements an WYSIWYG editor in the browser (no contenteditable)
4 # This program is free software: you can redistribute it and/or modify it under
5 # the terms of the GNU Affero General Public License as published by the Free
6 # Software Foundation, either version 3 of the License, or (at your option) any
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 timeout = (ms, cb) -> return setTimeout cb, ms
22 if (window.requestAnimationFrame?)
23 window.requestAnimationFrame cb
27 # xml 1.0 spec, chromium and firefox accept these, plus lots of unicode chars
28 valid_attr_regex = new RegExp '^[a-zA-Z_:][-a-zA-Z0-9_:.]*$'
29 # html5 spec is much more lax, but chromium won't let me make at attribute with the name "4"
30 js_attr_regex = new RegExp '^[oO][nN].'
32 debug_dot_at = (doc, x, y) ->
34 el = doc.createElement 'div'
35 el.setAttribute 'style', "position: absolute; left: #{x}px; top: #{y}px; width: 1px; height: 3px; background-color: red"
36 doc.body.appendChild el
37 #console.log(new Error().stack)
39 # text nodes don't have getBoundingClientRect(), so use selection api to find
41 get_el_bounds = (el) ->
42 if el.getBoundingClientRect?
43 rect = el.getBoundingClientRect()
45 # text nodes don't have getBoundingClientRect(), so use range api
46 range = el.ownerDocument.createRange()
47 range.selectNodeContents el
48 rect = range.getBoundingClientRect()
49 doc = el.ownerDocument.documentElement
50 win = el.ownerDocument.defaultView
51 y_fix = win.pageYOffset - doc.clientTop
52 x_fix = win.pageXOffset - doc.clientLeft
56 w: rect.width ? (rect.right - rect.left)
57 h: rect.height ? (rect.top - rect.bottom)
60 is_display_block = (el) ->
62 return el.currentStyle.display is 'block'
64 return window.getComputedStyle(el, null).getPropertyValue('display') is 'block'
66 # Pass return value from dom event handlers to this.
67 # If they return false, this will addinionally stop propagation and default.
68 event_return = (e, bool) ->
75 # Warning: currently assumes you're asking about a single character
76 # Note: chromium returns multiple bounding rects for a space at a line-break
77 # Note: chromium's getBoundingClientRect() is broken (when zero-area client rects)
78 # Note: sometimes returns null (eg for whitespace that is not visible)
79 text_range_bounds = (el, start, end) ->
80 range = document.createRange()
81 range.setStart el, start
83 rects = range.getClientRects()
88 doc = el.ownerDocument.documentElement
89 win = el.ownerDocument.defaultView
90 y_fix = win.pageYOffset - doc.clientTop
91 x_fix = win.pageXOffset - doc.clientLeft
95 w: rect.width ? (rect.right - rect.left)
96 h: rect.height ? (rect.top - rect.bottom)
98 bounding: range.getBoundingClientRect()
101 # figure out the x/y coordinates of where the cursor should be if it's at
102 # position ``i`` within text node ``n``
103 # sometimes returns null (eg for whitespace that is not visible)
104 window.cursor_to_xyh = cursor_to_xyh = (n, i) ->
105 range = document.createRange()
106 if n.text.length is 0
107 ret = text_range_bounds n.el, 0, 0
108 else if i is n.text.length
109 ret = text_range_bounds n.el, i - 1, i
113 ret = text_range_bounds n.el, i, i + 1
115 debug_dot_at n.el.ownerDocument, ret.x, ret.y
118 # encode text so it can be safely placed inside an html attribute
119 enc_attr_regex = new RegExp '(&)|(")|(\u00A0)', 'g'
121 return txt.replace enc_attr_regex, (match, amp, quote) ->
122 return '&' if (amp)
123 return '"' if (quote)
125 enc_text_regex = new RegExp '(&)|(<)|(\u00A0)', 'g'
127 return txt.replace enc_text_regex, (match, amp, lt) ->
128 return '&' if (amp)
129 return '<' if (lt)
149 # TODO make these always pretty-print (on the inside) like blocks
150 no_text_elements = { # these elements never contain text
160 domify = (doc, hash) ->
161 for tag, attrs of hash
163 return document.createTextNode attrs
164 el = document.createElement tag
173 outer_css = (args) ->
176 inner_padding = args.inner_padding ? overlay_padding
177 frame_width = args.frame_width ? inner_padding
178 # TODO editor controls height...
179 occupy = (left, top = left, right = left, bottom = top) ->
182 return Math.max(left, top, right, bottom)
189 ret += "border: #{occupy 1}px solid black;"
190 ret += "padding: #{occupy frame_width}px;"
193 ret += "border: #{occupy 1}px solid black;"
194 ret += "padding: #{occupy inner_padding}px;"
195 ret += "padding-right: #{inner_padding + occupy 0, 0, 15, 0}px;" # for scroll bar
196 ret += "width: #{w}px;"
197 ret += "height: #{h}px;"
198 ret += 'overflow-x: hidden;'
199 ret += 'overflow-y: scroll;'
202 ret += 'position: relative;'
203 ret += "width: #{w}px;"
204 ret += "min-height: #{h}px;"
207 ret += 'box-sizing: border-box;'
209 ret += 'border: none;'
211 ret += "width: #{w}px;"
212 #ret += "height: #{h}px;" # height auto-set when content set/changed
213 ret += '-ms-user-select: none;'
214 ret += '-webkit-user-select: none;'
215 ret += '-moz-user-select: none;'
216 ret += 'user-select: none;'
219 ret += 'position: absolute;'
220 ret += "left: -#{inner_padding}px;"
221 ret += "top: -#{inner_padding}px;"
222 ret += "right: -#{inner_padding}px;"
223 ret += "bottom: -#{inner_padding}px;"
224 ret += 'overflow: hidden;'
227 ret += 'position: absolute;'
228 ret += 'background: rgba(100,100,100,0.2);'
231 ret += 'position: absolute;'
232 ret += 'height: 1em;' # FIXME adjust for hight of text
234 ret += 'background: #444;'
235 ret += '-webkit-animation: blink 1s steps(2, start) infinite;'
236 ret += 'animation: blink 1s steps(2, start) infinite;'
238 ret += '@-webkit-keyframes blink {'
239 ret += 'to { visibility: hidden; }'
241 ret += '@keyframes blink {'
242 ret += 'to { visibility: hidden; }'
246 ret += 'position: absolute;'
247 ret += 'border: 1px solid rgba(0,0,0,0.1);'
248 ret += 'outline: 1px solid rgba(255,255,255,0.1);' # in case there's a black background
251 ret += 'z-index: 10;'
252 ret += 'position: absolute;'
253 ret += 'font-size: 8px;'
254 ret += 'white-space: pre;'
255 ret += 'background: rgba(255,255,255,0.4);'
256 ret += '-ms-user-select: none;'
257 ret += '-webkit-user-select: none;'
258 ret += '-moz-user-select: none;'
259 ret += 'user-select: none;'
266 '20': true # capslock
268 '144': true # numlock
270 '91': true # windows "start" key
271 # key codes: (valid on keydown, not keypress)
276 KEY_BACKSPACE = 8 # <--
277 KEY_DELETE = 46 # -->
286 control_key_codes = # we react to these, but they aren't typing
302 instantiate_tree = (tree, parent) ->
307 c.el = parent.ownerDocument.createTextNode c.text
308 parent.appendChild c.el
310 if c.name in ['script', 'object', 'iframe', 'link']
311 # TODO put placeholders instead
314 # TODO create in correct namespace
315 c.el = parent.ownerDocument.createElement c.name
317 # FIXME if attr_whitelist[k]?
318 if valid_attr_regex.test k
319 unless js_attr_regex.test k
320 c.el.setAttribute k, v
321 parent.appendChild c.el
323 instantiate_tree c.children, c.el
327 traverse_tree = (tree, cb) ->
333 done = traverse_tree c.children, cb
337 find_next_cursor_position = (tree, n, i) ->
338 if n.type is 'text' and n.text.length > i
339 orig_xyh = cursor_to_xyh n, i
341 console.log "ERROR: couldn't find xy for current cursor location"
343 for next_i in [i+1 .. n.text.length] # inclusive is valid (after last char)
344 next_xyh = cursor_to_xyh n, next_i
346 if next_xyh.x > orig_xyh.x or next_xyh.y > orig_xyh.y
350 traverse_tree tree, (node, state) ->
351 if node.type is 'text' and state_before is false
352 if cursor_to_xyh(node, 0)?
362 find_prev_cursor_position = (tree, n, i) ->
363 if n? and n.type is 'text' and i > 0
364 orig_xyh = cursor_to_xyh n, i
366 console.log "ERROR: couldn't find xy for current cursor location"
368 for prev_i in [i-1 .. 0]
369 prev_xyh = cursor_to_xyh n, prev_i
371 if prev_xyh.x < orig_xyh.x or prev_xyh.y < orig_xyh.y
376 traverse_tree tree, (node) ->
377 if node.type is 'text'
385 if cursor_to_xyh found, found.text.length # text visible?
386 return [found, found.text.length]
387 return find_prev_cursor_position tree, found, 0
390 find_loc_cursor_position = (tree, loc) ->
392 if c.type is 'tag' or c.type is 'text'
393 bounds = get_el_bounds c.el
394 continue if loc.x < bounds.x
395 continue if loc.x > bounds.x + bounds.w
396 continue if loc.y < bounds.y
397 continue if loc.y > bounds.y + bounds.h
399 ret = find_loc_cursor_position c.children, loc
402 # click is within bounding box that contains all text.
403 return [c, 0] if c.text.length is 0
405 before = cursor_to_xyh c, before_i
407 console.log "error: failed to find cursor pixel location for start of", c
409 after_i = c.text.length
410 after = cursor_to_xyh c, after_i
412 console.log "error: failed to find cursor pixel location for end of", c
414 if loc.y < before.y + before.h and loc.x < before.x
415 # console.log 'before first char on first line'
417 if loc.y > after.y and loc.x > after.x
418 # console.log 'after last char on last line'
421 console.log "Warning: click in bounding box but above first line"
422 continue # above first line (runaround?)
423 if loc.y > after.y + after.h
424 console.log "Warning: click in bounding box but below last line", loc.y, after.y, after.h
425 continue # below last line (shouldn't happen?)
426 while after_i - before_i > 1
427 cur_i = Math.round((before_i + after_i) / 2)
428 cur = cursor_to_xyh c, cur_i
430 console.log "error: failed to find cursor pixel location for", c, cur_i
432 if loc.y < cur.y or (loc.y <= cur.y + cur.h and loc.x < cur.x)
438 # which one is closest?
439 if Math.abs(before.x - loc.x) < Math.abs(after.x - loc.x)
445 # browsers collapse these (html5 spec calls these "space characters")
446 is_space_code = (char_code) ->
448 when 9, 10, 12, 13, 32
452 return is_space_code chr.charCodeAt 0
454 tree_remove_empty_text_nodes = (tree) ->
456 traverse_tree tree, (n) ->
458 if n.text.length is 0
462 # don't completely empty the tree
464 if tree[0].type is 'text'
465 console.log "oop, leaving a blank node because it's the only thing"
467 n.el.parentNode.removeChild n.el
468 for c, i in n.parent.children
470 n.parent.children.splice i, 1
473 # pass a array of nodes (from parser library, ie it should have .el and .text)
474 tree_dedup_space = (tree) ->
475 prev = cur = next = null
476 prev_i = cur_i = next_i = 0
477 prev_pos = pos = next_pos = null
478 prev_px = cur_px = next_px = null
482 tree_remove_empty_text_nodes(tree)
484 iterate = (tree, cb) ->
488 while i < n.text.length # don't foreach, cb might remove chars
493 block = is_display_block n.el
496 if n.children.length > 0
497 iterate n.children, cb
502 removed_char = cur.text.charAt(cur_i)
503 cur.el.textContent = cur.text = (cur.text.substr 0, cur_i) + (cur.text.substr cur_i + 1)
504 if next is cur # in same text node
506 throw "how is this possible?"
511 cur.el.textContent = cur.text = (cur.text.substr 0, cur_i) + removed_char + (cur.text.substr cur_i)
512 if next is cur # in same text node
515 # return true if cur was removed from the dom (ie re-use same prev)
517 # cur definitately set
518 # prev and/or next might be null, indicating the start/end of a display:block
519 return false unless is_space_code cur.text.charCodeAt cur_i
520 bounds = text_range_bounds cur.el, cur_i, cur_i + 1
522 # 1. zero rects returned by getClientRects() means collapsed space
525 # 2. width greater than zero means visible space
528 # now the weird edge cases...
530 # firefox and chromium both report zero width for characters at the end
531 # of a line where the text wraps (automatically, due to word-wrap) to
532 # the next line. These do not appear to be distinguishable from
533 # collapsed spaces via the range/bounds api, so...
535 # remove it from the dom, and if prev or next moves, put it back.
536 if prev? and not prev_px?
537 prev_px = cursor_to_xyh prev, prev_i
538 if next? and not next_px?
539 next_px = cursor_to_xyh next, next_i
540 #if prev is null and next is null
541 # parent_px = cur.parent.el.getBoundingClientRect()
545 new_prev_px = cursor_to_xyh prev, prev_i
546 if new_prev_px.x isnt prev_px.x or new_prev_px.y isnt prev_px.y
549 console.log "this shouldn't happen, we remove spaces that don't locate"
552 new_next_px = cursor_to_xyh next, next_i
553 if new_next_px.x isnt next_px.x or new_next_px.y isnt next_px.y
556 # console.log "removing space becase space after it is collapsed"
558 # pass null at start/end of display:block
566 # don't advance (to the next character next time) if we removed a
567 # character from the same text node as ``next``, because doing so
568 # renumbers the indexes in that string
569 if removed and cur is next
585 tree_remove_empty_text_nodes(tree)
587 class PeachHTML5Editor
588 # Options: (all optional)
589 # editor_id: "id" attribute for outer-most element created by/for editor
590 # on_init: callback for when the editable content is in place
591 constructor: (in_el, options) ->
592 @options = options ? {}
596 @inited = false # when iframes have loaded
597 @outer_iframe # iframe to hold editor
598 @outer_idoc # "document" object for @outer_iframe
599 @wrap2 = null # scrollbar is on this
600 @iframe = null # iframe to hold editable content
601 @idoc = null # "document" object for @iframe
604 @cursor_visible = false
605 @poll_for_blur_timeout = null
606 @iframe_offset = null
607 opt_fragment = @options.fragment ? true
610 @parser_opts.fragment = 'body'
612 @outer_iframe = domify document, iframe: {}
613 outer_iframe_style = 'border: none !important; margin: 0 !important; padding: 0 !important; height: 100% !important; width: 100% !important;'
614 if @options.editor_id?
615 @outer_iframe.setAttribute 'id', @options.editor_id
616 @outer_iframe.onload = =>
617 @outer_idoc = @outer_iframe.contentDocument
618 icss = domify @outer_idoc, style: children: [
619 domify @outer_idoc, text: css
621 @outer_idoc.head.appendChild icss
622 @iframe = domify @outer_idoc, iframe: {}
625 setTimeout (=> @init() unless @inited), 200 # firefox never fires this onload
626 @outer_idoc.body.appendChild(
627 domify @outer_idoc, div: id: 'wrap1', children: [
628 @wrap2 = domify @outer_idoc, div: id: 'wrap2', children: [
629 domify @outer_idoc, div: id: 'wrap3', children: [
631 @overlay = domify @outer_idoc, div: id: 'overlay'
636 outer_wrap = domify document, div: class: 'peach_html5_editor'
637 @in_el.parentNode.appendChild outer_wrap
638 outer_bounds = get_el_bounds outer_wrap
639 if outer_bounds.w < 300
641 if outer_bounds.h < 300
643 outer_iframe_style += "width: #{outer_bounds.w}px; height: #{outer_bounds.h}px;"
644 @outer_iframe.setAttribute 'style', outer_iframe_style
645 css = outer_css w: outer_bounds.w, h: outer_bounds.h
646 outer_wrap.appendChild @outer_iframe
647 init: -> # called by @iframe's onload (or timeout on firefox)
648 @idoc = @iframe.contentDocument
649 @overlay.onclick = (e) =>
651 return event_return e, @onclick e
652 @overlay.ondoubleclick = (e) =>
654 return event_return e, @ondoubleclick e
655 @outer_idoc.body.onkeyup = (e) =>
657 return event_return e, @onkeyup e
658 @outer_idoc.body.onkeydown = (e) =>
660 return event_return e, @onkeydown e
661 @outer_idoc.body.onkeypress = (e) =>
663 return event_return e, @onkeypress e
664 if @options.stylesheet
666 @idoc.head.appendChild domify @idoc, style: src: @options.stylesheet
667 @load_html @in_el.value
671 overlay_event_to_inner_xy: (e) ->
672 unless @iframe_offset?
673 @iframe_offset = get_el_bounds @iframe
674 x = e.pageX # TODO ?cross-browserify
675 y = e.pageY + @wrap2.scrollTop # TODO ?cross-browserify
676 # TODO adjust for scrolling
677 return x: x - @iframe_offset.x, y: y - @iframe_offset.y
679 xy = @overlay_event_to_inner_xy e
680 new_cursor = find_loc_cursor_position @tree, xy
682 @move_cursor new_cursor
686 ondoubleclick: (e) ->
690 return false if ignore_key_codes[e.keyCode]?
691 #return false if control_key_codes[e.keyCode]?
694 return false if ignore_key_codes[e.keyCode]?
695 #return false if control_key_codes[e.keyCode]?
699 new_cursor = find_prev_cursor_position @tree, @cursor...
701 @move_cursor new_cursor
704 new_cursor = find_next_cursor_position @tree, c, -1
706 @move_cursor new_cursor
713 new_cursor = find_next_cursor_position @tree, @cursor...
715 @move_cursor new_cursor
718 new_cursor = find_prev_cursor_position @tree, c, -1
720 @move_cursor new_cursor
728 return false unless @cursor?
729 return false unless @cursor[1] > 0
730 @cursor[0].text = @cursor[0].text.substr(0, @cursor[1] - 1) + @cursor[0].text.substr(@cursor[1])
731 @cursor[0].el.nodeValue = @cursor[0].text
732 @move_cursor [@cursor[0], @cursor[1] - 1]
736 return false unless @cursor?
737 return false unless @cursor[1] < @cursor[0].text.length
738 @cursor[0].text = @cursor[0].text.substr(0, @cursor[1]) + @cursor[0].text.substr(@cursor[1] + 1)
739 @cursor[0].el.nodeValue = @cursor[0].text
740 @move_cursor [@cursor[0], @cursor[1]]
759 return false if ignore_key_codes[e.keyCode]?
760 # return false if control_key_codes[e.keyCode]? # handled in keydown
761 char = e.charCode ? e.keyCode
763 char = String.fromCharCode char
765 @cursor[0].text = char + @cursor[0].text
766 else if @cursor[1] is @cursor[0].text.length - 1
767 @cursor[0].text += char
770 @cursor[0].text.substr(0, @cursor[1]) +
772 @cursor[0].text.substr(@cursor[1])
773 @cursor[0].el.nodeValue = @cursor[0].text
774 @move_cursor [@cursor[0], @cursor[1] + 1]
777 clear_dom: -> # remove all the editable content (and cursor, overlays, etc)
778 while @idoc.body.childNodes.length
779 @idoc.body.removeChild @idoc.body.childNodes[0]
783 @tree = peach_parser.parse html, @parser_opts
785 instantiate_tree @tree, @idoc.body
786 tree_dedup_space @tree
789 @in_el.onchange = null
790 @in_el.value = @pretty_html @tree
792 @load_html @in_el.value
793 @iframe.style.height = "0"
794 @iframe.style.height = "#{@idoc.body.scrollHeight}px"
795 kill_cursor: -> # remove it, forget where it was
797 @cursor_el.parentNode.removeChild @cursor_el
798 @cursor_visible = false
801 move_cursor: (cursor) ->
802 loc = cursor_to_xyh cursor[0], cursor[1]
804 console.log "error: tried to move cursor to position that has no pixel location", cursor[0], cursor[1]
807 # replace cursor element, to reset blink animation
809 @cursor_el.parentNode.removeChild @cursor_el
810 @cursor_el = domify @outer_idoc, div: id: 'cursor'
811 @overlay.appendChild @cursor_el
812 @cursor_visible = true
813 @cursor_el.style.left = "#{loc.x + overlay_padding - 1}px"
818 @cursor_el.style.top = "#{loc.y + overlay_padding + Math.round(height * .07)}px"
819 @cursor_el.style.height = "#{Math.round height * 0.82}px"
822 while @matting.length > 0
823 @overlay.removeChild @matting[0]
826 prev_bounds = x: 0, y: 0, w: 0, h: 0
832 bounds = get_el_bounds n.el
833 return unless bounds?
834 if bounds.x is prev_bounds.x and bounds.y is prev_bounds.y and bounds.w is prev_bounds.w and bounds.h is prev_bounds.h
837 matt = domify @outer_idoc, div: class: 'ann_box', style: "left: #{bounds.x - 1 + overlay_padding}px; top: #{bounds.y - 2 + overlay_padding}px; width: #{bounds.w}px; height: #{bounds.h}px" # outline: 1000px solid rgba(0,153,255,#{alpha});
838 @overlay.appendChild matt
840 ann = domify @outer_idoc, div: class: 'ann_tag', style: "left: #{bounds.x + 1 + overlay_padding}px; top: #{bounds.y - 7 + overlay_padding}px", children: [domify @outer_idoc, text: " #{n.name} "]
841 @overlay.appendChild ann
845 pretty_html: (tree, indent = '', parent_flags = pre_ish: false, block: true, want_nl: false) ->
847 want_nl = parent_flags.want_nl
848 prev_in_flow_is_text = false
849 prev_in_flow_is_block = false
852 inner_flags = want_nl: true
859 if n.el.currentStyle?
860 cs = n.el.currentStyle
861 whitespace = cs['white-space']
862 display = cs['display']
863 position = cs['position']
865 visibility = cs['visibility']
867 cs = @iframe.contentWindow.getComputedStyle(n.el, null)
868 whitespace = cs.getPropertyValue 'white-space'
869 display = cs.getPropertyValue 'display'
870 position = cs.getPropertyValue 'position'
871 float = cs.getPropertyValue 'float'
872 visibility = cs.getPropertyValue 'visibility'
873 if n.name is 'textarea'
874 inner_flags.pre_ish = true
876 inner_flags.pre_ish = whitespace.substr(0, 3) is 'pre'
882 when 'absolute', 'fixed'
885 if 'display' is 'none'
889 when 'hidden', 'collapse'
894 when 'inline', 'none'
895 inner_flags.block = false
896 is_block = in_flow_block = false
898 inner_flags.block = true
899 is_block = in_flow_block = false
900 else # block, table, etc
901 inner_flags.block = true
903 in_flow_block = in_flow
908 in_flow_block = false
909 else # 'comment', 'doctype'
913 in_flow_block = false
914 # print whitespace if we can
915 unless parent_flags.pre_ish
916 unless prev_in_flow_is_text and is_br
917 if (i is 0 and parent_flags.block) or in_flow_block or prev_in_flow_is_block
930 if n.attrs[k].length > 0
931 ret += "=\"#{enc_attr n.attrs[k]}\""
933 unless void_elements[n.name]?
935 next_indent = indent + ' '
939 ret += @pretty_html n.children, next_indent, inner_flags
940 ret += "</#{n.name}>"
942 ret += enc_text n.text
944 ret += "<!--#{n.text}-->" # TODO encode?
946 ret += "<!DOCTYPE #{n.name}"
947 if n.public_identifier? and n.public_identifier.length > 0
948 ret += " \"#{n.public_identifier}\""
949 if n.system_identifier? and n.system_identifier.length > 0
950 ret += " \"#{n.system_identifier}\""
954 prev_in_flow_is_text = is_text
955 prev_in_flow_is_block = is_block or (in_flow and is_br)
957 # output final newline if allowed
958 unless parent_flags.pre_ish
959 if prev_in_flow_is_block or parent_flags.block
960 ret += "\n#{indent.substr 4}"
965 @editor_is_focused = true
968 return if @poll_for_blur_timeout? # already polling
969 @poll_for_blur_timeout = timeout 150, =>
970 next_frame => # pause polling when browser knows we're not active/visible/etc.
971 @poll_for_blur_timeout = null
972 if document.activeElement is @outer_iframe
975 @editor_is_focused = false
978 window.peach_html5_editor = (args...) ->
979 return new PeachHTML5Editor args...
981 # test in browser: peach_html5_editor(document.getElementsByTagName('textarea')[0])