Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Oct 5, 2016
1 parent 9375b6a commit 3980a6f
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions Resources/public/js/views/fields/ez-richtext-editview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
},

Expand Down

0 comments on commit 3980a6f

Please # to comment.