mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
comment out logs/unused code in pdf viewer
This commit is contained in:
parent
25521d1a26
commit
94448ed447
4 changed files with 72 additions and 78 deletions
|
@ -74,7 +74,7 @@ define [
|
|||
scope.$watch "pdfSrc", (url) ->
|
||||
if url
|
||||
scope.loading = true
|
||||
console.log 'pdfSrc =', url
|
||||
# console.log 'pdfSrc =', url
|
||||
initializePosition()
|
||||
flashControls()
|
||||
scope.$broadcast 'layout-ready'
|
||||
|
@ -87,8 +87,8 @@ define [
|
|||
# initializePosition()
|
||||
# flashControls()
|
||||
|
||||
scope.$watch "highlights", (areas) ->
|
||||
console.log 'got HIGHLIGHTS in pdfJS', areas
|
||||
#scope.$watch "highlights", (areas) ->
|
||||
# console.log 'got HIGHLIGHTS in pdfJS', areas
|
||||
|
||||
# return if !areas?
|
||||
# highlights = for area in areas or []
|
||||
|
@ -143,7 +143,7 @@ define [
|
|||
if attrs.resizeOn?
|
||||
for event in attrs.resizeOn.split(",")
|
||||
scope.$on event, (e) ->
|
||||
console.log 'got a resize event', event, e
|
||||
#console.log 'got a resize event', event, e
|
||||
|
||||
template: """
|
||||
<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>
|
||||
|
|
|
@ -60,8 +60,7 @@ define [
|
|||
updatePageSize scope.defaultPageSize
|
||||
|
||||
if scope.page.current
|
||||
console.log 'we must scroll to this page', scope.page.pageNum,
|
||||
'at position', scope.page.position
|
||||
# console.log 'we must scroll to this page', scope.page.pageNum, 'at position', scope.page.position
|
||||
renderPage()
|
||||
# this is the current page, we want to scroll it into view
|
||||
scope.document.getPdfViewport(scope.page.pageNum).then (viewport) ->
|
||||
|
@ -92,12 +91,12 @@ define [
|
|||
scope.$watch 'highlights', (highlights, oldVal) ->
|
||||
return unless highlights?
|
||||
return unless highlights.length > 0
|
||||
console.log 'got highlight watch in pdfPage', scope.page
|
||||
# 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
|
||||
# console.log 'adding highlight', h, viewport
|
||||
top = viewport.viewBox[3] - hl.v
|
||||
highlightsLayer.addHighlight viewport, hl.h, top, hl.width, hl.height
|
||||
$timeout () ->
|
||||
|
|
|
@ -3,8 +3,6 @@ define [
|
|||
], (App) ->
|
||||
# App = angular.module 'PDFRenderer', ['pdfAnnotations', 'pdfTextLayer']
|
||||
|
||||
console.log 'hello from Renderer'
|
||||
|
||||
App.factory 'PDFRenderer', ['$q', '$timeout', 'pdfAnnotations', 'pdfTextLayer', ($q, $timeout, pdfAnnotations, pdfTextLayer) ->
|
||||
|
||||
class PDFRenderer
|
||||
|
@ -18,7 +16,6 @@ define [
|
|||
@resetState()
|
||||
|
||||
resetState: () ->
|
||||
console.log 'reseting renderer state'
|
||||
@page = []
|
||||
@complete = []
|
||||
@timeout = []
|
||||
|
@ -112,7 +109,7 @@ define [
|
|||
scale = @scale
|
||||
|
||||
if (not scale?)
|
||||
console.log 'scale is undefined, returning'
|
||||
# console.log 'scale is undefined, returning'
|
||||
return
|
||||
|
||||
canvas = $('<canvas class="pdf-canvas-new"></canvas>')
|
||||
|
@ -167,10 +164,8 @@ define [
|
|||
}
|
||||
.then () ->
|
||||
page.getTextContent().then (textContent) ->
|
||||
console.log 'text content is', textContent
|
||||
textLayer.setTextContent textContent
|
||||
page.getAnnotations().then (annotations) ->
|
||||
console.log 'annotations are', annotations
|
||||
annotationsLayer.setAnnotations annotations
|
||||
|
||||
addSpinner: (element) ->
|
||||
|
|
|
@ -42,7 +42,7 @@ define [
|
|||
result.pdfViewport.width
|
||||
]
|
||||
$scope.destinations = result.destinations
|
||||
console.log 'resolved q.all, page size is', result
|
||||
# console.log 'resolved q.all, page size is', result
|
||||
$scope.numPages = result.numPages
|
||||
|
||||
@setScale = (scale, containerHeight, containerWidth) ->
|
||||
|
@ -68,45 +68,45 @@ define [
|
|||
numScale * $scope.pdfPageSize[0],
|
||||
numScale * $scope.pdfPageSize[1]
|
||||
]
|
||||
console.log 'in setScale result', $scope.scale.scale, $scope.defaultPageSize
|
||||
# console.log 'in setScale result', $scope.scale.scale, $scope.defaultPageSize
|
||||
|
||||
@redraw = (position) ->
|
||||
console.log 'in redraw'
|
||||
console.log 'reseting pages array for', $scope.numPages
|
||||
# console.log 'in redraw'
|
||||
# console.log 'reseting pages array for', $scope.numPages
|
||||
$scope.pages = ({
|
||||
pageNum: i + 1
|
||||
} for i in [0 .. $scope.numPages-1])
|
||||
if position? && position.page?
|
||||
console.log 'position is', position.page, position.offset
|
||||
console.log 'setting current page', position.page
|
||||
# console.log 'position is', position.page, position.offset
|
||||
# console.log 'setting current page', position.page
|
||||
pagenum = position.page
|
||||
$scope.pages[pagenum].current = true
|
||||
$scope.pages[pagenum].position = position
|
||||
|
||||
@zoomIn = () ->
|
||||
console.log 'zoom in'
|
||||
# console.log 'zoom in'
|
||||
newScale = $scope.scale.scale * 1.2
|
||||
$scope.forceScale = { scaleMode: 'scale_mode_value', scale: newScale }
|
||||
|
||||
@zoomOut = () ->
|
||||
console.log 'zoom out'
|
||||
# console.log 'zoom out'
|
||||
newScale = $scope.scale.scale / 1.2
|
||||
$scope.forceScale = { scaleMode: 'scale_mode_value', scale: newScale }
|
||||
|
||||
@fitWidth = () ->
|
||||
console.log 'fit width'
|
||||
# console.log 'fit width'
|
||||
$scope.forceScale = { scaleMode: 'scale_mode_fit_width' }
|
||||
|
||||
@fitHeight = () ->
|
||||
console.log 'fit height'
|
||||
# console.log 'fit height'
|
||||
$scope.forceScale = { scaleMode: 'scale_mode_fit_height' }
|
||||
|
||||
@checkPosition = () ->
|
||||
console.log 'check position'
|
||||
# console.log 'check position'
|
||||
$scope.forceCheck = ($scope.forceCheck || 0) + 1
|
||||
|
||||
@showRandomHighlights = () ->
|
||||
console.log 'show highlights'
|
||||
# console.log 'show highlights'
|
||||
$scope.highlights = [
|
||||
{
|
||||
page: 3
|
||||
|
@ -122,44 +122,44 @@ define [
|
|||
# bottom measured in pts)
|
||||
|
||||
@getPdfPosition = () ->
|
||||
console.log 'in getPdfPosition'
|
||||
# console.log 'in getPdfPosition'
|
||||
topPageIdx = 0
|
||||
topPage = $scope.pages[0]
|
||||
# find first visible page
|
||||
visible = $scope.pages.some (page, i) ->
|
||||
[topPageIdx, topPage] = [i, page] if page.visible
|
||||
if visible
|
||||
console.log 'found it', topPageIdx
|
||||
# console.log 'found it', topPageIdx
|
||||
else
|
||||
console.log 'CANNOT FIND TOP PAGE'
|
||||
|
||||
console.log 'top page is', topPage.pageNum, topPage.elemTop, topPage.elemBottom, topPage
|
||||
# console.log 'top page is', topPage.pageNum, topPage.elemTop, topPage.elemBottom, topPage
|
||||
top = topPage.elemTop
|
||||
bottom = topPage.elemBottom
|
||||
viewportTop = 0
|
||||
viewportHeight = $element.height()
|
||||
topVisible = (top >= viewportTop && top < viewportTop + viewportHeight)
|
||||
someContentVisible = (top < viewportTop && bottom > viewportTop)
|
||||
console.log 'in PdfListView', top, topVisible, someContentVisible, viewportTop
|
||||
# console.log 'in PdfListView', top, topVisible, someContentVisible, viewportTop
|
||||
if topVisible
|
||||
canvasOffset = 0
|
||||
else if someContentVisible
|
||||
canvasOffset = viewportTop - top
|
||||
else
|
||||
canvasOffset = null
|
||||
console.log 'pdfListview position = ', canvasOffset
|
||||
# console.log 'pdfListview position = ', canvasOffset
|
||||
# instead of using promise, check if size is known and revert to
|
||||
# default otherwise
|
||||
console.log 'looking up viewport', topPage.viewport, $scope.pdfViewport
|
||||
# console.log 'looking up viewport', topPage.viewport, $scope.pdfViewport
|
||||
if topPage.viewport
|
||||
viewport = topPage.viewport
|
||||
pdfOffset = viewport.convertToPdfPoint(0, canvasOffset);
|
||||
else
|
||||
console.log 'WARNING: had to default to global page size'
|
||||
# console.log 'WARNING: had to default to global page size'
|
||||
viewport = $scope.pdfViewport
|
||||
scaledOffset = canvasOffset / $scope.scale.scale
|
||||
pdfOffset = viewport.convertToPdfPoint(0, scaledOffset);
|
||||
console.log 'converted to offset = ', pdfOffset
|
||||
# console.log 'converted to offset = ', pdfOffset
|
||||
newPosition = {
|
||||
"page": topPageIdx,
|
||||
"offset" : { "top" : pdfOffset[1], "left": 0 }
|
||||
|
@ -167,23 +167,23 @@ define [
|
|||
return newPosition
|
||||
|
||||
@computeOffset = (page, position) ->
|
||||
console.log 'computing offset for', page, position
|
||||
# console.log 'computing offset for', page, position
|
||||
element = page.element
|
||||
pageTop = $(element).offset().top - $(element).parent().offset().top
|
||||
console.log('top of page scroll is', pageTop, 'vs', page.elemTop)
|
||||
console.log('inner height is', $(element).innerHeight())
|
||||
# console.log('top of page scroll is', pageTop, 'vs', page.elemTop)
|
||||
# console.log('inner height is', $(element).innerHeight())
|
||||
currentScroll = $(element).parent().scrollTop()
|
||||
offset = position.offset
|
||||
# convert offset to pixels
|
||||
return $scope.document.getPdfViewport(page.pageNum).then (viewport) ->
|
||||
page.viewport = viewport
|
||||
pageOffset = viewport.convertToViewportPoint(offset.left, offset.top)
|
||||
console.log 'addition offset =', pageOffset
|
||||
console.log 'total', pageTop + pageOffset[1]
|
||||
# console.log 'addition offset =', pageOffset
|
||||
# console.log 'total', pageTop + pageOffset[1]
|
||||
Math.round(pageTop + pageOffset[1] + currentScroll) ## 10 is margin
|
||||
|
||||
@setPdfPosition = (page, position) ->
|
||||
console.log 'required pdf Position is', position
|
||||
# console.log 'required pdf Position is', position
|
||||
@computeOffset(page, position).then (offset) ->
|
||||
$scope.pleaseScrollTo = offset
|
||||
$scope.position = position
|
||||
|
@ -208,12 +208,12 @@ define [
|
|||
<div data-pdf-page class='pdf-page-container page-container' ng-repeat='page in pages'></div>
|
||||
"""
|
||||
link: (scope, element, attrs, ctrl) ->
|
||||
console.log 'in pdfViewer element is', element
|
||||
console.log 'attrs', attrs
|
||||
# console.log 'in pdfViewer element is', element
|
||||
# console.log 'attrs', attrs
|
||||
layoutReady = $q.defer()
|
||||
layoutReady.notify 'waiting for layout'
|
||||
layoutReady.promise.then () ->
|
||||
console.log 'layoutReady was resolved'
|
||||
# console.log 'layoutReady was resolved'
|
||||
|
||||
# TODO can we combine this with scope.parentSize, need to finalize boxes
|
||||
updateContainer = () ->
|
||||
|
@ -224,18 +224,18 @@ define [
|
|||
]
|
||||
|
||||
doRescale = (scale) ->
|
||||
console.log 'doRescale', scale
|
||||
# console.log 'doRescale', scale
|
||||
origposition = angular.copy scope.position
|
||||
console.log 'origposition', origposition
|
||||
# console.log 'origposition', origposition
|
||||
layoutReady.promise.then () ->
|
||||
[h, w] = [element.innerHeight(), element.width()]
|
||||
console.log 'in promise', h, w
|
||||
# console.log 'in promise', h, w
|
||||
ctrl.setScale(scale, h, w).then () ->
|
||||
ctrl.redraw(origposition)
|
||||
|
||||
scope.$on 'layout-ready', () ->
|
||||
console.log 'GOT LAYOUT READY EVENT'
|
||||
console.log 'calling refresh'
|
||||
# console.log 'GOT LAYOUT READY EVENT'
|
||||
# console.log 'calling refresh'
|
||||
updateContainer()
|
||||
layoutReady.resolve 'layout is ready'
|
||||
scope.parentSize = [
|
||||
|
@ -245,7 +245,7 @@ define [
|
|||
#scope.$apply()
|
||||
|
||||
scope.$on 'layout:pdf:resize', () ->
|
||||
console.log 'GOT LAYOUT-RESIZE EVENT'
|
||||
# console.log 'GOT LAYOUT-RESIZE EVENT'
|
||||
scope.parentSize = [
|
||||
element.innerHeight(),
|
||||
element.innerWidth()
|
||||
|
@ -253,7 +253,7 @@ define [
|
|||
#scope.$apply()
|
||||
|
||||
element.on 'scroll', () ->
|
||||
console.log 'scroll detected', scope.adjustingScroll
|
||||
# console.log 'scroll detected', scope.adjustingScroll
|
||||
updateContainer()
|
||||
scope.$apply()
|
||||
#console.log 'pdfposition', element.parent().scrollTop()
|
||||
|
@ -262,11 +262,11 @@ define [
|
|||
return
|
||||
#console.log 'not from auto scroll'
|
||||
scope.position = ctrl.getPdfPosition()
|
||||
console.log 'position is', scope.position.page, scope.position.offset
|
||||
# console.log 'position is', scope.position.page, scope.position.offset
|
||||
scope.$apply()
|
||||
|
||||
scope.$watch 'pdfSrc', (newVal, oldVal) ->
|
||||
console.log 'loading pdf', newVal, oldVal
|
||||
# console.log 'loading pdf', newVal, oldVal
|
||||
return unless newVal?
|
||||
ctrl.load()
|
||||
# trigger a redraw
|
||||
|
@ -275,38 +275,38 @@ define [
|
|||
scope.$watch 'scale', (newVal, oldVal) ->
|
||||
# no need to set scale when initialising, done in pdfSrc
|
||||
return if newVal == oldVal
|
||||
console.log 'XXX calling Setscale in scale watch'
|
||||
# console.log 'XXX calling Setscale in scale watch'
|
||||
doRescale newVal
|
||||
|
||||
scope.$watch 'forceScale', (newVal, oldVal) ->
|
||||
console.log 'got change in numscale watcher', newVal, oldVal
|
||||
# console.log 'got change in numscale watcher', newVal, oldVal
|
||||
return unless newVal?
|
||||
doRescale newVal
|
||||
|
||||
scope.$watch 'position', (newVal, oldVal) ->
|
||||
console.log 'got change in position watcher', newVal, oldVal
|
||||
# scope.$watch 'position', (newVal, oldVal) ->
|
||||
# console.log 'got change in position watcher', newVal, oldVal
|
||||
|
||||
scope.$watch 'forceCheck', (newVal, oldVal) ->
|
||||
console.log 'forceCheck', newVal, oldVal
|
||||
# console.log 'forceCheck', newVal, oldVal
|
||||
return unless newVal?
|
||||
scope.adjustingScroll = true # temporarily disable scroll
|
||||
doRescale scope.scale
|
||||
|
||||
scope.$watch('parentSize', (newVal, oldVal) ->
|
||||
console.log 'XXX in parentSize watch', newVal, oldVal
|
||||
# console.log 'XXX in parentSize watch', newVal, oldVal
|
||||
if newVal == oldVal
|
||||
console.log 'returning because old and new are the same'
|
||||
# console.log 'returning because old and new are the same'
|
||||
return
|
||||
return unless oldVal?
|
||||
console.log 'XXX calling setScale in parentSize watcher'
|
||||
# console.log 'XXX calling setScale in parentSize watcher'
|
||||
doRescale scope.scale
|
||||
, true)
|
||||
|
||||
scope.$watch 'elementWidth', (newVal, oldVal) ->
|
||||
console.log '*** watch INTERVAL element width is', newVal, oldVal
|
||||
# scope.$watch 'elementWidth', (newVal, oldVal) ->
|
||||
# console.log '*** watch INTERVAL element width is', newVal, oldVal
|
||||
|
||||
scope.$watch 'pleaseScrollTo', (newVal, oldVal) ->
|
||||
console.log 'got request to ScrollTo', newVal, 'oldVal', oldVal
|
||||
# console.log 'got request to ScrollTo', newVal, 'oldVal', oldVal
|
||||
return unless newVal?
|
||||
scope.adjustingScroll = true # temporarily disable scroll
|
||||
# handler while we reposition
|
||||
|
@ -314,38 +314,38 @@ define [
|
|||
scope.pleaseScrollTo = undefined
|
||||
|
||||
scope.$watch 'pleaseJumpTo', (newPosition, oldPosition) ->
|
||||
console.log 'in 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
|
||||
# console.log 'got request to navigate to', newVal, 'oldVal', oldVal
|
||||
scope.navigateTo = undefined
|
||||
console.log 'navigate to', newVal
|
||||
console.log 'look up page num'
|
||||
# console.log 'navigate to', newVal
|
||||
# console.log 'look up page num'
|
||||
scope.loaded.then () ->
|
||||
console.log 'destinations are', scope.destinations
|
||||
# console.log 'destinations are', scope.destinations
|
||||
r = scope.destinations[newVal.dest]
|
||||
console.log 'need to go to', r
|
||||
console.log 'page ref is', r[0]
|
||||
# console.log 'need to go to', r
|
||||
# console.log 'page ref is', r[0]
|
||||
scope.document.getPageIndex(r[0]).then (pidx) ->
|
||||
console.log 'page num is', pidx
|
||||
# console.log 'page num is', pidx
|
||||
page = scope.pages[pidx]
|
||||
scope.document.getPdfViewport(page.pageNum).then (viewport) ->
|
||||
console.log 'got viewport', viewport
|
||||
#console.log 'got viewport', viewport
|
||||
coords = viewport.convertToViewportPoint r[2], r[3]
|
||||
console.log 'viewport position', coords
|
||||
console.log 'r is', r, 'r[1]', r[1], 'r[1].name', r[1].name
|
||||
#console.log 'viewport position', coords
|
||||
#console.log 'r is', r, 'r[1]', r[1], 'r[1].name', r[1].name
|
||||
if r[1].name == 'XYZ'
|
||||
console.log 'XYZ:', r[2], r[3]
|
||||
#console.log 'XYZ:', r[2], r[3]
|
||||
newPosition = {page: pidx, offset: {top: r[3], left: r[2]}}
|
||||
ctrl.setPdfPosition scope.pages[pidx], newPosition # XXX?
|
||||
|
||||
scope.$watch "highlights", (areas) ->
|
||||
console.log 'got HIGHLIGHTS in pdfViewer', areas
|
||||
# console.log 'got HIGHLIGHTS in pdfViewer', areas
|
||||
return if !areas?
|
||||
console.log 'areas are', areas
|
||||
#console.log 'areas are', areas
|
||||
highlights = for area in areas or []
|
||||
{
|
||||
page: area.page - 1
|
||||
|
@ -355,7 +355,7 @@ define [
|
|||
height: area.height
|
||||
width: area.width
|
||||
}
|
||||
console.log 'highlights', highlights
|
||||
#console.log 'highlights', highlights
|
||||
|
||||
return if !highlights.length
|
||||
|
||||
|
|
Loading…
Reference in a new issue