mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add spinners and classes for feedback on pdfng loading and rendering
This commit is contained in:
parent
89d63c4f44
commit
206e7db144
5 changed files with 57 additions and 20 deletions
|
@ -8,7 +8,7 @@ define [
|
||||||
require: '^pdfViewer',
|
require: '^pdfViewer',
|
||||||
template: '''
|
template: '''
|
||||||
<div class="plv-page-view page-view">
|
<div class="plv-page-view page-view">
|
||||||
<div class="pdf-canvas"></div>
|
<div class="pdf-canvas pdfng-empty"></div>
|
||||||
<div class="plv-text-layer text-layer"></div>
|
<div class="plv-text-layer text-layer"></div>
|
||||||
<div class="plv-annotations-layer annotations-layer"></div>
|
<div class="plv-annotations-layer annotations-layer"></div>
|
||||||
<div class="plv-highlights-layer highlights-layer"></div>
|
<div class="plv-highlights-layer highlights-layer"></div>
|
||||||
|
|
|
@ -3,7 +3,7 @@ define [
|
||||||
], (App) ->
|
], (App) ->
|
||||||
# App = angular.module 'PDFRenderer', ['pdfAnnotations', 'pdfTextLayer']
|
# App = angular.module 'PDFRenderer', ['pdfAnnotations', 'pdfTextLayer']
|
||||||
|
|
||||||
App.factory 'PDFRenderer', ['$q', '$timeout', 'pdfAnnotations', 'pdfTextLayer', ($q, $timeout, pdfAnnotations, pdfTextLayer) ->
|
App.factory 'PDFRenderer', ['$q', '$timeout', 'pdfAnnotations', 'pdfTextLayer', 'pdfSpinner', ($q, $timeout, pdfAnnotations, pdfTextLayer, pdfSpinner) ->
|
||||||
|
|
||||||
class PDFRenderer
|
class PDFRenderer
|
||||||
JOB_QUEUE_INTERVAL: 25
|
JOB_QUEUE_INTERVAL: 25
|
||||||
|
@ -14,6 +14,7 @@ define [
|
||||||
@scale = @options.scale || 1
|
@scale = @options.scale || 1
|
||||||
@document = $q.when(PDFJS.getDocument @url)
|
@document = $q.when(PDFJS.getDocument @url)
|
||||||
@navigateFn = @options.navigateFn
|
@navigateFn = @options.navigateFn
|
||||||
|
@spinner = new pdfSpinner
|
||||||
@resetState()
|
@resetState()
|
||||||
|
|
||||||
resetState: () ->
|
resetState: () ->
|
||||||
|
@ -59,7 +60,7 @@ define [
|
||||||
return if @complete[pagenum]
|
return if @complete[pagenum]
|
||||||
@renderQueue = @renderQueue.filter (q) ->
|
@renderQueue = @renderQueue.filter (q) ->
|
||||||
q.pagenum != pagenum
|
q.pagenum != pagenum
|
||||||
# @stopSpinner (element.canvas)
|
@spinner.stop(element.canvas)
|
||||||
|
|
||||||
triggerRenderQueue: (interval = @JOB_QUEUE_INTERVAL) ->
|
triggerRenderQueue: (interval = @JOB_QUEUE_INTERVAL) ->
|
||||||
$timeout () =>
|
$timeout () =>
|
||||||
|
@ -73,7 +74,6 @@ define [
|
||||||
@triggerRenderQueue(0)
|
@triggerRenderQueue(0)
|
||||||
|
|
||||||
renderPage: (element, pagenum) ->
|
renderPage: (element, pagenum) ->
|
||||||
viewport = $q.defer()
|
|
||||||
current = {
|
current = {
|
||||||
'element': element
|
'element': element
|
||||||
'pagenum': pagenum
|
'pagenum': pagenum
|
||||||
|
@ -93,7 +93,8 @@ define [
|
||||||
return
|
return
|
||||||
@jobs = @jobs + 1
|
@jobs = @jobs + 1
|
||||||
|
|
||||||
# @addSpinner(element.canvas)
|
element.canvas.addClass('pdfng-loading')
|
||||||
|
@spinner.add(element.canvas)
|
||||||
|
|
||||||
pageLoad = @getPage(pagenum)
|
pageLoad = @getPage(pagenum)
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ define [
|
||||||
# console.log 'scale is undefined, returning'
|
# console.log 'scale is undefined, returning'
|
||||||
return
|
return
|
||||||
|
|
||||||
canvas = $('<canvas class="pdf-canvas pdf-canvas-new"></canvas>')
|
canvas = $('<canvas class="pdf-canvas pdfng-rendering"></canvas>')
|
||||||
|
|
||||||
viewport = page.getViewport (scale)
|
viewport = page.getViewport (scale)
|
||||||
|
|
||||||
|
@ -160,27 +161,16 @@ define [
|
||||||
})
|
})
|
||||||
|
|
||||||
element.canvas.replaceWith(canvas)
|
element.canvas.replaceWith(canvas)
|
||||||
canvas.removeClass('pdf-canvas-new')
|
|
||||||
|
|
||||||
return @renderTask = page.render {
|
return @renderTask = page.render {
|
||||||
canvasContext: ctx
|
canvasContext: ctx
|
||||||
viewport: viewport
|
viewport: viewport
|
||||||
}
|
}
|
||||||
.then () ->
|
.then () ->
|
||||||
|
canvas.removeClass('pdfng-rendering')
|
||||||
page.getTextContent().then (textContent) ->
|
page.getTextContent().then (textContent) ->
|
||||||
textLayer.setTextContent textContent
|
textLayer.setTextContent textContent
|
||||||
page.getAnnotations().then (annotations) ->
|
page.getAnnotations().then (annotations) ->
|
||||||
annotationsLayer.setAnnotations annotations
|
annotationsLayer.setAnnotations annotations
|
||||||
|
|
||||||
addSpinner: (element) ->
|
|
||||||
h = element.height()
|
|
||||||
w = element.width()
|
|
||||||
size = Math.floor(0.5 * Math.min(h, w))
|
|
||||||
spinner = $('<div style="position: absolute; top: 50%; left:50%; transform: translateX(-50%) translateY(-50%); z-index: 2"><i class="fa fa-spinner fa-spin" style="color: #999"></i></div>')
|
|
||||||
spinner.css({'font-size' : size + 'px'})
|
|
||||||
element.append(spinner)
|
|
||||||
|
|
||||||
stopSpinner: (element) ->
|
|
||||||
element.find('.fa-spin').removeClass('fa-spin')
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
define [
|
||||||
|
"base"
|
||||||
|
], (App) ->
|
||||||
|
App.factory 'pdfSpinner', [() ->
|
||||||
|
|
||||||
|
class pdfSpinner
|
||||||
|
|
||||||
|
constructor: () ->
|
||||||
|
# handler for spinners
|
||||||
|
|
||||||
|
add: (element) ->
|
||||||
|
h = element.height()
|
||||||
|
w = element.width()
|
||||||
|
size = Math.floor(0.5 * Math.min(h, w))
|
||||||
|
spinner = $('<div class="pdfng-spinner" style="position: absolute; top: 50%; left:50%; transform: translateX(-50%) translateY(-50%);"><i class="fa fa-spinner fa-spin" style="color: #999"></i></div>')
|
||||||
|
spinner.css({'font-size' : size + 'px'})
|
||||||
|
element.append(spinner)
|
||||||
|
|
||||||
|
stop: (element) ->
|
||||||
|
element.find('.fa-spin').removeClass('fa-spin')
|
||||||
|
|
||||||
|
remove: (element) ->
|
||||||
|
element.find('.fa-spin').remove()
|
||||||
|
|
||||||
|
]
|
|
@ -5,6 +5,7 @@ define [
|
||||||
"ide/pdfng/directives/pdfHighlights"
|
"ide/pdfng/directives/pdfHighlights"
|
||||||
"ide/pdfng/directives/pdfRenderer"
|
"ide/pdfng/directives/pdfRenderer"
|
||||||
"ide/pdfng/directives/pdfPage"
|
"ide/pdfng/directives/pdfPage"
|
||||||
|
"ide/pdfng/directives/pdfSpinner"
|
||||||
"libs/pdf" # needs pdfjs-1.0.712, override the path in require.js to get it
|
"libs/pdf" # needs pdfjs-1.0.712, override the path in require.js to get it
|
||||||
], (
|
], (
|
||||||
App
|
App
|
||||||
|
@ -13,13 +14,16 @@ define [
|
||||||
pdfHighlights
|
pdfHighlights
|
||||||
pdfRenderer
|
pdfRenderer
|
||||||
pdfPage
|
pdfPage
|
||||||
|
pdfSpinner
|
||||||
pdf
|
pdf
|
||||||
) ->
|
) ->
|
||||||
|
|
||||||
# App = angular.module 'pdfViewerApp', ['pdfPage', 'PDFRenderer', 'pdfHighlights']
|
# App = angular.module 'pdfViewerApp', ['pdfPage', 'PDFRenderer', 'pdfHighlights']
|
||||||
|
|
||||||
App.controller 'pdfViewerController', ['$scope', '$q', '$timeout', 'PDFRenderer', '$element', 'pdfHighlights', ($scope, $q, $timeout, PDFRenderer, $element, pdfHighlights) ->
|
App.controller 'pdfViewerController', ['$scope', '$q', '$timeout', 'PDFRenderer', '$element', 'pdfHighlights', 'pdfSpinner', ($scope, $q, $timeout, PDFRenderer, $element, pdfHighlights, pdfSpinner) ->
|
||||||
@load = () ->
|
@load = () ->
|
||||||
|
$scope.pages = []
|
||||||
|
|
||||||
$scope.document = new PDFRenderer($scope.pdfSrc, {
|
$scope.document = new PDFRenderer($scope.pdfSrc, {
|
||||||
scale: 1,
|
scale: 1,
|
||||||
navigateFn: (ref) ->
|
navigateFn: (ref) ->
|
||||||
|
@ -199,7 +203,7 @@ define [
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
App.directive 'pdfViewer', ['$q', '$timeout', ($q, $timeout) ->
|
App.directive 'pdfViewer', ['$q', '$timeout', 'pdfSpinner', ($q, $timeout, pdfSpinner) ->
|
||||||
{
|
{
|
||||||
controller: 'pdfViewerController'
|
controller: 'pdfViewerController'
|
||||||
controllerAs: 'ctrl'
|
controllerAs: 'ctrl'
|
||||||
|
@ -216,6 +220,7 @@ define [
|
||||||
link: (scope, element, attrs, ctrl) ->
|
link: (scope, element, attrs, ctrl) ->
|
||||||
# console.log 'in pdfViewer element is', element
|
# console.log 'in pdfViewer element is', element
|
||||||
# console.log 'attrs', attrs
|
# console.log 'attrs', attrs
|
||||||
|
spinner = new pdfSpinner
|
||||||
layoutReady = $q.defer()
|
layoutReady = $q.defer()
|
||||||
layoutReady.notify 'waiting for layout'
|
layoutReady.notify 'waiting for layout'
|
||||||
layoutReady.promise.then () ->
|
layoutReady.promise.then () ->
|
||||||
|
@ -237,12 +242,20 @@ define [
|
||||||
[h, w] = [element.innerHeight(), element.width()]
|
[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.setScale(scale, h, w).then () ->
|
||||||
|
spinner.remove(element)
|
||||||
ctrl.redraw(origposition)
|
ctrl.redraw(origposition)
|
||||||
|
|
||||||
scope.$on 'layout-ready', () ->
|
scope.$on 'layout-ready', () ->
|
||||||
# console.log 'GOT LAYOUT READY EVENT'
|
# console.log 'GOT LAYOUT READY EVENT'
|
||||||
# console.log 'calling refresh'
|
# console.log 'calling refresh'
|
||||||
|
if element.height() == 0 or element.width() == 0
|
||||||
|
# if element is zero-sized keep checking until it is ready
|
||||||
|
$timeout () ->
|
||||||
|
scope.$broadcast 'layout-ready'
|
||||||
|
, 250
|
||||||
|
return
|
||||||
updateContainer()
|
updateContainer()
|
||||||
|
spinner.add(element)
|
||||||
layoutReady.resolve 'layout is ready'
|
layoutReady.resolve 'layout is ready'
|
||||||
scope.parentSize = [
|
scope.parentSize = [
|
||||||
element.innerHeight(),
|
element.innerHeight(),
|
||||||
|
|
|
@ -27,6 +27,15 @@
|
||||||
background: white;
|
background: white;
|
||||||
box-shadow: black 0px 0px 10px;
|
box-shadow: black 0px 0px 10px;
|
||||||
}
|
}
|
||||||
|
div.pdf-canvas.pdfng-empty {
|
||||||
|
background-color: @gray-light;
|
||||||
|
}
|
||||||
|
div.pdf-canvas.pdfng-loading {
|
||||||
|
background-color: @gray-lighter;
|
||||||
|
}
|
||||||
|
canvas.pdf-canvas.pdfng-rendering {
|
||||||
|
box-shadow: red 0px 0px 10px;
|
||||||
|
}
|
||||||
.page-container {
|
.page-container {
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
Loading…
Reference in a new issue