X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=blobdiff_plain;f=editor.js;h=f3c620432efe3c70b07a5f5aeba0f1aab572a1ab;hp=72e850670bc2b307ba81629cd02634ce1710556d;hb=HEAD;hpb=4ec99c39c0180df2d6380cb11c86b6e5f13292cf diff --git a/editor.js b/editor.js index 72e8506..f3c6204 100644 --- a/editor.js +++ b/editor.js @@ -121,11 +121,10 @@ get_el_bounds = window.bounds = function(el) { } function is_display_block (el) { - if (el.currentStyle != null) { - return el.currentStyle.display === 'block' - } else { + if (el.nodeType === 1) { return window.getComputedStyle(el, null).getPropertyValue('display') === 'block' } + return false } // Pass return value from dom event handlers to this. @@ -428,12 +427,19 @@ function instantiate_tree (tree, parent) { break case 'tag': if (c.name === 'script' || c.name === 'object' || c.name === 'iframe' || c.name === 'link') { - // TODO put placeholders instead - remove.unshift(i) // add to beginning so they are removed last first + // TODO make some placeholders visible + // problematic to have different type than c: c.el = parent.ownerDocument.createComment(c.name + ' tag here') + c.el = parent.ownerDocument.createElement(c.name) + // correct type, but empty and no attributes continue } - // TODO create in correct namespace - c.el = parent.ownerDocument.createElement(c.name) + if (c.namespace === 'svg') { + c.el = parent.ownerDocument.createElementNS('http://www.w3.org/2000/svg', c.name) + } else if (c.namespace === 'mathml') { + c.el = parent.ownerDocument.createElementNS('http://www.w3.org/1998/Math/MathML', c.name) + } else { + c.el = parent.ownerDocument.createElement(c.name) + } ref1 = c.attrs for (k in ref1) { v = ref1[k] @@ -450,11 +456,6 @@ function instantiate_tree (tree, parent) { } } } - // these are in reverse order so we remove highest indexes first - for (i = 0; i < remove.length; i++) { - index = remove[i] - tree.splice(index, 1) - } } function traverse_tree (tree, cb) { @@ -1861,7 +1862,7 @@ PeachHTML5Editor.prototype.collapse_whitespace = function(tree) { if (block) { cb(null) } - if (n.children.length > 0) { + if (n.children.length > 0 && plaintext_elements[n.name] == null) { iterate(n.children, cb) } if (block) { @@ -2366,21 +2367,12 @@ PeachHTML5Editor.prototype.pretty_html = function(tree, indent, parent_flags) { is_br = true } is_text = false - if (n.el.currentStyle != null) { - cs = n.el.currentStyle - whitespace = cs['white-space'] - display = cs['display'] - position = cs['position'] - float = cs['float'] - visibility = cs['visibility'] - } else { - cs = this.iframe.contentWindow.getComputedStyle(n.el, null) - whitespace = cs.getPropertyValue('white-space') - display = cs.getPropertyValue('display') - position = cs.getPropertyValue('position') - float = cs.getPropertyValue('float') - visibility = cs.getPropertyValue('visibility') - } + cs = this.iframe.contentWindow.getComputedStyle(n.el, null) + whitespace = cs.getPropertyValue('white-space') + display = cs.getPropertyValue('display') + position = cs.getPropertyValue('position') + float = cs.getPropertyValue('float') + visibility = cs.getPropertyValue('visibility') if (n.name === 'textarea') { inner_flags.pre_ish = true } else {