fix(dom): allow to correctly clone document fragments
This commit is contained in:
parent
307011a96c
commit
2351896cc0
|
@ -135,7 +135,7 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
};
|
};
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
preventDefault(evt) {
|
preventDefault(evt) {
|
||||||
evt.returnValue = false;
|
evt.returnValue = false;
|
||||||
}
|
}
|
||||||
getInnerHTML(el) {
|
getInnerHTML(el) {
|
||||||
|
@ -302,11 +302,18 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||||
throw _notImplemented('getDistributedNodes');
|
throw _notImplemented('getDistributedNodes');
|
||||||
}
|
}
|
||||||
clone(node) {
|
clone(node) {
|
||||||
var temp = treeAdapter.createElement("template", null, []);
|
// e.g. document fragment
|
||||||
treeAdapter.appendChild(temp, node);
|
if (node.type === 'root') {
|
||||||
var serialized = serializer.serialize(temp);
|
var serialized = serializer.serialize(node);
|
||||||
var newParser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
|
var newParser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
|
||||||
return newParser.parseFragment(serialized).childNodes[0];
|
return newParser.parseFragment(serialized);
|
||||||
|
} else {
|
||||||
|
var temp = treeAdapter.createElement("template", null, []);
|
||||||
|
treeAdapter.appendChild(temp, node);
|
||||||
|
var serialized = serializer.serialize(temp);
|
||||||
|
var newParser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
|
||||||
|
return newParser.parseFragment(serialized).childNodes[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hasProperty(element, name:string) {
|
hasProperty(element, name:string) {
|
||||||
return _HTMLElementPropertyList.indexOf(name) > -1;
|
return _HTMLElementPropertyList.indexOf(name) > -1;
|
||||||
|
|
Loading…
Reference in New Issue