refactor(core): remove misc, completely unused functions from DomAdapter (#32278)

PR Close #32278
This commit is contained in:
Kara Erickson
2019-08-22 17:09:07 -07:00
committed by atscott
parent bceeeba405
commit 24127a2492
8 changed files with 6 additions and 100 deletions

View File

@ -13,12 +13,6 @@ import {setRootDomAdapter} from '../dom/dom_adapter';
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
const _attrToPropMap = {
'class': 'className',
'innerHtml': 'innerHTML',
'readonly': 'readOnly',
'tabindex': 'tabIndex',
};
const DOM_KEY_LOCATION_NUMPAD = 3;
@ -117,8 +111,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
}
get attrToPropMap(): any { return _attrToPropMap; }
contains(nodeA: any, nodeB: any): boolean { return nodeContains.call(nodeA, nodeB); }
querySelector(el: HTMLElement, selector: string): any { return el.querySelector(selector); }
querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); }
@ -147,9 +139,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
isPrevented(evt: Event): boolean {
return evt.defaultPrevented || evt.returnValue != null && !evt.returnValue;
}
getTemplateContent(el: Node): Node|null {
return 'content' in el && this.isTemplateElement(el) ? (<any>el).content : null;
}
nodeName(node: Node): string { return node.nodeName; }
nodeValue(node: Node): string|null { return node.nodeValue; }
type(node: HTMLInputElement): string { return node.type; }
@ -179,7 +168,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
appendChild(el: Node, node: Node) { el.appendChild(node); }
removeChild(el: Node, node: Node) { el.removeChild(node); }
replaceChild(el: Node, newChild: Node, oldChild: Node) { el.replaceChild(newChild, oldChild); }
remove(node: Node): Node {
if (node.parentNode) {
node.parentNode.removeChild(node);
@ -187,17 +175,11 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
return node;
}
insertBefore(parent: Node, ref: Node, node: Node) { parent.insertBefore(node, ref); }
insertAllBefore(parent: Node, ref: Node, nodes: Node[]) {
nodes.forEach((n: any) => parent.insertBefore(n, ref));
}
insertAfter(parent: Node, ref: Node, node: any) { parent.insertBefore(node, ref.nextSibling); }
setInnerHTML(el: Element, value: string) { el.innerHTML = value; }
getText(el: Node): string|null { return el.textContent; }
setText(el: Node, value: string) { el.textContent = value; }
getValue(el: any): string { return el.value; }
setValue(el: any, value: string) { el.value = value; }
getChecked(el: any): boolean { return el.checked; }
setChecked(el: any, value: boolean) { el.checked = value; }
createComment(text: string): Comment { return this.getDefaultDocument().createComment(text); }
createTemplate(html: any): HTMLElement {
const t = this.getDefaultDocument().createElement('template');
@ -216,25 +198,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
doc = doc || this.getDefaultDocument();
return doc.createTextNode(text);
}
createScriptTag(attrName: string, attrValue: string, doc?: Document): HTMLScriptElement {
doc = doc || this.getDefaultDocument();
const el = <HTMLScriptElement>doc.createElement('SCRIPT');
el.setAttribute(attrName, attrValue);
return el;
}
createStyleElement(css: string, doc?: Document): HTMLStyleElement {
doc = doc || this.getDefaultDocument();
const style = <HTMLStyleElement>doc.createElement('style');
this.appendChild(style, this.createTextNode(css, doc));
return style;
}
createShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).createShadowRoot(); }
getShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).shadowRoot; }
getHost(el: HTMLElement): HTMLElement { return (<any>el).host; }
clone(node: Node): Node { return node.cloneNode(true); }
getElementsByClassName(element: any, name: string): HTMLElement[] {
return element.getElementsByClassName(name);
}
getElementsByTagName(element: any, name: string): HTMLElement[] {
return element.getElementsByTagName(name);
}
@ -278,13 +245,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
return document.implementation.createHTMLDocument('fakeTitle');
}
getDefaultDocument(): Document { return document; }
getBoundingClientRect(el: Element): any {
try {
return el.getBoundingClientRect();
} catch {
return {top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0};
}
}
getTitle(doc: Document): string { return doc.title; }
setTitle(doc: Document, newTitle: string) { doc.title = newTitle || ''; }
elementMatches(n: any, selector: string): boolean {
@ -305,8 +265,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
return node.shadowRoot != null && node instanceof HTMLElement;
}
isShadowRoot(node: any): boolean { return node instanceof DocumentFragment; }
importIntoDoc(node: Node): any { return document.importNode(this.templateAwareRoot(node), true); }
adoptNode(node: Node): any { return document.adoptNode(node); }
getHref(el: Element): string { return el.getAttribute('href') !; }
getEventKey(event: any): string {

View File

@ -20,9 +20,6 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
constructor() { super(); }
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
resolveAndSetHref(el: HTMLAnchorElement, baseUrl: string, href: string) {
el.href = href == null ? baseUrl : baseUrl + '/../' + href;
}
supportsDOMEvents(): boolean { return true; }
supportsNativeShadowDOM(): boolean {
return typeof(<any>document.body).createShadowRoot === 'function';