mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
highlights working for moving to position in pdf from source
This commit is contained in:
parent
ea310f0248
commit
f914c75712
4 changed files with 51 additions and 49 deletions
|
@ -4,12 +4,11 @@ app.factory 'pdfHighlights', [ () ->
|
|||
class pdfHighlights
|
||||
|
||||
constructor: (options) ->
|
||||
@highlightsLayerDiv = options.highlights
|
||||
@viewport = options.viewport
|
||||
@highlightsLayerDiv = options.highlights[0]
|
||||
@highlightElements = []
|
||||
|
||||
addHighlight: (left, top, width, height) ->
|
||||
rect = @viewport.convertToViewportRectangle([left, top, left + width, top + height])
|
||||
addHighlight: (viewport, left, top, width, height) ->
|
||||
rect = viewport.convertToViewportRectangle([left, top, left + width, top + height])
|
||||
rect = PDFJS.Util.normalizeRect(rect)
|
||||
element = document.createElement("div")
|
||||
element.style.left = Math.floor(rect[0]) + 'px'
|
||||
|
|
|
@ -102,27 +102,28 @@ define [
|
|||
|
||||
scope.$watch "highlights", (areas) ->
|
||||
console.log 'got HIGHLIGHTS in pdfJS', areas
|
||||
return if !areas?
|
||||
highlights = for area in areas or []
|
||||
{
|
||||
page: area.page
|
||||
highlight:
|
||||
left: area.h
|
||||
top: area.v
|
||||
height: area.height
|
||||
width: area.width
|
||||
}
|
||||
|
||||
if highlights.length > 0
|
||||
first = highlights[0]
|
||||
position = {
|
||||
page: first.page
|
||||
offset:
|
||||
left: first.highlight.left
|
||||
top: first.highlight.top - 80
|
||||
}
|
||||
console.log 'position is', position, 'in highlights'
|
||||
scope.pleaseJumpTo = position
|
||||
# return if !areas?
|
||||
# highlights = for area in areas or []
|
||||
# {
|
||||
# page: area.page
|
||||
# highlight:
|
||||
# left: area.h
|
||||
# top: area.v
|
||||
# height: area.height
|
||||
# width: area.width
|
||||
# }
|
||||
|
||||
# if highlights.length > 0
|
||||
# first = highlights[0]
|
||||
# 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)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
app = angular.module 'pdfPage', []
|
||||
app = angular.module 'pdfPage', ['pdfHighlights']
|
||||
|
||||
app.directive 'pdfPage', ['$timeout', ($timeout) ->
|
||||
app.directive 'pdfPage', ['$timeout', 'pdfHighlights', ($timeout, pdfHighlights) ->
|
||||
{
|
||||
require: '^pdfViewer',
|
||||
template: '''
|
||||
|
@ -78,5 +78,22 @@ app.directive 'pdfPage', ['$timeout', ($timeout) ->
|
|||
else if !newVisible && oldVisible
|
||||
pausePage()
|
||||
|
||||
highlightsLayer = new pdfHighlights({
|
||||
highlights: highlightsElement
|
||||
})
|
||||
|
||||
scope.$watch 'highlights', (highlights, oldVal) ->
|
||||
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
|
||||
scope.document.getPdfViewport(scope.page.pageNum).then (viewport) ->
|
||||
for hl in pageHighlights
|
||||
console.log 'adding highlight', h, viewport
|
||||
top = viewport.viewBox[3] - hl.v
|
||||
highlightsLayer.addHighlight viewport, hl.h, top, hl.width, hl.height
|
||||
$timeout () ->
|
||||
highlightsLayer.clearHighlights()
|
||||
, 1000
|
||||
|
||||
}
|
||||
]
|
||||
|
|
|
@ -325,7 +325,7 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
|
|||
console.log 'areas are', areas
|
||||
highlights = for area in areas or []
|
||||
{
|
||||
page: area.page - 1
|
||||
page: area.page
|
||||
highlight:
|
||||
left: area.h
|
||||
top: area.v
|
||||
|
@ -337,31 +337,16 @@ app.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
|
|||
return if !highlights.length
|
||||
|
||||
first = highlights[0]
|
||||
ctrl.setPdfPosition(scope.pages[first.page], {
|
||||
page: scope.pages[first.page]
|
||||
|
||||
scope.document.getPdfViewport(first.page).then (viewport) ->
|
||||
position = {
|
||||
page: first.page
|
||||
offset:
|
||||
left: first.highlight.left
|
||||
top: first.highlight.top - 80
|
||||
})
|
||||
top: viewport.viewBox[3] - first.highlight.top + first.highlight.height + 72
|
||||
}
|
||||
ctrl.setPdfPosition(scope.pages[first.page - 1], position)
|
||||
|
||||
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)
|
||||
|
||||
#setTimeout () =>
|
||||
# pdfListView.clearHighlights()
|
||||
#, 1000
|
||||
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue