From ba49621e79c6f2c03256144c27703c378d60f7f1 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Tue, 9 Jan 2018 11:30:11 +0300 Subject: [PATCH] Update perfect scrollbar on document click... This isn't the most elegant solution but there is no other way of knowing when the contents of the scrollable container changes. Therefore, we update scrollbars on every document click. --- .../fuse-perfect-scrollbar.directive.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/core/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts b/src/app/core/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts index 6d3eed11..9156f2c3 100644 --- a/src/app/core/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts +++ b/src/app/core/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive.ts @@ -1,8 +1,8 @@ -import { AfterViewInit, Directive, ElementRef, OnDestroy, OnInit } from '@angular/core'; -import PerfectScrollbar from 'perfect-scrollbar'; +import { AfterViewInit, Directive, ElementRef, HostListener, OnDestroy } from '@angular/core'; import { FuseConfigService } from '../../services/config.service'; import { Subscription } from 'rxjs/Subscription'; import { Platform } from '@angular/cdk/platform'; +import PerfectScrollbar from 'perfect-scrollbar'; @Directive({ selector: '[fusePerfectScrollbar]' @@ -13,7 +13,7 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy isDisableCustomScrollbars = false; isMobile = false; isInitialized = true; - ps; + ps: PerfectScrollbar; constructor( public element: ElementRef, @@ -62,6 +62,21 @@ export class FusePerfectScrollbarDirective implements AfterViewInit, OnDestroy this.ps.destroy(); } + @HostListener('document:click', ['$event']) + documentClick(event: Event): void + { + if ( !this.isInitialized || !this.ps ) + { + return; + } + + // Update the scrollbar on document click.. + // This isn't the most elegant solution but there is no other way + // of knowing when the contents of the scrollable container changes. + // Therefore, we update scrollbars on every document click. + this.ps.update(); + } + update() { if ( !this.isInitialized )