本文整理匯總了TypeScript中@ephox/dom-globals.Element.cloneNode方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Element.cloneNode方法的具體用法?TypeScript Element.cloneNode怎麽用?TypeScript Element.cloneNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/dom-globals.Element
的用法示例。
在下文中一共展示了Element.cloneNode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
const preProcess = function (editor: Editor, node: Element, args) {
let impl, doc, oldDoc;
const dom = editor.dom;
node = node.cloneNode(true) as Element;
// Nodes needs to be attached to something in WebKit/Opera
// This fix will make DOM ranges and make Sizzle happy!
impl = document.implementation;
if (impl.createHTMLDocument) {
// Create an empty HTML document
doc = impl.createHTMLDocument('');
// Add the element or it's children if it's a body element to the new document
Tools.each(node.nodeName === 'BODY' ? node.childNodes : [node], function (node) {
doc.body.appendChild(doc.importNode(node, true));
});
// Grab first child or body element for serialization
if (node.nodeName !== 'BODY') {
node = doc.body.firstChild;
} else {
node = doc.body;
}
// set the new document in DOMUtils so createElement etc works
oldDoc = dom.doc;
dom.doc = doc;
}
Events.firePreProcess(editor, Merger.merge(args, { node }));
if (oldDoc) {
dom.doc = oldDoc;
}
return node;
};