From bcc86f4668f45c076e56286c0d1ba83c23e40fe7 Mon Sep 17 00:00:00 2001 From: Philip Sultanescu Date: Thu, 28 Feb 2019 03:46:19 +0100 Subject: [PATCH 1/4] fix(resizable-directive): browser check for angular universal Because it doesn't know what document is Fixes 'ReferenceError: document is not defined' --- src/resizable.directive.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/resizable.directive.ts b/src/resizable.directive.ts index 56c632a..f643df9 100644 --- a/src/resizable.directive.ts +++ b/src/resizable.directive.ts @@ -9,8 +9,11 @@ import { OnDestroy, NgZone, OnChanges, - SimpleChanges + SimpleChanges, + Inject, + PLATFORM_ID } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; import { Subject, Observable, Observer, merge, EMPTY } from 'rxjs'; import { map, @@ -374,6 +377,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { * @hidden */ constructor( + @Inject(PLATFORM_ID) private platformId: Object, private renderer: Renderer2, public elm: ElementRef, private zone: NgZone @@ -688,7 +692,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { }; const resizeCursors = getResizeCursors(); const cursor = getResizeCursor(currentResize.edges, resizeCursors); - this.renderer.setStyle(document.body, 'cursor', cursor); + // browser check for angular universal, because it doesn't know what document is + if (isPlatformBrowser(this.platformId)) { + this.renderer.setStyle(document.body, 'cursor', cursor); + } this.setElementClass(this.elm, RESIZE_ACTIVE_CLASS, true); if (this.enableGhostResize) { currentResize.clonedNode = this.elm.nativeElement.cloneNode(true); @@ -754,7 +761,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { this.mouseup.subscribe(() => { if (currentResize) { this.renderer.removeClass(this.elm.nativeElement, RESIZE_ACTIVE_CLASS); - this.renderer.setStyle(document.body, 'cursor', ''); + // browser check for angular universal, because it doesn't know what document is + if (isPlatformBrowser(this.platformId)) { + this.renderer.setStyle(document.body, 'cursor', ''); + } this.renderer.setStyle(this.elm.nativeElement, 'cursor', ''); this.zone.run(() => { this.resizeEnd.emit({ @@ -785,7 +795,10 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { * @hidden */ ngOnDestroy(): void { - this.renderer.setStyle(document.body, 'cursor', ''); + // browser check for angular universal, because it doesn't know what document is + if (isPlatformBrowser(this.platformId)) { + this.renderer.setStyle(document.body, 'cursor', ''); + } this.mousedown.complete(); this.mouseup.complete(); this.mousemove.complete(); From 1345ff47f3fcc7ec061f573c2cc73a40e165b68f Mon Sep 17 00:00:00 2001 From: Philip Sultanescu Date: Thu, 28 Feb 2019 04:07:50 +0100 Subject: [PATCH 2/4] fix(resizable.directive): avoid using Object, use object instead to fix travis error --- src/resizable.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resizable.directive.ts b/src/resizable.directive.ts index f643df9..dab56cd 100644 --- a/src/resizable.directive.ts +++ b/src/resizable.directive.ts @@ -377,7 +377,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { * @hidden */ constructor( - @Inject(PLATFORM_ID) private platformId: Object, + @Inject(PLATFORM_ID) private platformId: object, private renderer: Renderer2, public elm: ElementRef, private zone: NgZone From dd3dfaf762420e5c843d46914195658c02cd5431 Mon Sep 17 00:00:00 2001 From: Philip Sultanescu Date: Thu, 28 Feb 2019 05:11:37 +0100 Subject: [PATCH 3/4] fix(resizable.directive) try using any instead of object to avoid travis errors --- src/resizable.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resizable.directive.ts b/src/resizable.directive.ts index dab56cd..04d6c05 100644 --- a/src/resizable.directive.ts +++ b/src/resizable.directive.ts @@ -377,7 +377,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { * @hidden */ constructor( - @Inject(PLATFORM_ID) private platformId: object, + @Inject(PLATFORM_ID) private platformId: any, private renderer: Renderer2, public elm: ElementRef, private zone: NgZone From e17d632bcb003aebf1631097b42479e56b3185ad Mon Sep 17 00:00:00 2001 From: Philip Sultanescu Date: Thu, 28 Feb 2019 05:27:06 +0100 Subject: [PATCH 4/4] fix(resizable.directive) revert unnecessary checks --- src/resizable.directive.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/resizable.directive.ts b/src/resizable.directive.ts index 04d6c05..7c75111 100644 --- a/src/resizable.directive.ts +++ b/src/resizable.directive.ts @@ -692,10 +692,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { }; const resizeCursors = getResizeCursors(); const cursor = getResizeCursor(currentResize.edges, resizeCursors); - // browser check for angular universal, because it doesn't know what document is - if (isPlatformBrowser(this.platformId)) { - this.renderer.setStyle(document.body, 'cursor', cursor); - } + this.renderer.setStyle(document.body, 'cursor', cursor); this.setElementClass(this.elm, RESIZE_ACTIVE_CLASS, true); if (this.enableGhostResize) { currentResize.clonedNode = this.elm.nativeElement.cloneNode(true); @@ -761,10 +758,7 @@ export class ResizableDirective implements OnInit, OnChanges, OnDestroy { this.mouseup.subscribe(() => { if (currentResize) { this.renderer.removeClass(this.elm.nativeElement, RESIZE_ACTIVE_CLASS); - // browser check for angular universal, because it doesn't know what document is - if (isPlatformBrowser(this.platformId)) { - this.renderer.setStyle(document.body, 'cursor', ''); - } + this.renderer.setStyle(document.body, 'cursor', ''); this.renderer.setStyle(this.elm.nativeElement, 'cursor', ''); this.zone.run(() => { this.resizeEnd.emit({