support old and new pdf viewers depending on feature switch

This commit is contained in:
Brian Gough 2014-12-01 14:35:12 +00:00
parent 3fd8bfb221
commit 25bebe1104
5 changed files with 39 additions and 25 deletions

View file

@ -112,13 +112,20 @@ block content
- locals.suppressDefaultJs = true - locals.suppressDefaultJs = true
- var pdfPath = 'libs/pdf.worker.js' - // user.featureSwitches = {} // override
- if (user.featureSwitches && user.featureSwitches.pdfng) { pdfPath = 'libs/pdfjs-1.0.712/pdf.worker.js'; } - var usePdfNG = user.featureSwitches && user.featureSwitches.pdfng;
- var pdfPath = 'libs/pdf.worker.js';
- if (usePdfNG) { pdfPath = 'libs/pdfjs-1.0.712/pdf.worker.js'; }
- var fingerprintedPath = fingerprint(jsPath+pdfPath) - var fingerprintedPath = fingerprint(jsPath+pdfPath)
- var pdfJsWorkerPath = jsPath+pdfPath+'?fingerprint='+fingerprintedPath - var pdfJsWorkerPath = jsPath+pdfPath+'?fingerprint='+fingerprintedPath
script(type='text/javascript'). script(type='text/javascript').
window.pdfJsWorkerPath = "#{pdfJsWorkerPath}"; window.pdfJsWorkerPath = "#{pdfJsWorkerPath}";
// when using pdfng we need a different pdfjs version
if usePdfNG
script(type='text/javascript').
window.requirejs.paths['libs/pdf'] = 'libs/pdfjs-1.0.712/pdf'
script( script(
data-main=jsPath+"ide.js", data-main=jsPath+"ide.js",
baseurl=jsPath, baseurl=jsPath,

View file

@ -58,9 +58,13 @@ div.full-size.pdf(ng-controller="PdfController")
i.split-screen i.split-screen
.pdf-viewer(ng-show="pdf.url && pdf.view == 'pdf' && !pdf.failure && !pdf.timeout && !pdf.error") .pdf-viewer(ng-show="pdf.url && pdf.view == 'pdf' && !pdf.failure && !pdf.timeout && !pdf.error")
- // user.featureSwitches = {} // override
- var usePdfNG = user.featureSwitches && user.featureSwitches.pdfng;
- console.log('USER FEATURE SWITCHES', user.featureSwitches, usePdfNG);
if !usePdfNG
div( div(
pdfjs pdfjs
ng-if="settings.pdfViewer == 'pdfjs' && !(user.featureSwitches && user.featureSwitches.pdfng)" ng-if="settings.pdfViewer == 'pdfjs'"
pdf-src="pdf.url" pdf-src="pdf.url"
key="{{ project_id }}" key="{{ project_id }}"
resize-on="layout:main:resize,layout:pdf:resize" resize-on="layout:main:resize,layout:pdf:resize"
@ -68,9 +72,10 @@ div.full-size.pdf(ng-controller="PdfController")
position="pdf.position" position="pdf.position"
dbl-click-callback="syncToCode" dbl-click-callback="syncToCode"
) )
else
div( div(
pdfng pdfng
ng-if="settings.pdfViewer == 'pdfjs' && user.featureSwitches && user.featureSwitches.pdfng" ng-if="settings.pdfViewer == 'pdfjs'"
pdf-src="pdf.url" pdf-src="pdf.url"
key="{{ project_id }}" key="{{ project_id }}"
resize-on="layout:main:resize,layout:pdf:resize" resize-on="layout:main:resize,layout:pdf:resize"
@ -78,6 +83,7 @@ div.full-size.pdf(ng-controller="PdfController")
position="pdf.position" position="pdf.position"
dbl-click-callback="syncToCode" dbl-click-callback="syncToCode"
) )
iframe( iframe(
ng-src="{{ pdf.url }}" ng-src="{{ pdf.url }}"
ng-if="settings.pdfViewer == 'native'" ng-if="settings.pdfViewer == 'native'"

View file

@ -6,7 +6,7 @@ define [
"ide/online-users/OnlineUsersManager" "ide/online-users/OnlineUsersManager"
"ide/track-changes/TrackChangesManager" "ide/track-changes/TrackChangesManager"
"ide/permissions/PermissionsManager" "ide/permissions/PermissionsManager"
"ide/pdfng/PdfManager" "ide/pdf/PdfManager"
"ide/binary-files/BinaryFilesManager" "ide/binary-files/BinaryFilesManager"
"ide/settings/index" "ide/settings/index"
"ide/share/index" "ide/share/index"

View file

@ -2,6 +2,7 @@ define [
"ide/pdf/controllers/PdfController" "ide/pdf/controllers/PdfController"
"ide/pdf/controllers/PdfViewToggleController" "ide/pdf/controllers/PdfViewToggleController"
"ide/pdf/directives/pdfJs" "ide/pdf/directives/pdfJs"
"ide/pdfng/directives/pdfJs" # alternative incremental viewer
], () -> ], () ->
class PdfManager class PdfManager
constructor: (@ide, @$scope) -> constructor: (@ide, @$scope) ->

View file

@ -5,7 +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"
"libs/pdfjs-1.0.712/pdf" "libs/pdf" # needs pdfjs-1.0.712, override the path in require.js to get it
], ( ], (
App App
pdfTextLayer pdfTextLayer