From 3980a6fa2cf4cdbbfaeb71470d75747171657746 Mon Sep 17 00:00:00 2001 From: Damien Pobel Date: Wed, 5 Oct 2016 16:16:46 +0200 Subject: [PATCH] WIP --- .../js/views/fields/ez-richtext-editview.js | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Resources/public/js/views/fields/ez-richtext-editview.js b/Resources/public/js/views/fields/ez-richtext-editview.js index b234f2175..39c3b6575 100644 --- a/Resources/public/js/views/fields/ez-richtext-editview.js +++ b/Resources/public/js/views/fields/ez-richtext-editview.js @@ -266,10 +266,33 @@ YUI.add('ez-richtext-editview', function (Y) { * @return {DocumentFragment} */ _getHTMLDocumentFragment: function () { - var fragment = Y.config.doc.createDocumentFragment(), - root = Y.config.doc.createElement('div'), + var fragment = Y.config.doc.implementation.createHTMLDocument().createDocumentFragment(), + root = fragment.ownerDocument.createElement('div'), doc = (new DOMParser()).parseFromString(this.get('field').fieldValue.xhtml5edit, "text/xml"), - i; + importChildNodes = function (parent, element, skipElement) { + var i, newElement; + + if ( skipElement ) { + newElement = parent; + } else { + if ( element.nodeType === Node.ELEMENT_NODE ) { + newElement = parent.ownerDocument.createElement(element.localName); + for (i = 0; i != element.attributes.length; i++) { + importChildNodes(newElement, element.attributes[i], false); + } + parent.appendChild(newElement); + } else if ( element.nodeType === Node.TEXT_NODE ) { + parent.appendChild(parent.ownerDocument.createTextNode(element.nodeValue)); + } else if ( element.nodeType === Node.ATTRIBUTE_NODE ) { + parent.setAttribute(element.localName, element.value); + } else { + return; + } + } + for (i = 0; i != element.childNodes.length; i++) { + importChildNodes(newElement, element.childNodes[i], false); + } + }; if ( !doc || !doc.documentElement || doc.querySelector("parsererror") ) { console.warn( @@ -279,9 +302,8 @@ YUI.add('ez-richtext-editview', function (Y) { } fragment.appendChild(root); - for (i = 0; i != doc.documentElement.childNodes.length; i++) { - root.appendChild(doc.documentElement.childNodes.item(i).cloneNode(true)); - } + + importChildNodes(root, doc.documentElement, true); return fragment; },