mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
fix memory leaks for pdf viewers (#2316)
This commit is contained in:
committed by
Eugenio Romano
parent
b93cdc611c
commit
c418e428f4
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, HostListener, Input, OnChanges, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, HostListener, Input, OnChanges, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import { LogService } from 'ng2-alfresco-core';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
|
||||
@@ -32,7 +32,7 @@ declare let PDFJS: any;
|
||||
host: { 'class': 'adf-pdf-viewer' },
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class PdfViewerComponent implements OnChanges {
|
||||
export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
|
||||
@Input()
|
||||
urlFile: string;
|
||||
@@ -62,6 +62,8 @@ export class PdfViewerComponent implements OnChanges {
|
||||
|
||||
constructor(private renderingQueueServices: RenderingQueueServices,
|
||||
private logService: LogService) {
|
||||
// needed to preserve "this" context when setting as a global document event listener
|
||||
this.onDocumentScroll = this.onDocumentScroll.bind(this);
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
@@ -127,9 +129,7 @@ export class PdfViewerComponent implements OnChanges {
|
||||
let documentContainer = document.getElementById('viewer-pdf-container');
|
||||
let viewer: any = document.getElementById('viewer-viewerPdf');
|
||||
|
||||
window.document.addEventListener('scroll', (event) => {
|
||||
this.watchScroll(event.target);
|
||||
}, true);
|
||||
window.document.addEventListener('scroll', this.onDocumentScroll, true);
|
||||
|
||||
this.pdfViewer = new PDFJS.PDFViewer({
|
||||
container: documentContainer,
|
||||
@@ -142,6 +142,10 @@ export class PdfViewerComponent implements OnChanges {
|
||||
this.pdfViewer.setDocument(pdfDocument);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
window.document.removeEventListener('scroll', this.onDocumentScroll, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to scale the page current support implementation
|
||||
*
|
||||
@@ -397,4 +401,10 @@ export class PdfViewerComponent implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
onDocumentScroll(event: Event) {
|
||||
if (event && event.target) {
|
||||
this.watchScroll(event.target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user