vendor/assets/javascripts/generic/web/viewer.js in better-pdfjs-rails-1.6.380.5 vs vendor/assets/javascripts/generic/web/viewer.js in better-pdfjs-rails-1.6.422.0
- old
+ new
@@ -624,70 +624,10 @@
}
};
exports.DownloadManager = DownloadManager;
}));
(function (root, factory) {
- factory(root.pdfjsWebHandTool = {}, root.pdfjsWebGrabToPan, root.pdfjsWebPreferences);
- }(this, function (exports, grabToPan, preferences) {
- var GrabToPan = grabToPan.GrabToPan;
- var Preferences = preferences.Preferences;
- var HandTool = function HandToolClosure() {
- function HandTool(options) {
- this.container = options.container;
- this.eventBus = options.eventBus;
- this.wasActive = false;
- this.handTool = new GrabToPan({
- element: this.container,
- onActiveChanged: function (isActive) {
- this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
- }.bind(this)
- });
- this.eventBus.on('togglehandtool', this.toggle.bind(this));
- this.eventBus.on('localized', function (e) {
- Preferences.get('enableHandToolOnLoad').then(function resolved(value) {
- if (value) {
- this.handTool.activate();
- }
- }.bind(this), function rejected(reason) {
- });
- }.bind(this));
- this.eventBus.on('presentationmodechanged', function (e) {
- if (e.switchInProgress) {
- return;
- }
- if (e.active) {
- this.enterPresentationMode();
- } else {
- this.exitPresentationMode();
- }
- }.bind(this));
- }
- HandTool.prototype = {
- get isActive() {
- return !!this.handTool.active;
- },
- toggle: function HandTool_toggle() {
- this.handTool.toggle();
- },
- enterPresentationMode: function HandTool_enterPresentationMode() {
- if (this.isActive) {
- this.wasActive = true;
- this.handTool.deactivate();
- }
- },
- exitPresentationMode: function HandTool_exitPresentationMode() {
- if (this.wasActive) {
- this.wasActive = false;
- this.handTool.activate();
- }
- }
- };
- return HandTool;
- }();
- exports.HandTool = HandTool;
- }));
- (function (root, factory) {
factory(root.pdfjsWebPDFAttachmentViewer = {}, root.pdfjsWebPDFJS);
}(this, function (exports, pdfjsLib) {
var PDFAttachmentViewer = function PDFAttachmentViewerClosure() {
function PDFAttachmentViewer(options) {
this.attachments = null;
@@ -1630,10 +1570,72 @@
}
exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
exports.getGlobalEventBus = getGlobalEventBus;
}));
(function (root, factory) {
+ factory(root.pdfjsWebHandTool = {}, root.pdfjsWebGrabToPan, root.pdfjsWebPreferences, root.pdfjsWebUIUtils);
+ }(this, function (exports, grabToPan, preferences, uiUtils) {
+ var GrabToPan = grabToPan.GrabToPan;
+ var Preferences = preferences.Preferences;
+ var localized = uiUtils.localized;
+ var HandTool = function HandToolClosure() {
+ function HandTool(options) {
+ this.container = options.container;
+ this.eventBus = options.eventBus;
+ this.wasActive = false;
+ this.handTool = new GrabToPan({
+ element: this.container,
+ onActiveChanged: function (isActive) {
+ this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
+ }.bind(this)
+ });
+ this.eventBus.on('togglehandtool', this.toggle.bind(this));
+ Promise.all([
+ localized,
+ Preferences.get('enableHandToolOnLoad')
+ ]).then(function resolved(values) {
+ if (values[1] === true) {
+ this.handTool.activate();
+ }
+ }.bind(this)).catch(function rejected(reason) {
+ });
+ this.eventBus.on('presentationmodechanged', function (e) {
+ if (e.switchInProgress) {
+ return;
+ }
+ if (e.active) {
+ this.enterPresentationMode();
+ } else {
+ this.exitPresentationMode();
+ }
+ }.bind(this));
+ }
+ HandTool.prototype = {
+ get isActive() {
+ return !!this.handTool.active;
+ },
+ toggle: function HandTool_toggle() {
+ this.handTool.toggle();
+ },
+ enterPresentationMode: function HandTool_enterPresentationMode() {
+ if (this.isActive) {
+ this.wasActive = true;
+ this.handTool.deactivate();
+ }
+ },
+ exitPresentationMode: function HandTool_exitPresentationMode() {
+ if (this.wasActive) {
+ this.wasActive = false;
+ this.handTool.activate();
+ }
+ }
+ };
+ return HandTool;
+ }();
+ exports.HandTool = HandTool;
+ }));
+ (function (root, factory) {
factory(root.pdfjsWebPasswordPrompt = {}, root.pdfjsWebUIUtils, root.pdfjsWebOverlayManager, root.pdfjsWebPDFJS);
}(this, function (exports, uiUtils, overlayManager, pdfjsLib) {
var mozL10n = uiUtils.mozL10n;
var OverlayManager = overlayManager.OverlayManager;
var PasswordPrompt = function PasswordPromptClosure() {
@@ -2918,11 +2920,11 @@
toggleHandToolButton.firstElementChild.textContent = mozL10n.get('hand_tool_disable_label', null, 'Disable hand tool');
} else {
toggleHandToolButton.title = mozL10n.get('hand_tool_enable.title', null, 'Enable hand tool');
toggleHandToolButton.firstElementChild.textContent = mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
}
- }.bind(this));
+ });
},
open: function SecondaryToolbar_open() {
if (this.opened) {
return;
}
@@ -4202,11 +4204,11 @@
if (paintTask === self.paintTask) {
self.paintTask = null;
}
if (error === 'cancelled') {
self.error = null;
- return;
+ return Promise.resolve(undefined);
}
self.renderingState = RenderingStates.FINISHED;
if (self.loadingIconDiv) {
div.removeChild(self.loadingIconDiv);
delete self.loadingIconDiv;
@@ -4228,25 +4230,29 @@
self.eventBus.dispatch('pagerendered', {
source: self,
pageNumber: self.id,
cssTransform: false
});
+ if (error) {
+ return Promise.reject(error);
+ }
+ return Promise.resolve(undefined);
};
var paintTask = this.renderer === RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
paintTask.onRenderContinue = renderContinueCallback;
this.paintTask = paintTask;
var resultPromise = paintTask.promise.then(function () {
- finishPaintTask(null);
- if (textLayer) {
- pdfPage.getTextContent({ normalizeWhitespace: true }).then(function textContentResolved(textContent) {
- textLayer.setTextContent(textContent);
- textLayer.render(TEXT_LAYER_RENDER_DELAY);
- });
- }
+ return finishPaintTask(null).then(function () {
+ if (textLayer) {
+ pdfPage.getTextContent({ normalizeWhitespace: true }).then(function textContentResolved(textContent) {
+ textLayer.setTextContent(textContent);
+ textLayer.render(TEXT_LAYER_RENDER_DELAY);
+ });
+ }
+ });
}, function (reason) {
- finishPaintTask(reason);
- throw reason;
+ return finishPaintTask(reason);
});
if (this.annotationLayerFactory) {
if (!this.annotationLayer) {
this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.renderInteractiveForms);
}
@@ -5658,137 +5664,66 @@
toolbar: null,
secondaryToolbar: null,
eventBus: null,
pageRotation: 0,
isInitialViewSet: false,
- preferenceSidebarViewOnLoad: SidebarView.NONE,
- preferencePdfBugEnabled: false,
- preferenceShowPreviousViewOnLoad: true,
- preferenceDefaultZoomValue: '',
- preferenceDisablePageLabels: false,
+ viewerPrefs: {
+ sidebarViewOnLoad: SidebarView.NONE,
+ pdfBugEnabled: false,
+ showPreviousViewOnLoad: true,
+ defaultZoomValue: '',
+ disablePageLabels: false,
+ renderer: 'canvas',
+ enhanceTextSelection: false,
+ renderInteractiveForms: false
+ },
isViewerEmbedded: window.parent !== window,
url: '',
baseUrl: '',
externalServices: DefaultExernalServices,
initialize: function pdfViewInitialize(appConfig) {
- configure(pdfjsLib.PDFJS);
- this.appConfig = appConfig;
- var eventBus = appConfig.eventBus || getGlobalEventBus();
- this.eventBus = eventBus;
- this.bindEvents();
- var pdfRenderingQueue = new PDFRenderingQueue();
- pdfRenderingQueue.onIdle = this.cleanup.bind(this);
- this.pdfRenderingQueue = pdfRenderingQueue;
- var pdfLinkService = new PDFLinkService({ eventBus: eventBus });
- this.pdfLinkService = pdfLinkService;
- var downloadManager = this.externalServices.createDownloadManager();
- this.downloadManager = downloadManager;
- var container = appConfig.mainContainer;
- var viewer = appConfig.viewerContainer;
- this.pdfViewer = new PDFViewer({
- container: container,
- viewer: viewer,
- eventBus: eventBus,
- renderingQueue: pdfRenderingQueue,
- linkService: pdfLinkService,
- downloadManager: downloadManager,
- enhanceTextSelection: false,
- renderInteractiveForms: false
- });
- pdfRenderingQueue.setViewer(this.pdfViewer);
- pdfLinkService.setViewer(this.pdfViewer);
- var thumbnailContainer = appConfig.sidebar.thumbnailView;
- this.pdfThumbnailViewer = new PDFThumbnailViewer({
- container: thumbnailContainer,
- renderingQueue: pdfRenderingQueue,
- linkService: pdfLinkService
- });
- pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
+ var self = this;
+ var PDFJS = pdfjsLib.PDFJS;
Preferences.initialize();
this.preferences = Preferences;
- this.pdfHistory = new PDFHistory({
- linkService: pdfLinkService,
- eventBus: this.eventBus
- });
- pdfLinkService.setHistory(this.pdfHistory);
- this.findController = new PDFFindController({ pdfViewer: this.pdfViewer });
- this.findController.onUpdateResultsCount = function (matchCount) {
- if (this.supportsIntegratedFind) {
- return;
+ configure(PDFJS);
+ this.appConfig = appConfig;
+ return this._readPreferences().then(function () {
+ return self._initializeViewerComponents();
+ }).then(function () {
+ self.bindEvents();
+ self.bindWindowEvents();
+ localized.then(function () {
+ self.eventBus.dispatch('localized');
+ });
+ if (self.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) {
+ PDFJS.externalLinkTarget = PDFJS.LinkTarget.TOP;
}
- this.findBar.updateResultsCount(matchCount);
- }.bind(this);
- this.findController.onUpdateState = function (state, previous, matchCount) {
- if (this.supportsIntegratedFind) {
- this.externalServices.updateFindControlState({
- result: state,
- findPrevious: previous
- });
- } else {
- this.findBar.updateUIState(state, previous, matchCount);
- }
- }.bind(this);
- this.pdfViewer.setFindController(this.findController);
- var findBarConfig = Object.create(appConfig.findBar);
- findBarConfig.findController = this.findController;
- findBarConfig.eventBus = this.eventBus;
- this.findBar = new PDFFindBar(findBarConfig);
- this.overlayManager = OverlayManager;
- this.handTool = new HandTool({
- container: container,
- eventBus: this.eventBus
+ self.initialized = true;
});
- this.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties);
- this.toolbar = new Toolbar(appConfig.toolbar, container, eventBus);
- this.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
- if (this.supportsFullscreen) {
- this.pdfPresentationMode = new PDFPresentationMode({
- container: container,
- viewer: viewer,
- pdfViewer: this.pdfViewer,
- eventBus: this.eventBus,
- contextMenuItems: appConfig.fullscreen
- });
- }
- this.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay);
- this.pdfOutlineViewer = new PDFOutlineViewer({
- container: appConfig.sidebar.outlineView,
- eventBus: this.eventBus,
- linkService: pdfLinkService
- });
- this.pdfAttachmentViewer = new PDFAttachmentViewer({
- container: appConfig.sidebar.attachmentsView,
- eventBus: this.eventBus,
- downloadManager: downloadManager
- });
- var sidebarConfig = Object.create(appConfig.sidebar);
- sidebarConfig.pdfViewer = this.pdfViewer;
- sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
- sidebarConfig.pdfOutlineViewer = this.pdfOutlineViewer;
- sidebarConfig.eventBus = this.eventBus;
- this.pdfSidebar = new PDFSidebar(sidebarConfig);
- this.pdfSidebar.onToggled = this.forceRendering.bind(this);
+ },
+ _readPreferences: function () {
var self = this;
var PDFJS = pdfjsLib.PDFJS;
- var initializedPromise = Promise.all([
+ return Promise.all([
Preferences.get('enableWebGL').then(function resolved(value) {
PDFJS.disableWebGL = !value;
}),
Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
- self.preferenceSidebarViewOnLoad = value;
+ self.viewerPrefs['sidebarViewOnLoad'] = value;
}),
Preferences.get('pdfBugEnabled').then(function resolved(value) {
- self.preferencePdfBugEnabled = value;
+ self.viewerPrefs['pdfBugEnabled'] = value;
}),
Preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
- self.preferenceShowPreviousViewOnLoad = value;
+ self.viewerPrefs['showPreviousViewOnLoad'] = value;
}),
Preferences.get('defaultZoomValue').then(function resolved(value) {
- self.preferenceDefaultZoomValue = value;
+ self.viewerPrefs['defaultZoomValue'] = value;
}),
Preferences.get('enhanceTextSelection').then(function resolved(value) {
- self.pdfViewer.enhanceTextSelection = value;
+ self.viewerPrefs['enhanceTextSelection'] = value;
}),
Preferences.get('disableTextLayer').then(function resolved(value) {
if (PDFJS.disableTextLayer === true) {
return;
}
@@ -5823,25 +5758,119 @@
return;
}
PDFJS.externalLinkTarget = value;
}),
Preferences.get('renderer').then(function resolved(value) {
- self.pdfViewer.renderer = value;
+ self.viewerPrefs['renderer'] = value;
}),
Preferences.get('renderInteractiveForms').then(function resolved(value) {
- self.pdfViewer.renderInteractiveForms = value;
+ self.viewerPrefs['renderInteractiveForms'] = value;
}),
Preferences.get('disablePageLabels').then(function resolved(value) {
- self.preferenceDisablePageLabels = value;
+ self.viewerPrefs['disablePageLabels'] = value;
})
]).catch(function (reason) {
});
- return initializedPromise.then(function () {
- if (self.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) {
- PDFJS.externalLinkTarget = PDFJS.LinkTarget.TOP;
+ },
+ _initializeViewerComponents: function () {
+ var self = this;
+ var appConfig = this.appConfig;
+ return new Promise(function (resolve, reject) {
+ var eventBus = appConfig.eventBus || getGlobalEventBus();
+ self.eventBus = eventBus;
+ var pdfRenderingQueue = new PDFRenderingQueue();
+ pdfRenderingQueue.onIdle = self.cleanup.bind(self);
+ self.pdfRenderingQueue = pdfRenderingQueue;
+ var pdfLinkService = new PDFLinkService({ eventBus: eventBus });
+ self.pdfLinkService = pdfLinkService;
+ var downloadManager = self.externalServices.createDownloadManager();
+ self.downloadManager = downloadManager;
+ var container = appConfig.mainContainer;
+ var viewer = appConfig.viewerContainer;
+ self.pdfViewer = new PDFViewer({
+ container: container,
+ viewer: viewer,
+ eventBus: eventBus,
+ renderingQueue: pdfRenderingQueue,
+ linkService: pdfLinkService,
+ downloadManager: downloadManager,
+ renderer: self.viewerPrefs['renderer'],
+ enhanceTextSelection: self.viewerPrefs['enhanceTextSelection'],
+ renderInteractiveForms: self.viewerPrefs['renderInteractiveForms']
+ });
+ pdfRenderingQueue.setViewer(self.pdfViewer);
+ pdfLinkService.setViewer(self.pdfViewer);
+ var thumbnailContainer = appConfig.sidebar.thumbnailView;
+ self.pdfThumbnailViewer = new PDFThumbnailViewer({
+ container: thumbnailContainer,
+ renderingQueue: pdfRenderingQueue,
+ linkService: pdfLinkService
+ });
+ pdfRenderingQueue.setThumbnailViewer(self.pdfThumbnailViewer);
+ self.pdfHistory = new PDFHistory({
+ linkService: pdfLinkService,
+ eventBus: eventBus
+ });
+ pdfLinkService.setHistory(self.pdfHistory);
+ self.findController = new PDFFindController({ pdfViewer: self.pdfViewer });
+ self.findController.onUpdateResultsCount = function (matchCount) {
+ if (self.supportsIntegratedFind) {
+ return;
+ }
+ self.findBar.updateResultsCount(matchCount);
+ };
+ self.findController.onUpdateState = function (state, previous, matchCount) {
+ if (self.supportsIntegratedFind) {
+ self.externalServices.updateFindControlState({
+ result: state,
+ findPrevious: previous
+ });
+ } else {
+ self.findBar.updateUIState(state, previous, matchCount);
+ }
+ };
+ self.pdfViewer.setFindController(self.findController);
+ var findBarConfig = Object.create(appConfig.findBar);
+ findBarConfig.findController = self.findController;
+ findBarConfig.eventBus = eventBus;
+ self.findBar = new PDFFindBar(findBarConfig);
+ self.overlayManager = OverlayManager;
+ self.handTool = new HandTool({
+ container: container,
+ eventBus: eventBus
+ });
+ self.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties);
+ self.toolbar = new Toolbar(appConfig.toolbar, container, eventBus);
+ self.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
+ if (self.supportsFullscreen) {
+ self.pdfPresentationMode = new PDFPresentationMode({
+ container: container,
+ viewer: viewer,
+ pdfViewer: self.pdfViewer,
+ eventBus: eventBus,
+ contextMenuItems: appConfig.fullscreen
+ });
}
- self.initialized = true;
+ self.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay);
+ self.pdfOutlineViewer = new PDFOutlineViewer({
+ container: appConfig.sidebar.outlineView,
+ eventBus: eventBus,
+ linkService: pdfLinkService
+ });
+ self.pdfAttachmentViewer = new PDFAttachmentViewer({
+ container: appConfig.sidebar.attachmentsView,
+ eventBus: eventBus,
+ downloadManager: downloadManager
+ });
+ var sidebarConfig = Object.create(appConfig.sidebar);
+ sidebarConfig.pdfViewer = self.pdfViewer;
+ sidebarConfig.pdfThumbnailViewer = self.pdfThumbnailViewer;
+ sidebarConfig.pdfOutlineViewer = self.pdfOutlineViewer;
+ sidebarConfig.eventBus = eventBus;
+ self.pdfSidebar = new PDFSidebar(sidebarConfig);
+ self.pdfSidebar.onToggled = self.forceRendering.bind(self);
+ resolve(undefined);
});
},
run: function pdfViewRun(config) {
this.initialize(config).then(webViewerInitialized);
},
@@ -6131,11 +6160,11 @@
downloadedPromise.then(function () {
self.eventBus.dispatch('documentload', { source: self });
});
self.loadingBar.setWidth(self.appConfig.viewerContainer);
if (!pdfjsLib.PDFJS.disableHistory && !self.isViewerEmbedded) {
- if (!self.preferenceShowPreviousViewOnLoad) {
+ if (!self.viewerPrefs['showPreviousViewOnLoad']) {
self.pdfHistory.clearHistoryState();
}
self.pdfHistory.initialize(self.documentFingerprint);
if (self.pdfHistory.initialDestination) {
self.initialDestination = self.pdfHistory.initialDestination;
@@ -6148,19 +6177,19 @@
bookmark: self.initialBookmark,
hash: null
};
store.initializedPromise.then(function resolved() {
var storedHash = null, sidebarView = null;
- if (self.preferenceShowPreviousViewOnLoad && store.get('exists', false)) {
+ if (self.viewerPrefs['showPreviousViewOnLoad'] && store.get('exists', false)) {
var pageNum = store.get('page', '1');
- var zoom = self.preferenceDefaultZoomValue || store.get('zoom', DEFAULT_SCALE_VALUE);
+ var zoom = self.viewerPrefs['defaultZoomValue'] || store.get('zoom', DEFAULT_SCALE_VALUE);
var left = store.get('scrollLeft', '0');
var top = store.get('scrollTop', '0');
storedHash = 'page=' + pageNum + '&zoom=' + zoom + ',' + left + ',' + top;
sidebarView = store.get('sidebarView', SidebarView.NONE);
- } else if (self.preferenceDefaultZoomValue) {
- storedHash = 'page=1&zoom=' + self.preferenceDefaultZoomValue;
+ } else if (self.viewerPrefs['defaultZoomValue']) {
+ storedHash = 'page=1&zoom=' + self.viewerPrefs['defaultZoomValue'];
}
self.setInitialView(storedHash, {
scale: scale,
sidebarView: sidebarView
});
@@ -6184,11 +6213,11 @@
self.pdfViewer.currentScaleValue = self.pdfViewer.currentScaleValue;
self.setInitialView(initialParams.hash);
});
});
pdfDocument.getPageLabels().then(function (labels) {
- if (!labels || self.preferenceDisablePageLabels) {
+ if (!labels || self.viewerPrefs['disablePageLabels']) {
return;
}
var i = 0, numLabels = labels.length;
if (numLabels !== self.pagesCount) {
console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
@@ -6262,11 +6291,11 @@
},
setInitialView: function pdfViewSetInitialView(storedHash, options) {
var scale = options && options.scale;
var sidebarView = options && options.sidebarView;
this.isInitialViewSet = true;
- this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad || sidebarView | 0);
+ this.pdfSidebar.setInitialView(this.viewerPrefs['sidebarViewOnLoad'] || sidebarView | 0);
if (this.initialDestination) {
this.pdfLinkService.navigateTo(this.initialDestination);
this.initialDestination = null;
} else if (this.initialBookmark) {
this.pdfLinkService.setHash(this.initialBookmark);
@@ -6382,10 +6411,35 @@
eventBus.on('rotateccw', webViewerRotateCcw);
eventBus.on('documentproperties', webViewerDocumentProperties);
eventBus.on('find', webViewerFind);
eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
eventBus.on('fileinputchange', webViewerFileInputChange);
+ },
+ bindWindowEvents: function pdfViewBindWindowEvents() {
+ var eventBus = this.eventBus;
+ window.addEventListener('wheel', webViewerWheel);
+ window.addEventListener('click', webViewerClick);
+ window.addEventListener('keydown', webViewerKeyDown);
+ window.addEventListener('resize', function windowResize() {
+ eventBus.dispatch('resize');
+ });
+ window.addEventListener('hashchange', function windowHashChange() {
+ eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
+ });
+ window.addEventListener('beforeprint', function windowBeforePrint() {
+ eventBus.dispatch('beforeprint');
+ });
+ window.addEventListener('afterprint', function windowAfterPrint() {
+ eventBus.dispatch('afterprint');
+ });
+ window.addEventListener('change', function windowChange(evt) {
+ var files = evt.target.files;
+ if (!files || files.length === 0) {
+ return;
+ }
+ eventBus.dispatch('fileinputchange', { fileInput: evt.target });
+ });
}
};
var validateFileURL;
var HOSTED_VIEWER_ORIGINS = [
'null',
@@ -6445,11 +6499,11 @@
appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
} else {
fileInput.value = null;
}
var PDFJS = pdfjsLib.PDFJS;
- if (PDFViewerApplication.preferencePdfBugEnabled) {
+ if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
var hash = document.location.hash.substring(1);
var hashParams = parseQueryString(hash);
if ('disableworker' in hashParams) {
PDFJS.disableWorker = hashParams['disableworker'] === 'true';
}
@@ -6572,13 +6626,10 @@
}
}
function webViewerTextLayerRendered(e) {
}
function webViewerPageMode(e) {
- if (!PDFViewerApplication.initialized) {
- return;
- }
var mode = e.mode, view;
switch (mode) {
case 'thumbs':
view = SidebarView.THUMBS;
break;
@@ -6597,13 +6648,10 @@
return;
}
PDFViewerApplication.pdfSidebar.switchView(view, true);
}
function webViewerNamedAction(e) {
- if (!PDFViewerApplication.initialized) {
- return;
- }
var action = e.action;
switch (action) {
case 'GoToPage':
PDFViewerApplication.appConfig.toolbar.pageNumber.select();
break;
@@ -6618,13 +6666,10 @@
var active = e.active;
var switchInProgress = e.switchInProgress;
PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? PresentationModeState.CHANGING : active ? PresentationModeState.FULLSCREEN : PresentationModeState.NORMAL;
}
function webViewerSidebarViewChanged(e) {
- if (!PDFViewerApplication.initialized) {
- return;
- }
PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
var store = PDFViewerApplication.store;
if (!store || !PDFViewerApplication.isInitialViewSet) {
return;
}
@@ -6632,13 +6677,10 @@
store.set('sidebarView', e.view).catch(function () {
});
});
}
function webViewerUpdateViewarea(e) {
- if (!PDFViewerApplication.initialized) {
- return;
- }
var location = e.location, store = PDFViewerApplication.store;
if (store) {
store.initializedPromise.then(function () {
store.setMultiple({
'exists': true,
@@ -6656,31 +6698,19 @@
PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
var loading = currentPage.renderingState !== RenderingStates.FINISHED;
PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
}
- window.addEventListener('resize', function webViewerResize(evt) {
- if (!PDFViewerApplication.eventBus) {
- return;
- }
- PDFViewerApplication.eventBus.dispatch('resize');
- });
function webViewerResize() {
- if (PDFViewerApplication.initialized) {
- var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
- if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
- PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
- } else if (!currentScaleValue) {
- PDFViewerApplication.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
- }
- PDFViewerApplication.pdfViewer.update();
+ var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
+ if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
+ PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
+ } else if (!currentScaleValue) {
+ PDFViewerApplication.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
}
+ PDFViewerApplication.pdfViewer.update();
}
- window.addEventListener('hashchange', function webViewerHashchange(evt) {
- var hash = document.location.hash.substring(1);
- PDFViewerApplication.eventBus.dispatch('hashchange', { hash: hash });
- });
function webViewerHashchange(e) {
if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
var hash = e.hash;
if (!hash) {
return;
@@ -6691,17 +6721,10 @@
PDFViewerApplication.pdfLinkService.setHash(hash);
}
}
}
var webViewerFileInputChange;
- window.addEventListener('change', function webViewerChange(evt) {
- var files = evt.target.files;
- if (!files || files.length === 0) {
- return;
- }
- PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
- }, true);
webViewerFileInputChange = function webViewerFileInputChange(e) {
var file = e.fileInput.files[0];
if (!pdfjsLib.PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) {
PDFViewerApplication.open(URL.createObjectURL(file));
} else {
@@ -6718,14 +6741,10 @@
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
appConfig.toolbar.download.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
};
- function webViewerLocalized() {
- document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
- PDFViewerApplication.eventBus.dispatch('localized');
- }
function webViewerPresentationMode() {
PDFViewerApplication.requestPresentationMode();
}
function webViewerOpenFile() {
var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
@@ -6796,13 +6815,10 @@
findPrevious: false
});
}
function webViewerScaleChanging(e) {
PDFViewerApplication.toolbar.setPageScale(e.presetValue, e.scale);
- if (!PDFViewerApplication.initialized) {
- return;
- }
PDFViewerApplication.pdfViewer.update();
}
function webViewerPageChanging(e) {
var page = e.pageNumber;
PDFViewerApplication.toolbar.setPageNumber(page, e.pageLabel || null);
@@ -6816,13 +6832,13 @@
Stats.add(page, pageView.stats);
}
}
}
var zoomDisabled = false, zoomDisabledTimeout;
- function handleMouseWheel(evt) {
+ function webViewerWheel(evt) {
var pdfViewer = PDFViewerApplication.pdfViewer;
- if (!pdfViewer || pdfViewer.isInPresentationMode) {
+ if (pdfViewer.isInPresentationMode) {
return;
}
if (evt.ctrlKey || evt.metaKey) {
var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
@@ -6856,21 +6872,20 @@
zoomDisabledTimeout = setTimeout(function () {
zoomDisabled = false;
}, 1000);
}
}
- window.addEventListener('wheel', handleMouseWheel);
- window.addEventListener('click', function click(evt) {
+ function webViewerClick(evt) {
if (!PDFViewerApplication.secondaryToolbar.isOpen) {
return;
}
var appConfig = PDFViewerApplication.appConfig;
if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
PDFViewerApplication.secondaryToolbar.close();
}
- }, true);
- window.addEventListener('keydown', function keydown(evt) {
+ }
+ function webViewerKeyDown(evt) {
if (OverlayManager.active) {
return;
}
var handled = false, ensureViewerFocused = false;
var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
@@ -7086,17 +7101,13 @@
pdfViewer.focus();
}
if (handled) {
evt.preventDefault();
}
+ }
+ localized.then(function webViewerLocalized() {
+ document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
});
- window.addEventListener('beforeprint', function beforePrint(evt) {
- PDFViewerApplication.eventBus.dispatch('beforeprint');
- });
- window.addEventListener('afterprint', function afterPrint(evt) {
- PDFViewerApplication.eventBus.dispatch('afterprint');
- });
- localized.then(webViewerLocalized);
var PDFPrintServiceFactory = {
instance: {
supportsPrinting: false,
createPrintService: function () {
throw new Error('Not implemented: createPrintService');
\ No newline at end of file