refactor(core): remove testing-only DOM manipulation utils from DomAdapters (#32291)
PR Close #32291
This commit is contained in:

committed by
Miško Hevery

parent
ede5786d1e
commit
30dabdf8fc
@ -95,7 +95,7 @@ export function dispatchEvent(element: any, eventType: any): void {
|
||||
}
|
||||
|
||||
export function el(html: string): HTMLElement {
|
||||
return <HTMLElement>getDOM().firstChild(getContent(getDOM().createTemplate(html)));
|
||||
return <HTMLElement>getDOM().firstChild(getContent(createTemplate(html)));
|
||||
}
|
||||
|
||||
export function normalizeCSS(css: string): string {
|
||||
@ -160,7 +160,7 @@ export function stringifyElement(el: any /** TODO #9100 */): string {
|
||||
} else if (isCommentNode(el)) {
|
||||
result += `<!--${el.nodeValue}-->`;
|
||||
} else {
|
||||
result += getDOM().getText(el);
|
||||
result += el.textContent;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -212,3 +212,18 @@ export function hasClass(element: any, className: string): boolean {
|
||||
export function sortedClassList(element: any): any[] {
|
||||
return Array.prototype.slice.call(element.classList, 0).sort();
|
||||
}
|
||||
|
||||
export function createTemplate(html: any): HTMLElement {
|
||||
const t = getDOM().getDefaultDocument().createElement('template');
|
||||
t.innerHTML = html;
|
||||
return t;
|
||||
}
|
||||
|
||||
export function childNodesAsList(el: Node): any[] {
|
||||
const childNodes = el.childNodes;
|
||||
const res = [];
|
||||
for (let i = 0; i < childNodes.length; i++) {
|
||||
res[i] = childNodes[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import {Type, ɵglobal as global} from '@angular/core';
|
||||
import {ComponentFixture} from '@angular/core/testing';
|
||||
import {By, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
|
||||
import {hasClass, hasStyle, isCommentNode} from './browser_util';
|
||||
import {childNodesAsList, hasClass, hasStyle, isCommentNode} from './browser_util';
|
||||
|
||||
|
||||
|
||||
@ -293,18 +293,18 @@ function elementText(n: any): string {
|
||||
}
|
||||
|
||||
if (getDOM().isElementNode(n) && (n as Element).tagName == 'CONTENT') {
|
||||
return elementText(Array.prototype.slice.apply(getDOM().getDistributedNodes(n)));
|
||||
return elementText(Array.prototype.slice.apply((<any>n).getDistributedNodes()));
|
||||
}
|
||||
|
||||
if (hasShadowRoot(n)) {
|
||||
return elementText(getDOM().childNodesAsList((<any>n).shadowRoot));
|
||||
return elementText(childNodesAsList((<any>n).shadowRoot));
|
||||
}
|
||||
|
||||
if (hasNodes(n)) {
|
||||
return elementText(getDOM().childNodesAsList(n));
|
||||
return elementText(childNodesAsList(n));
|
||||
}
|
||||
|
||||
return getDOM().getText(n) !;
|
||||
return (n as any).textContent;
|
||||
}
|
||||
|
||||
function hasShadowRoot(node: any): boolean {
|
||||
|
Reference in New Issue
Block a user