X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=92fc1e03e0fbd11aa17c1105265a4af5496b7a87;hb=d415d52813ae2ee5c19bb2fd183de1f6158f6d13;hp=a8b6a27884f713ad810bb4cc2b516d9042c8a2a8;hpb=1cb701175ce0a92b96075574aed3005d52d5d047;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index a8b6a27..92fc1e0 100644 --- a/editor.coffee +++ b/editor.coffee @@ -19,6 +19,11 @@ overlay_padding = 10 timeout = (ms, cb) -> return setTimeout cb, ms +# xml 1.0 says: +valid_attr_regex = new RegExp '^[a-zA-Z_:][-a-zA-Z0-9_:.]*$' +# html5 spec is much more lax, but chromium won't let me make at attribute with the name "4" +js_attr_regex = new RegExp '^[oO][nN].' + debug_dot_at = (doc, x, y) -> return # disabled el = doc.createElement 'div' @@ -234,7 +239,8 @@ outer_css = (args) -> ret += '.ann_box {' ret += 'z-index: 5;' ret += 'position: absolute;' - ret += 'border: 1px solid rgba(0,0,0,.1);' + ret += 'border: 1px solid rgba(0,0,0,0.1);' + ret += 'outline: 1px solid rgba(255,255,255,0.1);' # in case there's a black background ret += '}' ret += '.ann_tag {' ret += 'z-index: 10;' @@ -295,11 +301,14 @@ instantiate_tree = (tree, parent) -> if c.name in ['script', 'object', 'iframe', 'link'] # TODO put placeholders instead remove.unshift i + continue # TODO create in correct namespace c.el = parent.ownerDocument.createElement c.name for k, v of c.attrs # FIXME if attr_whitelist[k]? - c.el.setAttribute k, v + if valid_attr_regex.test k + unless js_attr_regex.test k + c.el.setAttribute k, v parent.appendChild c.el if c.children.length instantiate_tree c.children, c.el @@ -785,7 +794,12 @@ class PeachHTML5Editor @overlay.appendChild @cursor_el @cursor_visible = true @cursor_el.style.left = "#{loc.x + overlay_padding - 1}px" - @cursor_el.style.top = "#{loc.y + overlay_padding}px" + if loc.h < 5 + height = 12 + else + height = loc.h + @cursor_el.style.top = "#{loc.y + overlay_padding + Math.round(height * .07)}px" + @cursor_el.style.height = "#{Math.round height * 0.82}px" @matt cursor[0] matt: (n) -> while @matting.length > 0