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
|
|
|
|
*/
|
|
|
|
|
2017-03-24 12:59:41 -04:00
|
|
|
let _DOM: DomAdapter = null !;
|
2016-04-28 20:50:03 -04:00
|
|
|
|
2019-08-22 22:16:25 -04:00
|
|
|
export function getDOM(): DomAdapter {
|
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 {
|
2019-08-27 19:39:33 -04:00
|
|
|
// Needs Domino-friendly test utility
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getProperty(el: Element, name: string): any;
|
2019-08-27 19:39:33 -04:00
|
|
|
abstract dispatchEvent(el: any, evt: any): any;
|
2015-06-18 18:44:44 -04:00
|
|
|
|
2019-08-27 19:39:33 -04:00
|
|
|
// Used by router
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract log(error: any): any;
|
|
|
|
abstract logGroup(error: any): any;
|
|
|
|
abstract logGroupEnd(): any;
|
2015-05-12 14:19:47 -04:00
|
|
|
|
2019-08-23 16:28:33 -04:00
|
|
|
// Used by Meta
|
2019-08-27 19:39:33 -04:00
|
|
|
abstract querySelectorAll(el: any, selector: string): any[];
|
2019-08-23 16:28:33 -04:00
|
|
|
abstract remove(el: any): Node;
|
|
|
|
abstract getAttribute(element: any, attribute: string): string|null;
|
|
|
|
|
|
|
|
// Used by platform-server
|
2019-08-27 19:39:33 -04:00
|
|
|
abstract setProperty(el: Element, name: string, value: any): any;
|
|
|
|
abstract querySelector(el: any, selector: string): any;
|
2019-08-24 11:18:00 -04:00
|
|
|
abstract nextSibling(el: any): Node|null;
|
|
|
|
abstract parentElement(el: any): Node|null;
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract clearNodes(el: any): any;
|
|
|
|
abstract appendChild(el: any, node: any): any;
|
|
|
|
abstract removeChild(el: any, node: any): any;
|
|
|
|
abstract insertBefore(parent: any, ref: any, node: any): any;
|
|
|
|
abstract setText(el: any, value: string): any;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createComment(text: string): any;
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract createElement(tagName: any, doc?: any): HTMLElement;
|
|
|
|
abstract createElementNS(ns: string, tagName: string, doc?: any): Element;
|
|
|
|
abstract createTextNode(text: string, doc?: any): Text;
|
|
|
|
abstract getElementsByTagName(element: any, name: string): HTMLElement[];
|
2019-08-23 15:32:00 -04:00
|
|
|
abstract addClass(element: any, className: string): any;
|
|
|
|
abstract removeClass(element: any, className: string): any;
|
|
|
|
abstract getStyle(element: any, styleName: string): any;
|
|
|
|
abstract setStyle(element: any, styleName: string, styleValue: string): any;
|
|
|
|
abstract removeStyle(element: any, styleName: string): any;
|
2017-02-15 00:03:18 -05: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;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createHtmlDocument(): HTMLDocument;
|
2017-08-08 05:17:40 -04:00
|
|
|
abstract getDefaultDocument(): Document;
|
2019-08-22 22:48:08 -04:00
|
|
|
|
|
|
|
// Used by Title
|
2017-02-14 19:14:40 -05:00
|
|
|
abstract getTitle(doc: Document): string;
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract setTitle(doc: Document, newTitle: string): any;
|
2019-08-22 22:48:08 -04:00
|
|
|
|
|
|
|
// Used by By.css
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract elementMatches(n: any, selector: string): boolean;
|
|
|
|
abstract isElementNode(node: any): boolean;
|
2019-08-22 21:26:01 -04:00
|
|
|
|
|
|
|
// Used by Testability
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract isShadowRoot(node: any): boolean;
|
2019-08-23 16:28:33 -04:00
|
|
|
abstract getHost(el: any): any;
|
2019-08-22 21:26:01 -04:00
|
|
|
|
|
|
|
// Used by KeyEventsPlugin
|
2019-08-27 19:21:39 -04:00
|
|
|
abstract onAndCancel(el: any, evt: any, listener: any): Function;
|
2017-02-15 00:03:18 -05:00
|
|
|
abstract getEventKey(event: any): string;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract supportsDOMEvents(): boolean;
|
2019-08-22 21:26:01 -04:00
|
|
|
|
|
|
|
// Used by PlatformLocation and ServerEventManagerPlugin
|
2017-02-14 19:14:40 -05:00
|
|
|
abstract getGlobalEventTarget(doc: Document, target: string): any;
|
2019-08-22 21:26:01 -04:00
|
|
|
|
|
|
|
// Used by PlatformLocation
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getHistory(): History;
|
2019-08-22 22:16:25 -04:00
|
|
|
abstract getLocation():
|
|
|
|
any; /** This is the ambient Location definition, NOT Location from @angular/common. */
|
2017-03-24 12:59:41 -04:00
|
|
|
abstract getBaseHref(doc: Document): string|null;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract resetBaseElement(): void;
|
2019-08-22 20:09:07 -04:00
|
|
|
|
|
|
|
// TODO: remove dependency in DefaultValueAccessor
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getUserAgent(): string;
|
2019-08-22 20:49:43 -04:00
|
|
|
|
|
|
|
// Used by AngularProfiler
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract performanceNow(): number;
|
2016-05-27 23:15:40 -04:00
|
|
|
|
2019-08-22 19:14:18 -04:00
|
|
|
// Used by CookieXSRFStrategy
|
2016-05-27 23:15:40 -04:00
|
|
|
abstract supportsCookies(): boolean;
|
2017-03-24 12:59:41 -04:00
|
|
|
abstract getCookie(name: string): string|null;
|
2015-05-12 14:19:47 -04:00
|
|
|
}
|