2016-05-31 18:22:59 -04:00
|
|
|
import {isBlank, Type} from '../facade/lang';
|
2015-05-12 14:19:47 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
var _DOM: DomAdapter = null;
|
|
|
|
|
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-04-28 20:50:03 -04:00
|
|
|
if (isBlank(_DOM)) {
|
|
|
|
_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.
|
|
|
|
*/
|
2015-09-25 17:48:17 -04:00
|
|
|
export abstract class DomAdapter {
|
2016-04-28 20:50:03 -04:00
|
|
|
public xhrType: Type = null;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract hasProperty(element, name: string): boolean;
|
|
|
|
abstract setProperty(el: Element, name: string, value: any);
|
|
|
|
abstract getProperty(el: Element, name: string): any;
|
|
|
|
abstract invoke(el: Element, methodName: string, args: any[]): any;
|
2015-06-18 18:44:44 -04:00
|
|
|
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract logError(error);
|
|
|
|
abstract log(error);
|
|
|
|
abstract logGroup(error);
|
|
|
|
abstract logGroupEnd();
|
2015-05-12 14:19:47 -04:00
|
|
|
|
2015-12-15 19:38:27 -05:00
|
|
|
/** @deprecated */
|
2016-04-28 20:50:03 -04:00
|
|
|
getXHR(): Type { return this.xhrType; }
|
2015-10-14 12:41:15 -04:00
|
|
|
|
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
|
|
|
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract parse(templateHtml: string);
|
|
|
|
abstract query(selector: string): any;
|
|
|
|
abstract querySelector(el, selector: string): HTMLElement;
|
|
|
|
abstract querySelectorAll(el, selector: string): any[];
|
|
|
|
abstract on(el, evt, listener);
|
|
|
|
abstract onAndCancel(el, evt, listener): Function;
|
|
|
|
abstract dispatchEvent(el, evt);
|
|
|
|
abstract createMouseEvent(eventType): any;
|
|
|
|
abstract createEvent(eventType: string): any;
|
|
|
|
abstract preventDefault(evt);
|
|
|
|
abstract isPrevented(evt): boolean;
|
|
|
|
abstract getInnerHTML(el): string;
|
2016-04-30 22:02:05 -04:00
|
|
|
/** Returns content if el is a <template> element, null otherwise. */
|
|
|
|
abstract getTemplateContent(el): any;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getOuterHTML(el): string;
|
|
|
|
abstract nodeName(node): string;
|
|
|
|
abstract nodeValue(node): string;
|
|
|
|
abstract type(node): string;
|
|
|
|
abstract content(node): any;
|
|
|
|
abstract firstChild(el): Node;
|
|
|
|
abstract nextSibling(el): Node;
|
|
|
|
abstract parentElement(el): Node;
|
|
|
|
abstract childNodes(el): Node[];
|
|
|
|
abstract childNodesAsList(el): Node[];
|
|
|
|
abstract clearNodes(el);
|
|
|
|
abstract appendChild(el, node);
|
|
|
|
abstract removeChild(el, node);
|
|
|
|
abstract replaceChild(el, newNode, oldNode);
|
|
|
|
abstract remove(el): Node;
|
|
|
|
abstract insertBefore(el, node);
|
|
|
|
abstract insertAllBefore(el, nodes);
|
|
|
|
abstract insertAfter(el, node);
|
|
|
|
abstract setInnerHTML(el, value);
|
|
|
|
abstract getText(el): string;
|
|
|
|
abstract setText(el, value: string);
|
|
|
|
abstract getValue(el): string;
|
|
|
|
abstract setValue(el, value: string);
|
|
|
|
abstract getChecked(el): boolean;
|
|
|
|
abstract setChecked(el, value: boolean);
|
|
|
|
abstract createComment(text: string): any;
|
|
|
|
abstract createTemplate(html): HTMLElement;
|
|
|
|
abstract createElement(tagName, doc?): HTMLElement;
|
2015-10-27 16:16:27 -04:00
|
|
|
abstract createElementNS(ns: string, tagName: string, doc?): Element;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract createTextNode(text: string, doc?): Text;
|
|
|
|
abstract createScriptTag(attrName: string, attrValue: string, doc?): HTMLElement;
|
|
|
|
abstract createStyleElement(css: string, doc?): HTMLStyleElement;
|
|
|
|
abstract createShadowRoot(el): any;
|
|
|
|
abstract getShadowRoot(el): any;
|
|
|
|
abstract getHost(el): any;
|
|
|
|
abstract getDistributedNodes(el): Node[];
|
|
|
|
abstract clone /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
|
|
|
abstract getElementsByClassName(element, name: string): HTMLElement[];
|
|
|
|
abstract getElementsByTagName(element, name: string): HTMLElement[];
|
|
|
|
abstract classList(element): any[];
|
2015-11-18 19:17:49 -05:00
|
|
|
abstract addClass(element, className: string);
|
|
|
|
abstract removeClass(element, className: string);
|
|
|
|
abstract hasClass(element, className: string): boolean;
|
2015-11-18 18:59:25 -05:00
|
|
|
abstract setStyle(element, styleName: string, styleValue: string);
|
|
|
|
abstract removeStyle(element, styleName: string);
|
|
|
|
abstract getStyle(element, styleName: string): string;
|
|
|
|
abstract hasStyle(element, styleName: string, styleValue?: string): boolean;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract tagName(element): string;
|
|
|
|
abstract attributeMap(element): Map<string, string>;
|
|
|
|
abstract hasAttribute(element, attribute: string): boolean;
|
2016-01-08 15:01:29 -05:00
|
|
|
abstract hasAttributeNS(element, ns: string, attribute: string): boolean;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract getAttribute(element, attribute: string): string;
|
2016-01-08 15:01:29 -05:00
|
|
|
abstract getAttributeNS(element, ns: string, attribute: string): string;
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract setAttribute(element, name: string, value: string);
|
2015-10-27 16:16:27 -04:00
|
|
|
abstract setAttributeNS(element, ns: string, name: string, value: string);
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract removeAttribute(element, attribute: string);
|
2016-01-08 15:01:29 -05:00
|
|
|
abstract removeAttributeNS(element, ns: string, attribute: string);
|
2015-09-25 17:48:17 -04:00
|
|
|
abstract templateAwareRoot(el);
|
|
|
|
abstract createHtmlDocument(): HTMLDocument;
|
|
|
|
abstract defaultDoc(): HTMLDocument;
|
|
|
|
abstract getBoundingClientRect(el);
|
|
|
|
abstract getTitle(): string;
|
|
|
|
abstract setTitle(newTitle: string);
|
|
|
|
abstract elementMatches(n, selector: string): boolean;
|
|
|
|
abstract isTemplateElement(el: any): boolean;
|
|
|
|
abstract isTextNode(node): boolean;
|
|
|
|
abstract isCommentNode(node): boolean;
|
|
|
|
abstract isElementNode(node): boolean;
|
|
|
|
abstract hasShadowRoot(node): boolean;
|
|
|
|
abstract isShadowRoot(node): boolean;
|
|
|
|
abstract importIntoDoc /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
|
|
|
abstract adoptNode /*<T extends Node>*/ (node: Node /*T*/): Node /*T*/;
|
|
|
|
abstract getHref(element): string;
|
|
|
|
abstract getEventKey(event): string;
|
|
|
|
abstract resolveAndSetHref(element, baseUrl: string, href: string);
|
|
|
|
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;
|
|
|
|
abstract setData(element, name: string, value: string);
|
|
|
|
abstract getComputedStyle(element): any;
|
|
|
|
abstract getData(element, name: string): string;
|
|
|
|
abstract setGlobalVar(name: string, value: any);
|
|
|
|
abstract requestAnimationFrame(callback): number;
|
|
|
|
abstract cancelAnimationFrame(id);
|
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;
|
|
|
|
abstract setCookie(name: string, value: string);
|
2015-05-12 14:19:47 -04:00
|
|
|
}
|