Skip to content

Commit

Permalink
fix(build): fix window not defined on An Universal (#5073)
Browse files Browse the repository at this point in the history
* fix(build): fix window not defined on An Universal

* fix(merge): resolve merge conflicts
  • Loading branch information
Domainv authored and valorkin committed Mar 4, 2019
1 parent 604e0f7 commit 682d1f2
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/positioning/positioning.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable, ElementRef, RendererFactory2 } from '@angular/core';
import { Injectable, ElementRef, RendererFactory2, Inject, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

import { positionElements } from './ng-positioning';

import { fromEvent, merge, of, animationFrameScheduler, Subject } from 'rxjs';
import { Options } from './models';

Expand Down Expand Up @@ -43,31 +45,33 @@ export interface PositioningOptions {
export class PositioningService {
options: Options;
private update$$ = new Subject<null>();

private events$: any = merge(
fromEvent(window, 'scroll'),
fromEvent(window, 'resize'),
of(0, animationFrameScheduler),
this.update$$
);

private positionElements = new Map();

constructor(rendererFactory: RendererFactory2) {
this.events$
.subscribe(() => {
this.positionElements
.forEach((positionElement: PositioningOptions) => {
positionElements(
_getHtmlElement(positionElement.target),
_getHtmlElement(positionElement.element),
positionElement.attachment,
positionElement.appendToBody,
this.options,
rendererFactory.createRenderer(null, null)
);
});
});
constructor(
rendererFactory: RendererFactory2,
@Inject(PLATFORM_ID) platformId: number
) {
if (isPlatformBrowser(platformId)) {
merge(
fromEvent(window, 'scroll'),
fromEvent(window, 'resize'),
of(0, animationFrameScheduler),
this.update$$
)
.subscribe(() => {
this.positionElements
.forEach((positionElement: PositioningOptions) => {
positionElements(
_getHtmlElement(positionElement.target),
_getHtmlElement(positionElement.element),
positionElement.attachment,
positionElement.appendToBody,
this.options,
rendererFactory.createRenderer(null, null)
);
});
});
}
}

position(options: PositioningOptions): void {
Expand Down

0 comments on commit 682d1f2

Please sign in to comment.