highlights/dblclick in pdfng - work in progress

This commit is contained in:
Brian Gough 2014-11-27 16:58:38 +00:00
parent 3694bea956
commit ea310f0248
2 changed files with 53 additions and 42 deletions

View file

@ -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: """
<div data-pdf-viewer class="pdfjs-viewer" pdf-src='pdfSrc' position='position' scale='scale'></div>
<div data-pdf-viewer class="pdfjs-viewer" pdf-src='pdfSrc' position='position' scale='scale' highlights='highlights' dbl-click-callback='dblClickCallback' please-jump-to='pleaseJumpTo'></div>
<div class="pdfjs-controls" ng-class="{'flash': flashControls }">
<div class="btn-group">
<a href

View file

@ -1,11 +1,5 @@
app = angular.module 'pdfViewerApp', ['pdfPage', 'PDFRenderer', 'pdfHighlights']
app.config [ "$logProvider", ($logProvider) ->
$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: """
<div data-pdf-page class='pdf-page-container page-container' ng-repeat='page in pages'></div>
@ -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,6 +320,7 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
ctrl.setPdfPosition scope.pages[pidx], newPosition
scope.$watch "highlights", (areas) ->
console.log 'got HIGHLIGHTS in pdfViewer', areas
return if !areas?
console.log 'areas are', areas
highlights = for area in areas or []
@ -333,21 +334,28 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
}
console.log 'highlights', highlights
if highlights.length > 0
return if !highlights.length
first = highlights[0]
ctrl.setPdfPosition({
page: first.page
ctrl.setPdfPosition(scope.pages[first.page], {
page: scope.pages[first.page]
offset:
left: first.highlight.left
top: first.highlight.top - 80
}, true)
})
# iterate over pages
# highlightsElement = $(element).find('.highlights-layer')
# highlightsLayer = new pdfHighlights({
# highlights: element.highlights[0]
# viewport: viewport
# })
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)