From 4faac8806589f464b4fc0a6444d6b6830e91632a Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 4 Dec 2014 16:50:38 +0000 Subject: [PATCH] handle destroy event in pdf page view and remove pending timeouts --- .../coffee/ide/pdfng/directives/pdfPage.coffee | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/web/public/coffee/ide/pdfng/directives/pdfPage.coffee b/services/web/public/coffee/ide/pdfng/directives/pdfPage.coffee index 42238b80ea..5bc64249f4 100644 --- a/services/web/public/coffee/ide/pdfng/directives/pdfPage.coffee +++ b/services/web/public/coffee/ide/pdfng/directives/pdfPage.coffee @@ -89,6 +89,11 @@ define [ scope.$watch 'highlights', (highlights, oldVal) -> return unless highlights? return unless highlights.length > 0 + if scope.timeoutHandler + $timeout.cancel(scope.timeoutHandler) + highlightsLayer.clearHighlights() + scope.timeoutHandler + # console.log 'got highlight watch in pdfPage', scope.page pageHighlights = (h for h in highlights when h.page == scope.page.pageNum) return unless pageHighlights.length @@ -97,12 +102,15 @@ define [ # console.log 'adding highlight', h, viewport top = viewport.viewBox[3] - hl.v highlightsLayer.addHighlight viewport, hl.h, top, hl.width, hl.height - $timeout () -> + scope.timeoutHandler = $timeout () -> highlightsLayer.clearHighlights() + scope.timeoutHandler = null , 1000 scope.$on "$destroy", () -> - console.log 'in destroy handler, TODO need to clean up timeout/highlights' + if scope.timeoutHandler + $timeout.cancel(scope.timeoutHandler) + highlightsLayer.clearHighlights() } ]