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:
parent
b99ef2b80a
commit
b492b9e12b
|
@ -10,6 +10,10 @@ import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnim
|
||||||
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
|
import {AnimationStyleNormalizer} from '../../src/dsl/style_normalization/animation_style_normalizer';
|
||||||
import {AnimationDriver} from '../../src/render/animation_driver';
|
import {AnimationDriver} from '../../src/render/animation_driver';
|
||||||
|
|
||||||
|
export function isBrowser() {
|
||||||
|
return (typeof window !== 'undefined' && typeof window.document !== 'undefined');
|
||||||
|
}
|
||||||
|
|
||||||
export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer {
|
export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer {
|
||||||
switch (players.length) {
|
switch (players.length) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -138,7 +142,7 @@ let _query: (element: any, selector: string, multi: boolean) => any[] =
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof Element != 'undefined') {
|
if (isBrowser()) {
|
||||||
// this is well supported in all browsers
|
// this is well supported in all browsers
|
||||||
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };
|
_contains = (elm1: any, elm2: any) => { return elm1.contains(elm2) as boolean; };
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {AnimationPlayer, ɵStyleData} from '@angular/animations';
|
||||||
import {allowPreviousPlayerStylesMerge, balancePreviousStylesIntoKeyframes, copyStyles} from '../../util';
|
import {allowPreviousPlayerStylesMerge, balancePreviousStylesIntoKeyframes, copyStyles} from '../../util';
|
||||||
import {AnimationDriver} from '../animation_driver';
|
import {AnimationDriver} from '../animation_driver';
|
||||||
import {CssKeyframesDriver} from '../css_keyframes/css_keyframes_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';
|
import {WebAnimationsPlayer} from './web_animations_player';
|
||||||
|
|
||||||
|
@ -75,5 +75,5 @@ export function supportsWebAnimations() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getElementAnimateFn(): any {
|
function getElementAnimateFn(): any {
|
||||||
return (typeof Element !== 'undefined' && (<any>Element).prototype['animate']) || {};
|
return (isBrowser() && (<any>Element).prototype['animate']) || {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue