2016-04-28 17:50:03 -07:00
|
|
|
import {DomAdapter} from '../dom/dom_adapter';
|
2016-06-08 16:38:52 -07:00
|
|
|
import {StringMapWrapper} from '../facade/collection';
|
|
|
|
import {Type, isFunction, isPresent} from '../facade/lang';
|
|
|
|
|
2015-10-14 09:41:15 -07:00
|
|
|
|
2015-03-09 11:35:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides DOM operations in any browser environment.
|
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
export abstract class GenericBrowserDomAdapter extends DomAdapter {
|
2015-09-18 00:49:56 +02:00
|
|
|
private _animationPrefix: string = null;
|
|
|
|
private _transitionEnd: string = null;
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
try {
|
|
|
|
var element = this.createElement('div', this.defaultDoc());
|
|
|
|
if (isPresent(this.getStyle(element, 'animationName'))) {
|
|
|
|
this._animationPrefix = '';
|
|
|
|
} else {
|
|
|
|
var domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
|
|
|
|
for (var i = 0; i < domPrefixes.length; i++) {
|
|
|
|
if (isPresent(this.getStyle(element, domPrefixes[i] + 'AnimationName'))) {
|
2015-10-31 13:04:26 -07:00
|
|
|
this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
|
2015-09-18 00:49:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 17:33:21 -07:00
|
|
|
var transEndEventNames: {[key: string]: string} = {
|
2015-09-18 00:49:56 +02:00
|
|
|
WebkitTransition: 'webkitTransitionEnd',
|
|
|
|
MozTransition: 'transitionend',
|
|
|
|
OTransition: 'oTransitionEnd otransitionend',
|
|
|
|
transition: 'transitionend'
|
|
|
|
};
|
2016-02-19 11:49:31 -08:00
|
|
|
StringMapWrapper.forEach(transEndEventNames, (value: string, key: string) => {
|
2015-09-18 00:49:56 +02:00
|
|
|
if (isPresent(this.getStyle(element, key))) {
|
|
|
|
this._transitionEnd = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this._animationPrefix = null;
|
|
|
|
this._transitionEnd = null;
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 09:41:15 -07:00
|
|
|
|
2015-08-28 11:29:19 -07:00
|
|
|
getDistributedNodes(el: HTMLElement): Node[] { return (<any>el).getDistributedNodes(); }
|
2015-07-07 20:03:00 -07:00
|
|
|
resolveAndSetHref(el: HTMLAnchorElement, baseUrl: string, href: string) {
|
2015-03-09 11:35:46 +01:00
|
|
|
el.href = href == null ? baseUrl : baseUrl + '/../' + href;
|
|
|
|
}
|
2015-05-12 11:19:47 -07:00
|
|
|
supportsDOMEvents(): boolean { return true; }
|
2015-06-26 11:10:52 -07:00
|
|
|
supportsNativeShadowDOM(): boolean {
|
|
|
|
return isFunction((<any>this.defaultDoc().body).createShadowRoot);
|
|
|
|
}
|
2015-09-18 00:49:56 +02:00
|
|
|
getAnimationPrefix(): string {
|
2016-06-08 16:38:52 -07:00
|
|
|
return isPresent(this._animationPrefix) ? this._animationPrefix : '';
|
2015-09-18 00:49:56 +02:00
|
|
|
}
|
2016-06-08 16:38:52 -07:00
|
|
|
getTransitionEnd(): string { return isPresent(this._transitionEnd) ? this._transitionEnd : ''; }
|
2015-09-18 00:49:56 +02:00
|
|
|
supportsAnimation(): boolean {
|
|
|
|
return isPresent(this._animationPrefix) && isPresent(this._transitionEnd);
|
|
|
|
}
|
2015-03-09 11:35:46 +01:00
|
|
|
}
|