Browse Source

Move the `Preferences` initialization/fetching code to the top of `PDFViewerApplication.initialize`, to enable using them when initializing the viewer components

Jonas Jenwald 9 years ago
parent
commit
ffb876fdf4
  1. 126
      web/app.js

126
web/app.js

@ -183,6 +183,69 @@ var PDFViewerApplication = { @@ -183,6 +183,69 @@ var PDFViewerApplication = {
// called once when the document is loaded
initialize: function pdfViewInitialize(appConfig) {
var self = this;
var PDFJS = pdfjsLib.PDFJS;
Preferences.initialize();
this.preferences = Preferences;
// Fetch the `Preferences` first, so that they can be used below when the
// various viewer components are initialized.
var preferencesPromise = Promise.all([
Preferences.get('enableWebGL').then(function resolved(value) {
PDFJS.disableWebGL = !value;
}),
Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
self.preferenceSidebarViewOnLoad = value;
}),
Preferences.get('pdfBugEnabled').then(function resolved(value) {
self.preferencePdfBugEnabled = value;
}),
Preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
self.preferenceShowPreviousViewOnLoad = value;
}),
Preferences.get('defaultZoomValue').then(function resolved(value) {
self.preferenceDefaultZoomValue = value;
}),
Preferences.get('disableTextLayer').then(function resolved(value) {
if (PDFJS.disableTextLayer === true) {
return;
}
PDFJS.disableTextLayer = value;
}),
Preferences.get('disableRange').then(function resolved(value) {
if (PDFJS.disableRange === true) {
return;
}
PDFJS.disableRange = value;
}),
Preferences.get('disableStream').then(function resolved(value) {
if (PDFJS.disableStream === true) {
return;
}
PDFJS.disableStream = value;
}),
Preferences.get('disableAutoFetch').then(function resolved(value) {
PDFJS.disableAutoFetch = value;
}),
Preferences.get('disableFontFace').then(function resolved(value) {
if (PDFJS.disableFontFace === true) {
return;
}
PDFJS.disableFontFace = value;
}),
Preferences.get('useOnlyCssZoom').then(function resolved(value) {
PDFJS.useOnlyCssZoom = value;
}),
Preferences.get('externalLinkTarget').then(function resolved(value) {
if (PDFJS.isExternalLinkTargetSet()) {
return;
}
PDFJS.externalLinkTarget = value;
}),
// TODO move more preferences and other async stuff here
]).catch(function (reason) { });
var initializedPromise = preferencesPromise.then(function () {
configure(pdfjsLib.PDFJS);
this.appConfig = appConfig;
@ -224,9 +287,6 @@ var PDFViewerApplication = { @@ -224,9 +287,6 @@ var PDFViewerApplication = {
});
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
Preferences.initialize();
this.preferences = Preferences;
this.pdfHistory = new PDFHistory({
linkService: pdfLinkService,
eventBus: this.eventBus
@ -242,7 +302,8 @@ var PDFViewerApplication = { @@ -242,7 +302,8 @@ var PDFViewerApplication = {
}
this.findBar.updateResultsCount(matchCount);
}.bind(this);
this.findController.onUpdateState = function (state, previous, matchCount) {
this.findController.onUpdateState = function (state, previous,
matchCount) {
if (this.supportsIntegratedFind) {
this.externalServices.updateFindControlState(
{result: state, findPrevious: previous});
@ -305,62 +366,7 @@ var PDFViewerApplication = { @@ -305,62 +366,7 @@ var PDFViewerApplication = {
this.pdfSidebar = new PDFSidebar(sidebarConfig);
this.pdfSidebar.onToggled = this.forceRendering.bind(this);
var self = this;
var PDFJS = pdfjsLib.PDFJS;
var initializedPromise = Promise.all([
Preferences.get('enableWebGL').then(function resolved(value) {
PDFJS.disableWebGL = !value;
}),
Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
self.preferenceSidebarViewOnLoad = value;
}),
Preferences.get('pdfBugEnabled').then(function resolved(value) {
self.preferencePdfBugEnabled = value;
}),
Preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
self.preferenceShowPreviousViewOnLoad = value;
}),
Preferences.get('defaultZoomValue').then(function resolved(value) {
self.preferenceDefaultZoomValue = value;
}),
Preferences.get('disableTextLayer').then(function resolved(value) {
if (PDFJS.disableTextLayer === true) {
return;
}
PDFJS.disableTextLayer = value;
}),
Preferences.get('disableRange').then(function resolved(value) {
if (PDFJS.disableRange === true) {
return;
}
PDFJS.disableRange = value;
}),
Preferences.get('disableStream').then(function resolved(value) {
if (PDFJS.disableStream === true) {
return;
}
PDFJS.disableStream = value;
}),
Preferences.get('disableAutoFetch').then(function resolved(value) {
PDFJS.disableAutoFetch = value;
}),
Preferences.get('disableFontFace').then(function resolved(value) {
if (PDFJS.disableFontFace === true) {
return;
}
PDFJS.disableFontFace = value;
}),
Preferences.get('useOnlyCssZoom').then(function resolved(value) {
PDFJS.useOnlyCssZoom = value;
}),
Preferences.get('externalLinkTarget').then(function resolved(value) {
if (PDFJS.isExternalLinkTargetSet()) {
return;
}
PDFJS.externalLinkTarget = value;
}),
// TODO move more preferences and other async stuff here
]).catch(function (reason) { });
}.bind(this));
return initializedPromise.then(function () {
if (self.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) {

Loading…
Cancel
Save