2016-06-23 09:47:54 -07: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 18:21:28 -07:00
|
|
|
import {Type} from '@angular/core';
|
|
|
|
|
2017-03-24 09:59:41 -07:00
|
|
|
let _DOM: DomAdapter = null !;
|
2016-04-28 17:50:03 -07:00
|
|
|
|
2016-05-01 22:50:37 -07:00
|
|
|
export function getDOM() {
|
2016-04-28 17:50:03 -07:00
|
|
|
return _DOM;
|
|
|
|
}
|
|
|
|
|
2016-05-01 22:50:37 -07:00
|
|
|
export function setDOM(adapter: DomAdapter) {
|
2016-04-28 17:50:03 -07:00
|
|
|
_DOM = adapter;
|
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
|
|
|
|
export function setRootDomAdapter(adapter: DomAdapter) {
|
2016-09-30 09:26:53 -07:00
|
|
|
if (!_DOM) {
|
2016-04-28 17:50:03 -07:00
|
|
|
_DOM = adapter;
|
2015-05-19 15:05:02 -07:00
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
}
|
|
|
|
|
2015-07-07 20:03:00 -07:00
|
|
|
/* tslint:disable:requireParameterType */
|
2015-05-12 11:19:47 -07:00
|
|
|
/**
|
|
|
|
* Provides DOM operations in an environment-agnostic way.
|
2016-08-17 13:42:18 -07:00
|
|
|
*
|
|
|
|
* @security Tread carefully! Interacting with the DOM directly is dangerous and
|
|
|
|
* can introduce XSS risks.
|
2015-05-12 11:19:47 -07:00
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
export abstract class DomAdapter {
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract hasProperty(element: any, name: string): boolean;
|
|
|
|
abstract setProperty(el: Element, name: string, value: any): any;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract getProperty(el: Element, name: string): any;
|
|
|
|
abstract invoke(el: Element, methodName: string, args: any[]): any;
|
2015-06-18 15:44:44 -07:00
|
|
|
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract logError(error: any): any;
|
|
|
|
abstract log(error: any): any;
|
|
|
|
abstract logGroup(error: any): any;
|
|
|
|
abstract logGroupEnd(): any;
|
2015-05-12 11:19:47 -07:00
|
|
|
|
2017-03-14 17:15:46 -07:00
|
|
|
abstract contains(nodeA: any, nodeB: any): boolean;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract parse(templateHtml: string): any;
|
|
|
|
abstract querySelector(el: any, selector: string): any;
|
|
|
|
abstract querySelectorAll(el: any, selector: string): any[];
|
|
|
|
abstract on(el: any, evt: any, listener: any): any;
|
|
|
|
abstract onAndCancel(el: any, evt: any, listener: any): Function;
|
|
|
|
abstract dispatchEvent(el: any, evt: any): any;
|
|
|
|
abstract createMouseEvent(eventType: any): any;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract createEvent(eventType: string): any;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract preventDefault(evt: any): any;
|
|
|
|
abstract isPrevented(evt: any): boolean;
|
|
|
|
abstract nodeName(node: any): string;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract nodeValue(node: any): string|null;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract type(node: any): string;
|
|
|
|
abstract content(node: any): any;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract firstChild(el: any): Node|null;
|
|
|
|
abstract nextSibling(el: any): Node|null;
|
|
|
|
abstract parentElement(el: any): Node|null;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract childNodes(el: any): Node[];
|
|
|
|
abstract childNodesAsList(el: any): Node[];
|
|
|
|
abstract clearNodes(el: any): any;
|
|
|
|
abstract appendChild(el: any, node: any): any;
|
|
|
|
abstract removeChild(el: any, node: any): any;
|
|
|
|
abstract remove(el: any): Node;
|
|
|
|
abstract insertBefore(parent: any, ref: any, node: any): any;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract getText(el: any): string|null;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract setText(el: any, value: string): any;
|
|
|
|
abstract getValue(el: any): string;
|
|
|
|
abstract setValue(el: any, value: string): any;
|
|
|
|
abstract getChecked(el: any): boolean;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract createComment(text: string): any;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract createTemplate(html: any): HTMLElement;
|
|
|
|
abstract createElement(tagName: any, doc?: any): HTMLElement;
|
|
|
|
abstract createElementNS(ns: string, tagName: string, doc?: any): Element;
|
|
|
|
abstract createTextNode(text: string, doc?: any): Text;
|
|
|
|
abstract getHost(el: any): any;
|
|
|
|
abstract getDistributedNodes(el: any): Node[];
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract clone /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract getElementsByTagName(element: any, name: string): HTMLElement[];
|
|
|
|
abstract classList(element: any): any[];
|
|
|
|
abstract addClass(element: any, className: string): any;
|
|
|
|
abstract removeClass(element: any, className: string): any;
|
|
|
|
abstract hasClass(element: any, className: string): boolean;
|
|
|
|
abstract setStyle(element: any, styleName: string, styleValue: string): any;
|
|
|
|
abstract removeStyle(element: any, styleName: string): any;
|
|
|
|
abstract getStyle(element: any, styleName: string): string;
|
|
|
|
abstract hasStyle(element: any, styleName: string, styleValue?: string): boolean;
|
|
|
|
abstract tagName(element: any): string;
|
|
|
|
abstract hasAttribute(element: any, attribute: string): boolean;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract getAttribute(element: any, attribute: string): string|null;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract setAttribute(element: any, name: string, value: string): any;
|
|
|
|
abstract setAttributeNS(element: any, ns: string, name: string, value: string): any;
|
|
|
|
abstract removeAttribute(element: any, attribute: string): any;
|
|
|
|
abstract removeAttributeNS(element: any, ns: string, attribute: string): any;
|
|
|
|
abstract templateAwareRoot(el: any): any;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract createHtmlDocument(): HTMLDocument;
|
2017-08-08 02:17:40 -07:00
|
|
|
abstract getDefaultDocument(): Document;
|
2017-02-14 16:14:40 -08:00
|
|
|
abstract getTitle(doc: Document): string;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract setTitle(doc: Document, newTitle: string): any;
|
|
|
|
abstract elementMatches(n: any, selector: string): boolean;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract isTemplateElement(el: any): boolean;
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract isTextNode(node: any): boolean;
|
|
|
|
abstract isElementNode(node: any): boolean;
|
2019-08-22 18:26:01 -07:00
|
|
|
|
|
|
|
// Used by Testability
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract isShadowRoot(node: any): boolean;
|
2019-08-22 18:26:01 -07:00
|
|
|
|
|
|
|
// Used by KeyEventsPlugin
|
2017-02-14 21:03:18 -08:00
|
|
|
abstract getEventKey(event: any): string;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract supportsDOMEvents(): boolean;
|
2019-08-22 18:26:01 -07:00
|
|
|
|
|
|
|
// Used by PlatformLocation and ServerEventManagerPlugin
|
2017-02-14 16:14:40 -08:00
|
|
|
abstract getGlobalEventTarget(doc: Document, target: string): any;
|
2019-08-22 18:26:01 -07:00
|
|
|
|
|
|
|
// Used by PlatformLocation
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract getHistory(): History;
|
|
|
|
abstract getLocation(): Location;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract getBaseHref(doc: Document): string|null;
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract resetBaseElement(): void;
|
2019-08-22 17:09:07 -07:00
|
|
|
|
|
|
|
// TODO: remove dependency in DefaultValueAccessor
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract getUserAgent(): string;
|
2019-08-22 17:49:43 -07:00
|
|
|
|
|
|
|
// Used by AngularProfiler
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract performanceNow(): number;
|
2016-05-27 20:15:40 -07:00
|
|
|
|
2019-08-22 16:14:18 -07:00
|
|
|
// Used by CookieXSRFStrategy
|
2016-05-27 20:15:40 -07:00
|
|
|
abstract supportsCookies(): boolean;
|
2017-03-24 09:59:41 -07:00
|
|
|
abstract getCookie(name: string): string|null;
|
2015-05-12 11:19:47 -07:00
|
|
|
}
|