mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
57 lines
1.3 KiB
CoffeeScript
57 lines
1.3 KiB
CoffeeScript
define [
|
|
"base"
|
|
], (App) ->
|
|
|
|
# uses the PDFJS text layer renderer to provide invisible overlayed
|
|
# text for searching
|
|
|
|
App.factory 'pdfTextLayer', [ () ->
|
|
|
|
class pdfTextLayer
|
|
|
|
constructor: (options) ->
|
|
@textLayerDiv = options.textLayerDiv
|
|
@divContentDone = false
|
|
@viewport = options.viewport
|
|
@textDivs = []
|
|
@renderer = options.renderer
|
|
@renderingDone = false
|
|
|
|
render: (timeout) ->
|
|
if @renderingDone or not @divContentDone
|
|
return
|
|
|
|
if @textLayerRenderTask?
|
|
@textLayerRenderTask.cancel()
|
|
@textLayerRenderTask = null
|
|
|
|
@textDivs = []
|
|
textLayerFrag = document.createDocumentFragment()
|
|
|
|
@textLayerRenderTask = @renderer {
|
|
textContent: this.textContent,
|
|
container: textLayerFrag,
|
|
viewport: this.viewport,
|
|
textDivs: this.textDivs,
|
|
timeout: timeout,
|
|
enhanceTextSelection: this.enhanceTextSelection,
|
|
}
|
|
|
|
textLayerSuccess = () =>
|
|
@textLayerDiv.appendChild(textLayerFrag)
|
|
@renderingDone = true
|
|
|
|
textLayerFailure = () ->
|
|
return # canceled or failed to render text layer -- skipping errors
|
|
|
|
@textLayerRenderTask.promise.then(textLayerSuccess, textLayerFailure)
|
|
|
|
setTextContent: (textContent) ->
|
|
if (@textLayerRenderTask)
|
|
@textLayerRenderTask.cancel();
|
|
@textLayerRenderTask = null;
|
|
|
|
@textContent = textContent;
|
|
@divContentDone = true;
|
|
|
|
]
|