2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-10 21:21:28 -04:00
|
|
|
import {Type} from '@angular/core';
|
|
|
|
|
2016-09-27 20:30:26 -04:00
|
|
|
let _DOM: DomAdapter = null;
|
2016-04-28 20:50:03 -04:00
|
|
|
|
2016-05-02 01:50:37 -04:00
|
|
|
export function getDOM() {
|
2016-04-28 20:50:03 -04:00
|
|
|
return _DOM;
|
|
|
|
}
|
|
|
|
|
2016-05-02 01:50:37 -04:00
|
|
|
export function setDOM(adapter: DomAdapter) {
|
2016-04-28 20:50:03 -04:00
|
|
|
_DOM = adapter;
|
|
|
|
}
|
2015-05-12 14:19:47 -04:00
|
|
|
|
|
|
|
export function setRootDomAdapter(adapter: DomAdapter) {
|
2016-09-30 12:26:53 -04:00
|
|
|
if (!_DOM) {
|
2016-04-28 20:50:03 -04:00
|
|
|
_DOM = adapter;
|
2015-05-19 18:05:02 -04:00
|
|
|
}
|
2015-05-12 14:19:47 -04:00
|
|
|
}
|
|
|
|
|
2015-07-07 23:03:00 -04:00
|
|
|
/* tslint:disable:requireParameterType */
|
2015-05-12 14:19:47 -04:00
|
|
|
/**
|
|
|
|
* Provides DOM operations in an environment-agnostic way.
|
2016-08-17 16:42:18 -04:00
|
|
|
*
|
|
|
|
* @security Tread carefully! Interacting with the DOM directly is dangerous and
|
|
|
|
* can introduce XSS risks.
|
2015-05-12 14:19:47 -04:00
|
|
|
*/
|
2015-09-25 17:48:17 -04:00
|
|
|
export abstract class DomAdapter {
|
2016-08-17 12:24:44 -04:00
|
|
|
public resourceLoaderType: Type<any> = null;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract hasProperty(element: any /** TODO #9100 */, name: string): boolean;
|
|
|
|
abstract setProperty(el: Element, name: string, value: any): any /** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getProperty(el: Element, name: string): any;
|
|
|
|
abstract invoke(el: Element, methodName: string, args: any[]): any;
|
2015-06-18 18:44:44 -04:00
|
|
|
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract logError(error: any /** TODO #9100 */): any /** TODO #9100 */;
|
|
|
|
abstract log(error: any /** TODO #9100 */): any /** TODO #9100 */;
|
|
|
|
abstract logGroup(error: any /** TODO #9100 */): any /** TODO #9100 */;
|
|
|
|
abstract logGroupEnd(): any /** TODO #9100 */;
|
2015-05-12 14:19:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps attribute names to their corresponding property names for cases
|
|
|
|
* where attribute name doesn't match property name.
|
|
|
|
*/
|
2016-01-12 19:38:36 -05:00
|
|
|
get attrToPropMap(): {[key: string]: string} { return this._attrToPropMap; };
|
|
|
|
set attrToPropMap(value: {[key: string]: string}) { this._attrToPropMap = value; };
|
|
|
|
/** @internal */
|
|
|
|
_attrToPropMap: {[key: string]: string};
|
2015-05-12 14:19:47 -04:00
|
|
|
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract parse(templateHtml: string): any /** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract query(selector: string): any;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract querySelector(el: any /** TODO #9100 */, selector: string): HTMLElement;
|
|
|
|
abstract querySelectorAll(el: any /** TODO #9100 */, selector: string): any[];
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract on(
|
|
|
|
el: any /** TODO #9100 */, evt: any /** TODO #9100 */, listener: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract onAndCancel(
|
|
|
|
el: any /** TODO #9100 */, evt: any /** TODO #9100 */,
|
|
|
|
listener: any /** TODO #9100 */): Function;
|
|
|
|
abstract dispatchEvent(el: any /** TODO #9100 */, evt: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract createMouseEvent(eventType: any /** TODO #9100 */): any;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createEvent(eventType: string): any;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract preventDefault(evt: any /** TODO #9100 */): any /** TODO #9100 */;
|
|
|
|
abstract isPrevented(evt: any /** TODO #9100 */): boolean;
|
|
|
|
abstract getInnerHTML(el: any /** TODO #9100 */): string;
|
2016-04-30 22:02:05 -04:00
|
|
|
/** Returns content if el is a <template> element, null otherwise. */
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getTemplateContent(el: any /** TODO #9100 */): any;
|
|
|
|
abstract getOuterHTML(el: any /** TODO #9100 */): string;
|
|
|
|
abstract nodeName(node: any /** TODO #9100 */): string;
|
|
|
|
abstract nodeValue(node: any /** TODO #9100 */): string;
|
|
|
|
abstract type(node: any /** TODO #9100 */): string;
|
|
|
|
abstract content(node: any /** TODO #9100 */): any;
|
|
|
|
abstract firstChild(el: any /** TODO #9100 */): Node;
|
|
|
|
abstract nextSibling(el: any /** TODO #9100 */): Node;
|
|
|
|
abstract parentElement(el: any /** TODO #9100 */): Node;
|
|
|
|
abstract childNodes(el: any /** TODO #9100 */): Node[];
|
|
|
|
abstract childNodesAsList(el: any /** TODO #9100 */): Node[];
|
|
|
|
abstract clearNodes(el: any /** TODO #9100 */): any /** TODO #9100 */;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract appendChild(el: any /** TODO #9100 */, node: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract removeChild(el: any /** TODO #9100 */, node: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract replaceChild(
|
|
|
|
el: any /** TODO #9100 */, newNode: any /** TODO #9100 */,
|
|
|
|
oldNode: any /** TODO #9100 */): any /** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract remove(el: any /** TODO #9100 */): Node;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract insertBefore(el: any /** TODO #9100 */, node: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract insertAllBefore(el: any /** TODO #9100 */, nodes: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract insertAfter(el: any /** TODO #9100 */, node: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract setInnerHTML(el: any /** TODO #9100 */, value: any /** TODO #9100 */): any
|
|
|
|
/** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getText(el: any /** TODO #9100 */): string;
|
|
|
|
abstract setText(el: any /** TODO #9100 */, value: string): any /** TODO #9100 */;
|
|
|
|
abstract getValue(el: any /** TODO #9100 */): string;
|
|
|
|
abstract setValue(el: any /** TODO #9100 */, value: string): any /** TODO #9100 */;
|
|
|
|
abstract getChecked(el: any /** TODO #9100 */): boolean;
|
|
|
|
abstract setChecked(el: any /** TODO #9100 */, value: boolean): any /** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createComment(text: string): any;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract createTemplate(html: any /** TODO #9100 */): HTMLElement;
|
|
|
|
abstract createElement(tagName: any /** TODO #9100 */, doc?: any /** TODO #9100 */): HTMLElement;
|
|
|
|
abstract createElementNS(ns: string, tagName: string, doc?: any /** TODO #9100 */): Element;
|
|
|
|
abstract createTextNode(text: string, doc?: any /** TODO #9100 */): Text;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract createScriptTag(attrName: string, attrValue: string, doc?: any /** TODO #9100 */):
|
|
|
|
HTMLElement;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract createStyleElement(css: string, doc?: any /** TODO #9100 */): HTMLStyleElement;
|
|
|
|
abstract createShadowRoot(el: any /** TODO #9100 */): any;
|
|
|
|
abstract getShadowRoot(el: any /** TODO #9100 */): any;
|
|
|
|
abstract getHost(el: any /** TODO #9100 */): any;
|
|
|
|
abstract getDistributedNodes(el: any /** TODO #9100 */): Node[];
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract clone /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getElementsByClassName(element: any /** TODO #9100 */, name: string): HTMLElement[];
|
|
|
|
abstract getElementsByTagName(element: any /** TODO #9100 */, name: string): HTMLElement[];
|
|
|
|
abstract classList(element: any /** TODO #9100 */): any[];
|
|
|
|
abstract addClass(element: any /** TODO #9100 */, className: string): any /** TODO #9100 */;
|
|
|
|
abstract removeClass(element: any /** TODO #9100 */, className: string): any /** TODO #9100 */;
|
|
|
|
abstract hasClass(element: any /** TODO #9100 */, className: string): boolean;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract setStyle(element: any /** TODO #9100 */, styleName: string, styleValue: string): any
|
|
|
|
/** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract removeStyle(element: any /** TODO #9100 */, styleName: string): any /** TODO #9100 */;
|
|
|
|
abstract getStyle(element: any /** TODO #9100 */, styleName: string): string;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract hasStyle(element: any /** TODO #9100 */, styleName: string, styleValue?: string):
|
|
|
|
boolean;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract tagName(element: any /** TODO #9100 */): string;
|
|
|
|
abstract attributeMap(element: any /** TODO #9100 */): Map<string, string>;
|
|
|
|
abstract hasAttribute(element: any /** TODO #9100 */, attribute: string): boolean;
|
|
|
|
abstract hasAttributeNS(element: any /** TODO #9100 */, ns: string, attribute: string): boolean;
|
|
|
|
abstract getAttribute(element: any /** TODO #9100 */, attribute: string): string;
|
|
|
|
abstract getAttributeNS(element: any /** TODO #9100 */, ns: string, attribute: string): string;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract setAttribute(element: any /** TODO #9100 */, name: string, value: string): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract setAttributeNS(element: any /** TODO #9100 */, ns: string, name: string, value: string):
|
|
|
|
any /** TODO #9100 */;
|
|
|
|
abstract removeAttribute(element: any /** TODO #9100 */, attribute: string): any
|
|
|
|
/** TODO #9100 */;
|
|
|
|
abstract removeAttributeNS(element: any /** TODO #9100 */, ns: string, attribute: string): any
|
|
|
|
/** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract templateAwareRoot(el: any /** TODO #9100 */): any /** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createHtmlDocument(): HTMLDocument;
|
|
|
|
abstract defaultDoc(): HTMLDocument;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getBoundingClientRect(el: any /** TODO #9100 */): any /** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getTitle(): string;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract setTitle(newTitle: string): any /** TODO #9100 */;
|
|
|
|
abstract elementMatches(n: any /** TODO #9100 */, selector: string): boolean;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract isTemplateElement(el: any): boolean;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract isTextNode(node: any /** TODO #9100 */): boolean;
|
|
|
|
abstract isCommentNode(node: any /** TODO #9100 */): boolean;
|
|
|
|
abstract isElementNode(node: any /** TODO #9100 */): boolean;
|
|
|
|
abstract hasShadowRoot(node: any /** TODO #9100 */): boolean;
|
|
|
|
abstract isShadowRoot(node: any /** TODO #9100 */): boolean;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract importIntoDoc /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
|
|
|
abstract adoptNode /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getHref(element: any /** TODO #9100 */): string;
|
|
|
|
abstract getEventKey(event: any /** TODO #9100 */): string;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract resolveAndSetHref(element: any /** TODO #9100 */, baseUrl: string, href: string): any
|
|
|
|
/** TODO #9100 */;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract supportsDOMEvents(): boolean;
|
|
|
|
abstract supportsNativeShadowDOM(): boolean;
|
|
|
|
abstract getGlobalEventTarget(target: string): any;
|
|
|
|
abstract getHistory(): History;
|
|
|
|
abstract getLocation(): Location;
|
|
|
|
abstract getBaseHref(): string;
|
|
|
|
abstract resetBaseElement(): void;
|
|
|
|
abstract getUserAgent(): string;
|
2016-06-08 19:38:52 -04:00
|
|
|
abstract setData(element: any /** TODO #9100 */, name: string, value: string): any
|
|
|
|
/** TODO #9100 */;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract getComputedStyle(element: any /** TODO #9100 */): any;
|
|
|
|
abstract getData(element: any /** TODO #9100 */, name: string): string;
|
|
|
|
abstract setGlobalVar(name: string, value: any): any /** TODO #9100 */;
|
2016-05-25 15:46:22 -04:00
|
|
|
abstract supportsWebAnimation(): boolean;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract performanceNow(): number;
|
|
|
|
abstract getAnimationPrefix(): string;
|
|
|
|
abstract getTransitionEnd(): string;
|
|
|
|
abstract supportsAnimation(): boolean;
|
2016-05-27 23:15:40 -04:00
|
|
|
|
|
|
|
abstract supportsCookies(): boolean;
|
|
|
|
abstract getCookie(name: string): string;
|
2016-06-08 18:45:15 -04:00
|
|
|
abstract setCookie(name: string, value: string): any /** TODO #9100 */;
|
2015-05-12 14:19:47 -04:00
|
|
|
}
|