const createPreviewIframeNode = function (editor: Editor, node: Node) { let previewWrapper; let previewNode; let shimNode; const name = node.name; previewWrapper = new Node('span', 1); previewWrapper.attr({ 'contentEditable': 'false', 'style': node.attr('style'), 'data-mce-object': name, 'class': 'mce-preview-object mce-object-' + name }); retainAttributesAndInnerHtml(editor, node, previewWrapper); previewNode = new Node(name, 1); previewNode.attr({ src: node.attr('src'), allowfullscreen: node.attr('allowfullscreen'), style: node.attr('style'), class: node.attr('class'), width: node.attr('width'), height: node.attr('height'), frameborder: '0' }); shimNode = new Node('span', 1); shimNode.attr('class', 'mce-shim'); previewWrapper.append(previewNode); previewWrapper.append(shimNode); return previewWrapper; };
const retainAttributesAndInnerHtml = function (editor: Editor, sourceNode: Node, targetNode: Node) { let attrName; let attrValue; let attribs; let ai; let innerHtml; // Prefix all attributes except width, height and style since we // will add these to the placeholder attribs = sourceNode.attributes; ai = attribs.length; while (ai--) { attrName = attribs[ai].name; attrValue = attribs[ai].value; if (attrName !== 'width' && attrName !== 'height' && attrName !== 'style') { if (attrName === 'data' || attrName === 'src') { attrValue = editor.convertURL(attrValue, attrName); } targetNode.attr('data-mce-p-' + attrName, attrValue); } } // Place the inner HTML contents inside an escaped attribute // This enables us to copy/paste the fake object innerHtml = sourceNode.firstChild && sourceNode.firstChild.value; if (innerHtml) { targetNode.attr('data-mce-html', escape(Sanitize.sanitize(editor, innerHtml))); targetNode.firstChild = null; } };
suite.test('clone', function () { let root, node, clone; node = new Node('#text', 3); node.value = 'value'; clone = node.clone(); LegacyUnit.equal(clone.name, '#text'); LegacyUnit.equal(clone.type, 3); LegacyUnit.equal(clone.value, 'value'); LegacyUnit.equal(clone.parent, undefined); LegacyUnit.equal(clone.next, undefined); LegacyUnit.equal(clone.prev, undefined); root = new Node('#frag', 11); node = new Node('#text', 3); node.value = 'value'; root.append(node); LegacyUnit.equal(clone.name, '#text'); LegacyUnit.equal(clone.type, 3); LegacyUnit.equal(clone.value, 'value'); LegacyUnit.equal(clone.parent, undefined); LegacyUnit.equal(clone.next, undefined); LegacyUnit.equal(clone.prev, undefined); node = new Node('b', 1); node.attr('id', 'id'); node.attr('class', 'class'); node.attr('title', 'title'); clone = node.clone(); LegacyUnit.equal(clone.name, 'b'); LegacyUnit.equal(clone.type, 1); LegacyUnit.deepEqual(clone.attributes, [{ name: 'class', value: 'class' }, { name: 'title', value: 'title' }]); LegacyUnit.deepEqual(clone.attributes.map, { class: 'class', title: 'title' }); });
Tools.each('keywords,description,author,copyright,robots'.split(','), function (name) { const nodes = headerFragment.getAll('meta'); let i, meta; const value = data[name]; for (i = 0; i < nodes.length; i++) { meta = nodes[i]; if (meta.attr('name') === name) { if (value) { meta.attr('content', value); } else { meta.remove(); } return; } } if (value) { elm = new Node('meta', 1); elm.attr('name', name); elm.attr('content', value); elm.shortEnded = true; addHeadNode(elm); } });
const isWithinEphoxEmbed = function (node: Node) { while ((node = node.parent)) { if (node.attr('data-ephox-embed-iri')) { return true; } } return false; };
const isWithinEmbedWrapper = function (node: Node) { while ((node = node.parent)) { if (node.attr('data-ephox-embed-iri') || isPageEmbedWrapper(node)) { return true; } } return false; };
const createPlaceholderNode = function (editor: Editor, node: Node) { let placeHolder; const name = node.name; placeHolder = new Node('img', 1); placeHolder.shortEnded = true; retainAttributesAndInnerHtml(editor, node, placeHolder); placeHolder.attr({ 'width': node.attr('width') || '300', 'height': node.attr('height') || (name === 'audio' ? '30' : '150'), 'style': node.attr('style'), 'src': Env.transparentSrc, 'data-mce-object': name, 'class': 'mce-object mce-object-' + name }); return placeHolder; };
const getFontTree = () => { const body = new Node('body', 1); const font = new Node('font', 1); const text = new Node('#text', 3); text.value = 'x'; font.attr('size', '7'); font.append(text); body.append(font); return body; };
Tools.each(data.stylesheets, function (stylesheet) { if (!currentStyleSheetsMap[stylesheet]) { elm = new Node('link', 1); elm.attr({ rel: 'stylesheet', text: 'text/css', href: stylesheet }); elm.shortEnded = true; addHeadNode(elm); } delete currentStyleSheetsMap[stylesheet]; });
function convertParagraphToLi(paragraphNode, listName, start?) { const level = paragraphNode._listLevel || lastLevel; // Handle list nesting if (level !== lastLevel) { if (level < lastLevel) { // Move to parent list if (currentListNode) { currentListNode = currentListNode.parent.parent; } } else { // Create new list prevListNode = currentListNode; currentListNode = null; } } if (!currentListNode || currentListNode.name !== listName) { prevListNode = prevListNode || currentListNode; currentListNode = new Node(listName, 1); if (start > 1) { currentListNode.attr('start', '' + start); } paragraphNode.wrap(currentListNode); } else { currentListNode.append(paragraphNode); } paragraphNode.name = 'li'; // Append list to previous list if it exists if (level > lastLevel && prevListNode) { prevListNode.lastChild.append(currentListNode); } lastLevel = level; // Remove start of list item "1. " or "· " etc removeIgnoredNodes(paragraphNode); trimListStart(paragraphNode, /^\u00a0+/); trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/); trimListStart(paragraphNode, /^\u00a0+/); }