fix(animations): Fix browser detection logic (#24188)

Element type is being polyfilled on the server now and cannot be used to detect browser environment.

PR Close #24188
This commit is contained in:
Vikram Subramanian 2018-05-29 13:34:10 -07:00 committed by Victor Berchet
parent b99ef2b80a
commit b492b9e12b
2 changed files with 7 additions and 3 deletions

View File

@ -10,6 +10,10 @@ import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnim
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
import {AnimationDriver} from '../../src/render/animation_driver';
export function isBrowser() {
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
}
export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer {
switch (players.length) {
case 0:
@ -138,7 +142,7 @@ let _query: (element: any, selector: string, multi: boolean) => any[] =
return [];
};
if (typeof Element != 'undefined') {
if (isBrowser()) {
// this is well supported in all browsers
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };

View File

@ -10,7 +10,7 @@ import {AnimationPlayer, ɵStyleData} from '@angular/animations';
import {allowPreviousPlayerStylesMerge, balancePreviousStylesIntoKeyframes, copyStyles} from '../../util';
import {AnimationDriver} from '../animation_driver';
import {CssKeyframesDriver} from '../css_keyframes/css_keyframes_driver';
import {containsElement, invokeQuery, matchesElement, validateStyleProperty} from '../shared';
import {containsElement, invokeQuery, isBrowser, matchesElement, validateStyleProperty} from '../shared';
import {WebAnimationsPlayer} from './web_animations_player';
@ -75,5 +75,5 @@ export function supportsWebAnimations() {
}
function getElementAnimateFn(): any {
return (typeof Element !== 'undefined' && (<any>Element).prototype['animate']) || {};
return (isBrowser() && (<any>Element).prototype['animate']) || {};
}