mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 20:38:28 +00:00
Allow switching between pdfjs and native viewer
This commit is contained in:
parent
96696e745e
commit
9097fdd930
7 changed files with 48 additions and 11 deletions
|
@ -30,7 +30,7 @@ div.full-size(
|
|||
include ./pdf
|
||||
|
||||
.ui-layout-resizer-controls.synctex-controls(
|
||||
ng-show="!!pdf.url"
|
||||
ng-show="!!pdf.url && settings.pdfViewer == 'pdfjs' && showControls"
|
||||
ng-controller="PdfSynctexController"
|
||||
)
|
||||
a.btn.btn-default.btn-xs(
|
||||
|
|
|
@ -64,6 +64,15 @@ aside#left-menu.full-size(
|
|||
each size in ['10','11','12','13','14','16','20','24']
|
||||
option(value=size) #{size}px
|
||||
|
||||
.form-controls
|
||||
label(for="pdfViewer") PDF Viewer
|
||||
select.form-control(
|
||||
name="pdfViewer"
|
||||
ng-model="settings.pdfViewer"
|
||||
)
|
||||
option(value="pdfjs") Built-In
|
||||
option(value="native") Native
|
||||
|
||||
#left-menu-mask(
|
||||
ng-show="ui.leftMenuShown",
|
||||
ng-click="ui.leftMenuShown = false"
|
||||
|
|
|
@ -30,6 +30,7 @@ div.full-size(ng-controller="PdfController")
|
|||
.pdf-viewer(ng-show="pdf.url && pdf.view == 'pdf' && !pdf.failure && !pdf.timeout && !pdf.error")
|
||||
div(
|
||||
pdfjs
|
||||
ng-if="settings.pdfViewer == 'pdfjs'"
|
||||
pdf-src="pdf.url"
|
||||
key="project_id"
|
||||
resize-on="layout:main:resize,layout:pdf:resize"
|
||||
|
@ -37,6 +38,10 @@ div.full-size(ng-controller="PdfController")
|
|||
position="pdf.position"
|
||||
dbl-click-callback="syncToCode"
|
||||
)
|
||||
iframe(
|
||||
ng-src="{{ pdf.url }}"
|
||||
ng-if="settings.pdfViewer == 'native'"
|
||||
)
|
||||
|
||||
.pdf-uncompiled(ng-show="pdf.uncompiled && !pdf.compiling")
|
||||
|
|
||||
|
|
|
@ -10,10 +10,15 @@ define [
|
|||
spacing_open: 24
|
||||
spacing_closed: 24
|
||||
onresize: () =>
|
||||
console.log "Triggering", "layout:#{name}:resize", name
|
||||
scope.$broadcast "layout:#{name}:resize"
|
||||
repositionControls()
|
||||
#maskIframesOnResize: true
|
||||
onResize()
|
||||
maskIframesOnResize: scope.$eval(
|
||||
attrs.maskIframesOnResize or "false"
|
||||
)
|
||||
|
||||
onResize = () ->
|
||||
state = element.layout().readState()
|
||||
scope.$broadcast "layout:#{name}:resize", state
|
||||
repositionControls()
|
||||
|
||||
# Restore previously recorded state
|
||||
if (state = $.localStorage("layout.#{name}"))?
|
||||
|
|
|
@ -157,15 +157,15 @@ define [
|
|||
doc_id = ide.editorManager.getCurrentDocId()
|
||||
if !doc_id?
|
||||
deferred.reject()
|
||||
return deferred.promise()
|
||||
return deferred.promise
|
||||
doc = ide.fileTreeManager.findEntityById(doc_id)
|
||||
if !doc?
|
||||
deferred.reject()
|
||||
return deferred.promise()
|
||||
return deferred.promise
|
||||
path = ide.fileTreeManager.getEntityPath(doc)
|
||||
if !path?
|
||||
deferred.reject()
|
||||
return deferred.promise()
|
||||
return deferred.promise
|
||||
|
||||
# If the root file is folder/main.tex, then synctex sees the
|
||||
# path as folder/./main.tex
|
||||
|
@ -185,7 +185,6 @@ define [
|
|||
}
|
||||
})
|
||||
.success (data) ->
|
||||
console.log "SYNCTEX RESPONSE", data
|
||||
deferred.resolve(data.pdf or [])
|
||||
.error (error) ->
|
||||
deferred.reject(error)
|
||||
|
@ -196,7 +195,7 @@ define [
|
|||
deferred = $q.defer()
|
||||
if !position?
|
||||
deferred.reject()
|
||||
return deferred.promise()
|
||||
return deferred.promise
|
||||
|
||||
# It's not clear exactly where we should sync to if it wasn't directly
|
||||
# clicked on, but a little bit down from the very top seems best.
|
||||
|
@ -213,7 +212,6 @@ define [
|
|||
}
|
||||
})
|
||||
.success (data) ->
|
||||
console.log "SYNCTEX RESPONSE", data
|
||||
if data.code? and data.code.length > 0
|
||||
doc = ide.fileTreeManager.findEntityByPath(data.code[0].file)
|
||||
return if !doc?
|
||||
|
@ -227,6 +225,17 @@ define [
|
|||
]
|
||||
|
||||
App.controller "PdfSynctexController", ["$scope", "synctex", "ide", ($scope, synctex, ide) ->
|
||||
$scope.showControls = true
|
||||
$scope.$on "layout:pdf:resize", (event, data) ->
|
||||
console.log "RESIZE DATA", data.east
|
||||
if data.east.initClosed
|
||||
$scope.showControls = false
|
||||
else
|
||||
$scope.showControls = true
|
||||
setTimeout () ->
|
||||
$scope.$digest()
|
||||
, 0
|
||||
|
||||
$scope.syncToPdf = () ->
|
||||
synctex
|
||||
.syncToPdf($scope.editor.cursorPosition)
|
||||
|
|
|
@ -22,6 +22,10 @@ define [], () ->
|
|||
if autoComplete != oldAutoComplete
|
||||
@saveSettings({autoComplete: autoComplete})
|
||||
|
||||
@$scope.$watch "settings.pdfViewer", (pdfViewer, oldPdfViewer) =>
|
||||
if pdfViewer != oldPdfViewer
|
||||
@saveSettings({pdfViewer: pdfViewer})
|
||||
|
||||
@$scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
|
||||
return if @ignoreUpdates
|
||||
if oldLanguage? and language != oldLanguage
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
}
|
||||
|
||||
.pdf-viewer {
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
.pdfjs-viewer {
|
||||
.full-size;
|
||||
background-color: @gray-lighter;
|
||||
|
|
Loading…
Reference in a new issue