From ea310f0248c6efc322d7071a2b8c83ee32143309 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 27 Nov 2014 16:58:38 +0000 Subject: [PATCH] highlights/dblclick in pdfng - work in progress --- .../coffee/ide/pdfng/directives/pdfJs.coffee | 23 +++--- .../ide/pdfng/directives/pdfViewer.coffee | 72 ++++++++++--------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee b/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee index 3adebce715..bf21d1342d 100644 --- a/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee +++ b/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee @@ -50,6 +50,7 @@ define [ # pdfListView.listView.pageHeightOffset = 20 scope.loading = false + scope.pleaseJumpTo = {} scope.scale = {} initializedPosition = false initializePosition = () -> @@ -80,12 +81,12 @@ define [ # scope.position = pdfListView.getPdfPosition(true) onDoubleClick = (e) -> + console.log 'double click event' scope.dblClickCallback?(page: e.page, offset: { top: e.y, left: e.x }) scope.$watch "pdfSrc", (url) -> if url scope.loading = true - scope.progress = 0 console.log 'pdfSrc =', url initializePosition() flashControls() @@ -100,10 +101,11 @@ define [ # flashControls() scope.$watch "highlights", (areas) -> + console.log 'got HIGHLIGHTS in pdfJS', areas return if !areas? highlights = for area in areas or [] { - page: area.page - 1 + page: area.page highlight: left: area.h top: area.v @@ -113,13 +115,14 @@ define [ if highlights.length > 0 first = highlights[0] - # pdfListView.setPdfPosition({ - # page: first.page - # offset: - # left: first.highlight.left - # top: first.highlight.top - 80 - # }, true) - + position = { + page: first.page + offset: + left: first.highlight.left + top: first.highlight.top - 80 + } + console.log 'position is', position, 'in highlights' + scope.pleaseJumpTo = position # pdfListView.clearHighlights() # pdfListView.setHighlights(highlights, true) @@ -155,7 +158,7 @@ define [ console.log 'got a resize event', event, e template: """ -
+
- $logProvider.debugEnabled true -] - -console.log "HELLO" - app.controller 'pdfViewerController', ['$scope', '$q', 'PDFRenderer', '$element', 'pdfHighlights', ($scope, $q, PDFRenderer, $element, pdfHighlights) -> @load = () -> $scope.document = new PDFRenderer($scope.pdfSrc, { @@ -187,6 +181,7 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) -> "position": "=" "scale": "=" "dblClickCallback": "=" + "pleaseJumpTo": "=" } template: """
@@ -296,6 +291,11 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) -> $(element).scrollTop(newVal) scope.pleaseScrollTo = undefined + scope.$watch 'pleaseJumpTo', (newPosition, oldPosition) -> + console.log 'in pleaseJumpTo', newPosition, oldPosition + return unless newPosition? + ctrl.setPdfPosition scope.pages[newPosition.page-1], newPosition + scope.$watch 'navigateTo', (newVal, oldVal) -> return unless newVal? console.log 'got request to navigate to', newVal, 'oldVal', oldVal @@ -320,34 +320,42 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) -> ctrl.setPdfPosition scope.pages[pidx], newPosition scope.$watch "highlights", (areas) -> - return if !areas? - console.log 'areas are', areas - highlights = for area in areas or [] - { - page: area.page - 1 - highlight: - left: area.h - top: area.v - height: area.height - width: area.width - } - console.log 'highlights', highlights + console.log 'got HIGHLIGHTS in pdfViewer', areas + return if !areas? + console.log 'areas are', areas + highlights = for area in areas or [] + { + page: area.page - 1 + highlight: + left: area.h + top: area.v + height: area.height + width: area.width + } + console.log 'highlights', highlights - if highlights.length > 0 - first = highlights[0] - ctrl.setPdfPosition({ - page: first.page - offset: - left: first.highlight.left - top: first.highlight.top - 80 - }, true) + return if !highlights.length - # iterate over pages - # highlightsElement = $(element).find('.highlights-layer') - # highlightsLayer = new pdfHighlights({ - # highlights: element.highlights[0] - # viewport: viewport - # }) + first = highlights[0] + ctrl.setPdfPosition(scope.pages[first.page], { + page: scope.pages[first.page] + offset: + left: first.highlight.left + top: first.highlight.top - 80 + }) + + for h in highlights + console.log 'iterating highlights', h + page = scope.pages[h.page] + element = page.element + viewport = page.viewport + highlightsElement = $(element).find('.highlights-layer') + highlightsLayer = new pdfHighlights({ + highlights: highlightsElement + viewport: viewport + }) + k=h.highlight + highlightsLayer.addHighlight(k.left,k.top,k.width,k.height) #pdfListView.clearHighlights() #ctrl.setHighlights(highlights, true)