1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
|
28 |
|
29 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
30 |
|
31 | var _ui_utils = require("./ui_utils");
|
32 |
|
33 | var _app_options = require("./app_options");
|
34 |
|
35 | var _pdf = require("../pdf");
|
36 |
|
37 | var _pdf_cursor_tools = require("./pdf_cursor_tools");
|
38 |
|
39 | var _pdf_rendering_queue = require("./pdf_rendering_queue");
|
40 |
|
41 | var _pdf_sidebar = require("./pdf_sidebar");
|
42 |
|
43 | var _overlay_manager = require("./overlay_manager");
|
44 |
|
45 | var _password_prompt = require("./password_prompt");
|
46 |
|
47 | var _pdf_attachment_viewer = require("./pdf_attachment_viewer");
|
48 |
|
49 | var _pdf_document_properties = require("./pdf_document_properties");
|
50 |
|
51 | var _pdf_find_bar = require("./pdf_find_bar");
|
52 |
|
53 | var _pdf_find_controller = require("./pdf_find_controller");
|
54 |
|
55 | var _pdf_history = require("./pdf_history");
|
56 |
|
57 | var _pdf_link_service = require("./pdf_link_service");
|
58 |
|
59 | var _pdf_outline_viewer = require("./pdf_outline_viewer");
|
60 |
|
61 | var _pdf_presentation_mode = require("./pdf_presentation_mode");
|
62 |
|
63 | var _pdf_sidebar_resizer = require("./pdf_sidebar_resizer");
|
64 |
|
65 | var _pdf_thumbnail_viewer = require("./pdf_thumbnail_viewer");
|
66 |
|
67 | var _pdf_viewer = require("./pdf_viewer");
|
68 |
|
69 | var _secondary_toolbar = require("./secondary_toolbar");
|
70 |
|
71 | var _toolbar = require("./toolbar");
|
72 |
|
73 | var _view_history = require("./view_history");
|
74 |
|
75 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
76 |
|
77 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
78 |
|
79 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
80 |
|
81 | function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
82 |
|
83 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
84 |
|
85 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
86 |
|
87 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
88 |
|
89 | var DEFAULT_SCALE_DELTA = 1.1;
|
90 | var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
|
91 | var FORCE_PAGES_LOADED_TIMEOUT = 10000;
|
92 | var WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
|
93 | var ViewOnLoad = {
|
94 | UNKNOWN: -1,
|
95 | PREVIOUS: 0,
|
96 | INITIAL: 1
|
97 | };
|
98 | var DefaultExternalServices = {
|
99 | updateFindControlState: function updateFindControlState(data) {},
|
100 | updateFindMatchesCount: function updateFindMatchesCount(data) {},
|
101 | initPassiveLoading: function initPassiveLoading(callbacks) {},
|
102 | fallback: function fallback(data, callback) {},
|
103 | reportTelemetry: function reportTelemetry(data) {},
|
104 | createDownloadManager: function createDownloadManager(options) {
|
105 | throw new Error('Not implemented: createDownloadManager');
|
106 | },
|
107 | createPreferences: function createPreferences() {
|
108 | throw new Error('Not implemented: createPreferences');
|
109 | },
|
110 | createL10n: function createL10n(options) {
|
111 | throw new Error('Not implemented: createL10n');
|
112 | },
|
113 | supportsIntegratedFind: false,
|
114 | supportsDocumentFonts: true,
|
115 | supportsDocumentColors: true,
|
116 | supportedMouseWheelZoomModifierKeys: {
|
117 | ctrlKey: true,
|
118 | metaKey: true
|
119 | }
|
120 | };
|
121 | exports.DefaultExternalServices = DefaultExternalServices;
|
122 | var PDFViewerApplication = {
|
123 | initialBookmark: document.location.hash.substring(1),
|
124 | initialized: false,
|
125 | fellback: false,
|
126 | appConfig: null,
|
127 | pdfDocument: null,
|
128 | pdfLoadingTask: null,
|
129 | printService: null,
|
130 | pdfViewer: null,
|
131 | pdfThumbnailViewer: null,
|
132 | pdfRenderingQueue: null,
|
133 | pdfPresentationMode: null,
|
134 | pdfDocumentProperties: null,
|
135 | pdfLinkService: null,
|
136 | pdfHistory: null,
|
137 | pdfSidebar: null,
|
138 | pdfSidebarResizer: null,
|
139 | pdfOutlineViewer: null,
|
140 | pdfAttachmentViewer: null,
|
141 | pdfCursorTools: null,
|
142 | store: null,
|
143 | downloadManager: null,
|
144 | overlayManager: null,
|
145 | preferences: null,
|
146 | toolbar: null,
|
147 | secondaryToolbar: null,
|
148 | eventBus: null,
|
149 | l10n: null,
|
150 | isInitialViewSet: false,
|
151 | downloadComplete: false,
|
152 | isViewerEmbedded: window.parent !== window,
|
153 | url: '',
|
154 | baseUrl: '',
|
155 | externalServices: DefaultExternalServices,
|
156 | _boundEvents: {},
|
157 | contentDispositionFilename: null,
|
158 | initialize: function () {
|
159 | var _initialize = _asyncToGenerator(
|
160 |
|
161 | _regenerator["default"].mark(function _callee(appConfig) {
|
162 | var _this = this;
|
163 |
|
164 | var appContainer;
|
165 | return _regenerator["default"].wrap(function _callee$(_context) {
|
166 | while (1) {
|
167 | switch (_context.prev = _context.next) {
|
168 | case 0:
|
169 | this.preferences = this.externalServices.createPreferences();
|
170 | this.appConfig = appConfig;
|
171 | _context.next = 4;
|
172 | return this._readPreferences();
|
173 |
|
174 | case 4:
|
175 | _context.next = 6;
|
176 | return this._parseHashParameters();
|
177 |
|
178 | case 6:
|
179 | _context.next = 8;
|
180 | return this._initializeL10n();
|
181 |
|
182 | case 8:
|
183 | if (this.isViewerEmbedded && _app_options.AppOptions.get('externalLinkTarget') === _pdf.LinkTarget.NONE) {
|
184 | _app_options.AppOptions.set('externalLinkTarget', _pdf.LinkTarget.TOP);
|
185 | }
|
186 |
|
187 | _context.next = 11;
|
188 | return this._initializeViewerComponents();
|
189 |
|
190 | case 11:
|
191 | this.bindEvents();
|
192 | this.bindWindowEvents();
|
193 | appContainer = appConfig.appContainer || document.documentElement;
|
194 | this.l10n.translate(appContainer).then(function () {
|
195 | _this.eventBus.dispatch('localized', {
|
196 | source: _this
|
197 | });
|
198 | });
|
199 | this.initialized = true;
|
200 |
|
201 | case 16:
|
202 | case "end":
|
203 | return _context.stop();
|
204 | }
|
205 | }
|
206 | }, _callee, this);
|
207 | }));
|
208 |
|
209 | function initialize(_x) {
|
210 | return _initialize.apply(this, arguments);
|
211 | }
|
212 |
|
213 | return initialize;
|
214 | }(),
|
215 | _readPreferences: function () {
|
216 | var _readPreferences2 = _asyncToGenerator(
|
217 |
|
218 | _regenerator["default"].mark(function _callee2() {
|
219 | var prefs, name;
|
220 | return _regenerator["default"].wrap(function _callee2$(_context2) {
|
221 | while (1) {
|
222 | switch (_context2.prev = _context2.next) {
|
223 | case 0:
|
224 | if (!(_app_options.AppOptions.get('disablePreferences') === true)) {
|
225 | _context2.next = 2;
|
226 | break;
|
227 | }
|
228 |
|
229 | return _context2.abrupt("return");
|
230 |
|
231 | case 2:
|
232 | _context2.prev = 2;
|
233 | _context2.next = 5;
|
234 | return this.preferences.getAll();
|
235 |
|
236 | case 5:
|
237 | prefs = _context2.sent;
|
238 |
|
239 | for (name in prefs) {
|
240 | _app_options.AppOptions.set(name, prefs[name]);
|
241 | }
|
242 |
|
243 | _context2.next = 12;
|
244 | break;
|
245 |
|
246 | case 9:
|
247 | _context2.prev = 9;
|
248 | _context2.t0 = _context2["catch"](2);
|
249 | console.error("_readPreferences: \"".concat(_context2.t0.message, "\"."));
|
250 |
|
251 | case 12:
|
252 | case "end":
|
253 | return _context2.stop();
|
254 | }
|
255 | }
|
256 | }, _callee2, this, [[2, 9]]);
|
257 | }));
|
258 |
|
259 | function _readPreferences() {
|
260 | return _readPreferences2.apply(this, arguments);
|
261 | }
|
262 |
|
263 | return _readPreferences;
|
264 | }(),
|
265 | _parseHashParameters: function () {
|
266 | var _parseHashParameters2 = _asyncToGenerator(
|
267 |
|
268 | _regenerator["default"].mark(function _callee3() {
|
269 | var waitOn, hash, hashParams, viewer, enabled;
|
270 | return _regenerator["default"].wrap(function _callee3$(_context3) {
|
271 | while (1) {
|
272 | switch (_context3.prev = _context3.next) {
|
273 | case 0:
|
274 | if (_app_options.AppOptions.get('pdfBugEnabled')) {
|
275 | _context3.next = 2;
|
276 | break;
|
277 | }
|
278 |
|
279 | return _context3.abrupt("return", undefined);
|
280 |
|
281 | case 2:
|
282 | waitOn = [];
|
283 | hash = document.location.hash.substring(1);
|
284 | hashParams = (0, _ui_utils.parseQueryString)(hash);
|
285 |
|
286 | if ('disableworker' in hashParams && hashParams['disableworker'] === 'true') {
|
287 | waitOn.push(loadFakeWorker());
|
288 | }
|
289 |
|
290 | if ('disablerange' in hashParams) {
|
291 | _app_options.AppOptions.set('disableRange', hashParams['disablerange'] === 'true');
|
292 | }
|
293 |
|
294 | if ('disablestream' in hashParams) {
|
295 | _app_options.AppOptions.set('disableStream', hashParams['disablestream'] === 'true');
|
296 | }
|
297 |
|
298 | if ('disableautofetch' in hashParams) {
|
299 | _app_options.AppOptions.set('disableAutoFetch', hashParams['disableautofetch'] === 'true');
|
300 | }
|
301 |
|
302 | if ('disablefontface' in hashParams) {
|
303 | _app_options.AppOptions.set('disableFontFace', hashParams['disablefontface'] === 'true');
|
304 | }
|
305 |
|
306 | if ('disablehistory' in hashParams) {
|
307 | _app_options.AppOptions.set('disableHistory', hashParams['disablehistory'] === 'true');
|
308 | }
|
309 |
|
310 | if ('webgl' in hashParams) {
|
311 | _app_options.AppOptions.set('enableWebGL', hashParams['webgl'] === 'true');
|
312 | }
|
313 |
|
314 | if ('useonlycsszoom' in hashParams) {
|
315 | _app_options.AppOptions.set('useOnlyCssZoom', hashParams['useonlycsszoom'] === 'true');
|
316 | }
|
317 |
|
318 | if ('verbosity' in hashParams) {
|
319 | _app_options.AppOptions.set('verbosity', hashParams['verbosity'] | 0);
|
320 | }
|
321 |
|
322 | if (!('textlayer' in hashParams)) {
|
323 | _context3.next = 23;
|
324 | break;
|
325 | }
|
326 |
|
327 | _context3.t0 = hashParams['textlayer'];
|
328 | _context3.next = _context3.t0 === 'off' ? 18 : _context3.t0 === 'visible' ? 20 : _context3.t0 === 'shadow' ? 20 : _context3.t0 === 'hover' ? 20 : 23;
|
329 | break;
|
330 |
|
331 | case 18:
|
332 | _app_options.AppOptions.set('textLayerMode', _ui_utils.TextLayerMode.DISABLE);
|
333 |
|
334 | return _context3.abrupt("break", 23);
|
335 |
|
336 | case 20:
|
337 | viewer = this.appConfig.viewerContainer;
|
338 | viewer.classList.add('textLayer-' + hashParams['textlayer']);
|
339 | return _context3.abrupt("break", 23);
|
340 |
|
341 | case 23:
|
342 | if ('pdfbug' in hashParams) {
|
343 | _app_options.AppOptions.set('pdfBug', true);
|
344 |
|
345 | enabled = hashParams['pdfbug'].split(',');
|
346 | waitOn.push(loadAndEnablePDFBug(enabled));
|
347 | }
|
348 |
|
349 | if ('locale' in hashParams) {
|
350 | _app_options.AppOptions.set('locale', hashParams['locale']);
|
351 | }
|
352 |
|
353 | return _context3.abrupt("return", Promise.all(waitOn)["catch"](function (reason) {
|
354 | console.error("_parseHashParameters: \"".concat(reason.message, "\"."));
|
355 | }));
|
356 |
|
357 | case 26:
|
358 | case "end":
|
359 | return _context3.stop();
|
360 | }
|
361 | }
|
362 | }, _callee3, this);
|
363 | }));
|
364 |
|
365 | function _parseHashParameters() {
|
366 | return _parseHashParameters2.apply(this, arguments);
|
367 | }
|
368 |
|
369 | return _parseHashParameters;
|
370 | }(),
|
371 | _initializeL10n: function () {
|
372 | var _initializeL10n2 = _asyncToGenerator(
|
373 |
|
374 | _regenerator["default"].mark(function _callee4() {
|
375 | var dir;
|
376 | return _regenerator["default"].wrap(function _callee4$(_context4) {
|
377 | while (1) {
|
378 | switch (_context4.prev = _context4.next) {
|
379 | case 0:
|
380 | this.l10n = this.externalServices.createL10n({
|
381 | locale: _app_options.AppOptions.get('locale')
|
382 | });
|
383 | _context4.next = 3;
|
384 | return this.l10n.getDirection();
|
385 |
|
386 | case 3:
|
387 | dir = _context4.sent;
|
388 | document.getElementsByTagName('html')[0].dir = dir;
|
389 |
|
390 | case 5:
|
391 | case "end":
|
392 | return _context4.stop();
|
393 | }
|
394 | }
|
395 | }, _callee4, this);
|
396 | }));
|
397 |
|
398 | function _initializeL10n() {
|
399 | return _initializeL10n2.apply(this, arguments);
|
400 | }
|
401 |
|
402 | return _initializeL10n;
|
403 | }(),
|
404 | _initializeViewerComponents: function () {
|
405 | var _initializeViewerComponents2 = _asyncToGenerator(
|
406 |
|
407 | _regenerator["default"].mark(function _callee5() {
|
408 | var appConfig, eventBus, pdfRenderingQueue, pdfLinkService, downloadManager, findController, container, viewer;
|
409 | return _regenerator["default"].wrap(function _callee5$(_context5) {
|
410 | while (1) {
|
411 | switch (_context5.prev = _context5.next) {
|
412 | case 0:
|
413 | appConfig = this.appConfig;
|
414 | this.overlayManager = new _overlay_manager.OverlayManager();
|
415 | eventBus = appConfig.eventBus || (0, _ui_utils.getGlobalEventBus)(_app_options.AppOptions.get('eventBusDispatchToDOM'));
|
416 | this.eventBus = eventBus;
|
417 | pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
|
418 | pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
419 | this.pdfRenderingQueue = pdfRenderingQueue;
|
420 | pdfLinkService = new _pdf_link_service.PDFLinkService({
|
421 | eventBus: eventBus,
|
422 | externalLinkTarget: _app_options.AppOptions.get('externalLinkTarget'),
|
423 | externalLinkRel: _app_options.AppOptions.get('externalLinkRel')
|
424 | });
|
425 | this.pdfLinkService = pdfLinkService;
|
426 | downloadManager = this.externalServices.createDownloadManager({
|
427 | disableCreateObjectURL: _app_options.AppOptions.get('disableCreateObjectURL')
|
428 | });
|
429 | this.downloadManager = downloadManager;
|
430 | findController = new _pdf_find_controller.PDFFindController({
|
431 | linkService: pdfLinkService,
|
432 | eventBus: eventBus
|
433 | });
|
434 | this.findController = findController;
|
435 | container = appConfig.mainContainer;
|
436 | viewer = appConfig.viewerContainer;
|
437 | this.pdfViewer = new _pdf_viewer.PDFViewer({
|
438 | container: container,
|
439 | viewer: viewer,
|
440 | eventBus: eventBus,
|
441 | renderingQueue: pdfRenderingQueue,
|
442 | linkService: pdfLinkService,
|
443 | downloadManager: downloadManager,
|
444 | findController: findController,
|
445 | renderer: _app_options.AppOptions.get('renderer'),
|
446 | enableWebGL: _app_options.AppOptions.get('enableWebGL'),
|
447 | l10n: this.l10n,
|
448 | textLayerMode: _app_options.AppOptions.get('textLayerMode'),
|
449 | imageResourcesPath: _app_options.AppOptions.get('imageResourcesPath'),
|
450 | renderInteractiveForms: _app_options.AppOptions.get('renderInteractiveForms'),
|
451 | enablePrintAutoRotate: _app_options.AppOptions.get('enablePrintAutoRotate'),
|
452 | useOnlyCssZoom: _app_options.AppOptions.get('useOnlyCssZoom'),
|
453 | maxCanvasPixels: _app_options.AppOptions.get('maxCanvasPixels')
|
454 | });
|
455 | pdfRenderingQueue.setViewer(this.pdfViewer);
|
456 | pdfLinkService.setViewer(this.pdfViewer);
|
457 | this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
|
458 | container: appConfig.sidebar.thumbnailView,
|
459 | renderingQueue: pdfRenderingQueue,
|
460 | linkService: pdfLinkService,
|
461 | l10n: this.l10n
|
462 | });
|
463 | pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
464 | this.pdfHistory = new _pdf_history.PDFHistory({
|
465 | linkService: pdfLinkService,
|
466 | eventBus: eventBus
|
467 | });
|
468 | pdfLinkService.setHistory(this.pdfHistory);
|
469 | this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
470 | this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
|
471 | this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
|
472 | container: container,
|
473 | eventBus: eventBus,
|
474 | cursorToolOnLoad: _app_options.AppOptions.get('cursorToolOnLoad')
|
475 | });
|
476 | this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
477 | this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
|
478 |
|
479 | if (this.supportsFullscreen) {
|
480 | this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
|
481 | container: container,
|
482 | viewer: viewer,
|
483 | pdfViewer: this.pdfViewer,
|
484 | eventBus: eventBus,
|
485 | contextMenuItems: appConfig.fullscreen
|
486 | });
|
487 | }
|
488 |
|
489 | this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
|
490 | this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
|
491 | container: appConfig.sidebar.outlineView,
|
492 | eventBus: eventBus,
|
493 | linkService: pdfLinkService
|
494 | });
|
495 | this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
|
496 | container: appConfig.sidebar.attachmentsView,
|
497 | eventBus: eventBus,
|
498 | downloadManager: downloadManager
|
499 | });
|
500 | this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
|
501 | elements: appConfig.sidebar,
|
502 | pdfViewer: this.pdfViewer,
|
503 | pdfThumbnailViewer: this.pdfThumbnailViewer,
|
504 | eventBus: eventBus,
|
505 | l10n: this.l10n
|
506 | });
|
507 | this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
508 | this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
|
509 |
|
510 | case 34:
|
511 | case "end":
|
512 | return _context5.stop();
|
513 | }
|
514 | }
|
515 | }, _callee5, this);
|
516 | }));
|
517 |
|
518 | function _initializeViewerComponents() {
|
519 | return _initializeViewerComponents2.apply(this, arguments);
|
520 | }
|
521 |
|
522 | return _initializeViewerComponents;
|
523 | }(),
|
524 | run: function run(config) {
|
525 | this.initialize(config).then(webViewerInitialized);
|
526 | },
|
527 | zoomIn: function zoomIn(ticks) {
|
528 | var newScale = this.pdfViewer.currentScale;
|
529 |
|
530 | do {
|
531 | newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
532 | newScale = Math.ceil(newScale * 10) / 10;
|
533 | newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
|
534 | } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
|
535 |
|
536 | this.pdfViewer.currentScaleValue = newScale;
|
537 | },
|
538 | zoomOut: function zoomOut(ticks) {
|
539 | var newScale = this.pdfViewer.currentScale;
|
540 |
|
541 | do {
|
542 | newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
543 | newScale = Math.floor(newScale * 10) / 10;
|
544 | newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
|
545 | } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
|
546 |
|
547 | this.pdfViewer.currentScaleValue = newScale;
|
548 | },
|
549 | zoomReset: function zoomReset() {
|
550 | var ignoreDuplicate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
551 |
|
552 | if (this.pdfViewer.isInPresentationMode) {
|
553 | return;
|
554 | } else if (ignoreDuplicate && this.pdfViewer.currentScaleValue === _ui_utils.DEFAULT_SCALE_VALUE) {
|
555 | return;
|
556 | }
|
557 |
|
558 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
559 | },
|
560 |
|
561 | get pagesCount() {
|
562 | return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
563 | },
|
564 |
|
565 | set page(val) {
|
566 | this.pdfViewer.currentPageNumber = val;
|
567 | },
|
568 |
|
569 | get page() {
|
570 | return this.pdfViewer.currentPageNumber;
|
571 | },
|
572 |
|
573 | get printing() {
|
574 | return !!this.printService;
|
575 | },
|
576 |
|
577 | get supportsPrinting() {
|
578 | return PDFPrintServiceFactory.instance.supportsPrinting;
|
579 | },
|
580 |
|
581 | get supportsFullscreen() {
|
582 | var support;
|
583 | var doc = document.documentElement;
|
584 | support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
|
585 |
|
586 | if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
|
587 | support = false;
|
588 | }
|
589 |
|
590 | return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
|
591 | },
|
592 |
|
593 | get supportsIntegratedFind() {
|
594 | return this.externalServices.supportsIntegratedFind;
|
595 | },
|
596 |
|
597 | get supportsDocumentFonts() {
|
598 | return this.externalServices.supportsDocumentFonts;
|
599 | },
|
600 |
|
601 | get supportsDocumentColors() {
|
602 | return this.externalServices.supportsDocumentColors;
|
603 | },
|
604 |
|
605 | get loadingBar() {
|
606 | var bar = new _ui_utils.ProgressBar('#loadingBar');
|
607 | return (0, _pdf.shadow)(this, 'loadingBar', bar);
|
608 | },
|
609 |
|
610 | get supportedMouseWheelZoomModifierKeys() {
|
611 | return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
612 | },
|
613 |
|
614 | initPassiveLoading: function initPassiveLoading() {
|
615 | throw new Error('Not implemented: initPassiveLoading');
|
616 | },
|
617 | setTitleUsingUrl: function setTitleUsingUrl() {
|
618 | var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
619 | this.url = url;
|
620 | this.baseUrl = url.split('#')[0];
|
621 | var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
|
622 |
|
623 | if (!title) {
|
624 | try {
|
625 | title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
|
626 | } catch (ex) {
|
627 | title = url;
|
628 | }
|
629 | }
|
630 |
|
631 | this.setTitle(title);
|
632 | },
|
633 | setTitle: function setTitle(title) {
|
634 | if (this.isViewerEmbedded) {
|
635 | return;
|
636 | }
|
637 |
|
638 | document.title = title;
|
639 | },
|
640 | close: function () {
|
641 | var _close = _asyncToGenerator(
|
642 |
|
643 | _regenerator["default"].mark(function _callee6() {
|
644 | var errorWrapper, promise;
|
645 | return _regenerator["default"].wrap(function _callee6$(_context6) {
|
646 | while (1) {
|
647 | switch (_context6.prev = _context6.next) {
|
648 | case 0:
|
649 | errorWrapper = this.appConfig.errorWrapper.container;
|
650 | errorWrapper.setAttribute('hidden', 'true');
|
651 |
|
652 | if (this.pdfLoadingTask) {
|
653 | _context6.next = 4;
|
654 | break;
|
655 | }
|
656 |
|
657 | return _context6.abrupt("return", undefined);
|
658 |
|
659 | case 4:
|
660 | promise = this.pdfLoadingTask.destroy();
|
661 | this.pdfLoadingTask = null;
|
662 |
|
663 | if (this.pdfDocument) {
|
664 | this.pdfDocument = null;
|
665 | this.pdfThumbnailViewer.setDocument(null);
|
666 | this.pdfViewer.setDocument(null);
|
667 | this.pdfLinkService.setDocument(null);
|
668 | this.pdfDocumentProperties.setDocument(null);
|
669 | }
|
670 |
|
671 | this.store = null;
|
672 | this.isInitialViewSet = false;
|
673 | this.downloadComplete = false;
|
674 | this.url = '';
|
675 | this.baseUrl = '';
|
676 | this.contentDispositionFilename = null;
|
677 | this.pdfSidebar.reset();
|
678 | this.pdfOutlineViewer.reset();
|
679 | this.pdfAttachmentViewer.reset();
|
680 | this.findBar.reset();
|
681 | this.toolbar.reset();
|
682 | this.secondaryToolbar.reset();
|
683 |
|
684 | if (typeof PDFBug !== 'undefined') {
|
685 | PDFBug.cleanup();
|
686 | }
|
687 |
|
688 | return _context6.abrupt("return", promise);
|
689 |
|
690 | case 21:
|
691 | case "end":
|
692 | return _context6.stop();
|
693 | }
|
694 | }
|
695 | }, _callee6, this);
|
696 | }));
|
697 |
|
698 | function close() {
|
699 | return _close.apply(this, arguments);
|
700 | }
|
701 |
|
702 | return close;
|
703 | }(),
|
704 | open: function () {
|
705 | var _open = _asyncToGenerator(
|
706 |
|
707 | _regenerator["default"].mark(function _callee7(file, args) {
|
708 | var _this2 = this;
|
709 |
|
710 | var workerParameters, key, parameters, apiParameters, _key, prop, loadingTask;
|
711 |
|
712 | return _regenerator["default"].wrap(function _callee7$(_context7) {
|
713 | while (1) {
|
714 | switch (_context7.prev = _context7.next) {
|
715 | case 0:
|
716 | if (!this.pdfLoadingTask) {
|
717 | _context7.next = 3;
|
718 | break;
|
719 | }
|
720 |
|
721 | _context7.next = 3;
|
722 | return this.close();
|
723 |
|
724 | case 3:
|
725 | workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
|
726 |
|
727 | for (key in workerParameters) {
|
728 | _pdf.GlobalWorkerOptions[key] = workerParameters[key];
|
729 | }
|
730 |
|
731 | parameters = Object.create(null);
|
732 |
|
733 | if (typeof file === 'string') {
|
734 | this.setTitleUsingUrl(file);
|
735 | parameters.url = file;
|
736 | } else if (file && 'byteLength' in file) {
|
737 | parameters.data = file;
|
738 | } else if (file.url && file.originalUrl) {
|
739 | this.setTitleUsingUrl(file.originalUrl);
|
740 | parameters.url = file.url;
|
741 | }
|
742 |
|
743 | apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
|
744 |
|
745 | for (_key in apiParameters) {
|
746 | parameters[_key] = apiParameters[_key];
|
747 | }
|
748 |
|
749 | if (args) {
|
750 | for (prop in args) {
|
751 | if (prop === 'length') {
|
752 | this.pdfDocumentProperties.setFileSize(args[prop]);
|
753 | }
|
754 |
|
755 | parameters[prop] = args[prop];
|
756 | }
|
757 | }
|
758 |
|
759 | loadingTask = (0, _pdf.getDocument)(parameters);
|
760 | this.pdfLoadingTask = loadingTask;
|
761 |
|
762 | loadingTask.onPassword = function (updateCallback, reason) {
|
763 | _this2.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
764 |
|
765 | _this2.passwordPrompt.open();
|
766 | };
|
767 |
|
768 | loadingTask.onProgress = function (_ref) {
|
769 | var loaded = _ref.loaded,
|
770 | total = _ref.total;
|
771 |
|
772 | _this2.progress(loaded / total);
|
773 | };
|
774 |
|
775 | loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
776 | return _context7.abrupt("return", loadingTask.promise.then(function (pdfDocument) {
|
777 | _this2.load(pdfDocument);
|
778 | }, function (exception) {
|
779 | if (loadingTask !== _this2.pdfLoadingTask) {
|
780 | return undefined;
|
781 | }
|
782 |
|
783 | var message = exception && exception.message;
|
784 | var loadingErrorMessage;
|
785 |
|
786 | if (exception instanceof _pdf.InvalidPDFException) {
|
787 | loadingErrorMessage = _this2.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
|
788 | } else if (exception instanceof _pdf.MissingPDFException) {
|
789 | loadingErrorMessage = _this2.l10n.get('missing_file_error', null, 'Missing PDF file.');
|
790 | } else if (exception instanceof _pdf.UnexpectedResponseException) {
|
791 | loadingErrorMessage = _this2.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
|
792 | } else {
|
793 | loadingErrorMessage = _this2.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
|
794 | }
|
795 |
|
796 | return loadingErrorMessage.then(function (msg) {
|
797 | _this2.error(msg, {
|
798 | message: message
|
799 | });
|
800 |
|
801 | throw new Error(msg);
|
802 | });
|
803 | }));
|
804 |
|
805 | case 16:
|
806 | case "end":
|
807 | return _context7.stop();
|
808 | }
|
809 | }
|
810 | }, _callee7, this);
|
811 | }));
|
812 |
|
813 | function open(_x2, _x3) {
|
814 | return _open.apply(this, arguments);
|
815 | }
|
816 |
|
817 | return open;
|
818 | }(),
|
819 | download: function download() {
|
820 | var _this3 = this;
|
821 |
|
822 | function downloadByUrl() {
|
823 | downloadManager.downloadUrl(url, filename);
|
824 | }
|
825 |
|
826 | var url = this.baseUrl;
|
827 | var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
|
828 | var downloadManager = this.downloadManager;
|
829 |
|
830 | downloadManager.onerror = function (err) {
|
831 | _this3.error("PDF failed to download: ".concat(err));
|
832 | };
|
833 |
|
834 | if (!this.pdfDocument || !this.downloadComplete) {
|
835 | downloadByUrl();
|
836 | return;
|
837 | }
|
838 |
|
839 | this.pdfDocument.getData().then(function (data) {
|
840 | var blob = new Blob([data], {
|
841 | type: 'application/pdf'
|
842 | });
|
843 | downloadManager.download(blob, url, filename);
|
844 | })["catch"](downloadByUrl);
|
845 | },
|
846 | fallback: function fallback(featureId) {},
|
847 | error: function error(message, moreInfo) {
|
848 | var moreInfoText = [this.l10n.get('error_version_info', {
|
849 | version: _pdf.version || '?',
|
850 | build: _pdf.build || '?'
|
851 | }, 'PDF.js v{{version}} (build: {{build}})')];
|
852 |
|
853 | if (moreInfo) {
|
854 | moreInfoText.push(this.l10n.get('error_message', {
|
855 | message: moreInfo.message
|
856 | }, 'Message: {{message}}'));
|
857 |
|
858 | if (moreInfo.stack) {
|
859 | moreInfoText.push(this.l10n.get('error_stack', {
|
860 | stack: moreInfo.stack
|
861 | }, 'Stack: {{stack}}'));
|
862 | } else {
|
863 | if (moreInfo.filename) {
|
864 | moreInfoText.push(this.l10n.get('error_file', {
|
865 | file: moreInfo.filename
|
866 | }, 'File: {{file}}'));
|
867 | }
|
868 |
|
869 | if (moreInfo.lineNumber) {
|
870 | moreInfoText.push(this.l10n.get('error_line', {
|
871 | line: moreInfo.lineNumber
|
872 | }, 'Line: {{line}}'));
|
873 | }
|
874 | }
|
875 | }
|
876 |
|
877 | var errorWrapperConfig = this.appConfig.errorWrapper;
|
878 | var errorWrapper = errorWrapperConfig.container;
|
879 | errorWrapper.removeAttribute('hidden');
|
880 | var errorMessage = errorWrapperConfig.errorMessage;
|
881 | errorMessage.textContent = message;
|
882 | var closeButton = errorWrapperConfig.closeButton;
|
883 |
|
884 | closeButton.onclick = function () {
|
885 | errorWrapper.setAttribute('hidden', 'true');
|
886 | };
|
887 |
|
888 | var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
|
889 | var moreInfoButton = errorWrapperConfig.moreInfoButton;
|
890 | var lessInfoButton = errorWrapperConfig.lessInfoButton;
|
891 |
|
892 | moreInfoButton.onclick = function () {
|
893 | errorMoreInfo.removeAttribute('hidden');
|
894 | moreInfoButton.setAttribute('hidden', 'true');
|
895 | lessInfoButton.removeAttribute('hidden');
|
896 | errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
|
897 | };
|
898 |
|
899 | lessInfoButton.onclick = function () {
|
900 | errorMoreInfo.setAttribute('hidden', 'true');
|
901 | moreInfoButton.removeAttribute('hidden');
|
902 | lessInfoButton.setAttribute('hidden', 'true');
|
903 | };
|
904 |
|
905 | moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
906 | lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
907 | closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
|
908 | moreInfoButton.removeAttribute('hidden');
|
909 | lessInfoButton.setAttribute('hidden', 'true');
|
910 | Promise.all(moreInfoText).then(function (parts) {
|
911 | errorMoreInfo.value = parts.join('\n');
|
912 | });
|
913 | },
|
914 | progress: function progress(level) {
|
915 | var _this4 = this;
|
916 |
|
917 | if (this.downloadComplete) {
|
918 | return;
|
919 | }
|
920 |
|
921 | var percent = Math.round(level * 100);
|
922 |
|
923 | if (percent > this.loadingBar.percent || isNaN(percent)) {
|
924 | this.loadingBar.percent = percent;
|
925 | var disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams['disableAutoFetch'] : _app_options.AppOptions.get('disableAutoFetch');
|
926 |
|
927 | if (disableAutoFetch && percent) {
|
928 | if (this.disableAutoFetchLoadingBarTimeout) {
|
929 | clearTimeout(this.disableAutoFetchLoadingBarTimeout);
|
930 | this.disableAutoFetchLoadingBarTimeout = null;
|
931 | }
|
932 |
|
933 | this.loadingBar.show();
|
934 | this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
|
935 | _this4.loadingBar.hide();
|
936 |
|
937 | _this4.disableAutoFetchLoadingBarTimeout = null;
|
938 | }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
|
939 | }
|
940 | }
|
941 | },
|
942 | load: function load(pdfDocument) {
|
943 | var _this5 = this;
|
944 |
|
945 | this.pdfDocument = pdfDocument;
|
946 | pdfDocument.getDownloadInfo().then(function () {
|
947 | _this5.downloadComplete = true;
|
948 |
|
949 | _this5.loadingBar.hide();
|
950 |
|
951 | firstPagePromise.then(function () {
|
952 | _this5.eventBus.dispatch('documentloaded', {
|
953 | source: _this5
|
954 | });
|
955 | });
|
956 | });
|
957 | var pageLayoutPromise = pdfDocument.getPageLayout()["catch"](function () {});
|
958 | var pageModePromise = pdfDocument.getPageMode()["catch"](function () {});
|
959 | var openActionDestPromise = pdfDocument.getOpenActionDestination()["catch"](function () {});
|
960 | this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
961 | this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
962 | var store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint);
|
963 | var baseDocumentUrl;
|
964 | baseDocumentUrl = null;
|
965 | this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
966 | this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
967 | var pdfViewer = this.pdfViewer;
|
968 | pdfViewer.setDocument(pdfDocument);
|
969 | var firstPagePromise = pdfViewer.firstPagePromise;
|
970 | var pagesPromise = pdfViewer.pagesPromise;
|
971 | var onePageRendered = pdfViewer.onePageRendered;
|
972 | var pdfThumbnailViewer = this.pdfThumbnailViewer;
|
973 | pdfThumbnailViewer.setDocument(pdfDocument);
|
974 | firstPagePromise.then(function (pdfPage) {
|
975 | _this5.loadingBar.setWidth(_this5.appConfig.viewerContainer);
|
976 |
|
977 | var storePromise = store.getMultiple({
|
978 | page: null,
|
979 | zoom: _ui_utils.DEFAULT_SCALE_VALUE,
|
980 | scrollLeft: '0',
|
981 | scrollTop: '0',
|
982 | rotation: null,
|
983 | sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
|
984 | scrollMode: _ui_utils.ScrollMode.UNKNOWN,
|
985 | spreadMode: _ui_utils.SpreadMode.UNKNOWN
|
986 | })["catch"](function () {});
|
987 | Promise.all([storePromise, pageLayoutPromise, pageModePromise, openActionDestPromise]).then(
|
988 |
|
989 | function () {
|
990 | var _ref3 = _asyncToGenerator(
|
991 |
|
992 | _regenerator["default"].mark(function _callee8(_ref2) {
|
993 | var _ref4, _ref4$, values, pageLayout, pageMode, openActionDest, viewOnLoad, initialBookmark, zoom, hash, rotation, sidebarView, scrollMode, spreadMode;
|
994 |
|
995 | return _regenerator["default"].wrap(function _callee8$(_context8) {
|
996 | while (1) {
|
997 | switch (_context8.prev = _context8.next) {
|
998 | case 0:
|
999 | _ref4 = _slicedToArray(_ref2, 4), _ref4$ = _ref4[0], values = _ref4$ === void 0 ? {} : _ref4$, pageLayout = _ref4[1], pageMode = _ref4[2], openActionDest = _ref4[3];
|
1000 | viewOnLoad = _app_options.AppOptions.get('viewOnLoad');
|
1001 |
|
1002 | _this5._initializePdfHistory({
|
1003 | fingerprint: pdfDocument.fingerprint,
|
1004 | viewOnLoad: viewOnLoad,
|
1005 | initialDest: openActionDest
|
1006 | });
|
1007 |
|
1008 | initialBookmark = _this5.initialBookmark;
|
1009 | zoom = _app_options.AppOptions.get('defaultZoomValue');
|
1010 | hash = zoom ? "zoom=".concat(zoom) : null;
|
1011 | rotation = null;
|
1012 | sidebarView = _app_options.AppOptions.get('sidebarViewOnLoad');
|
1013 | scrollMode = _app_options.AppOptions.get('scrollModeOnLoad');
|
1014 | spreadMode = _app_options.AppOptions.get('spreadModeOnLoad');
|
1015 |
|
1016 | if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
1017 | hash = "page=".concat(values.page, "&zoom=").concat(zoom || values.zoom, ",") + "".concat(values.scrollLeft, ",").concat(values.scrollTop);
|
1018 | rotation = parseInt(values.rotation, 10);
|
1019 |
|
1020 | if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
|
1021 | sidebarView = values.sidebarView | 0;
|
1022 | }
|
1023 |
|
1024 | if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
|
1025 | scrollMode = values.scrollMode | 0;
|
1026 | }
|
1027 |
|
1028 | if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
1029 | spreadMode = values.spreadMode | 0;
|
1030 | }
|
1031 | }
|
1032 |
|
1033 | if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
|
1034 | sidebarView = apiPageModeToSidebarView(pageMode);
|
1035 | }
|
1036 |
|
1037 | if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
1038 | spreadMode = apiPageLayoutToSpreadMode(pageLayout);
|
1039 | }
|
1040 |
|
1041 | _this5.setInitialView(hash, {
|
1042 | rotation: rotation,
|
1043 | sidebarView: sidebarView,
|
1044 | scrollMode: scrollMode,
|
1045 | spreadMode: spreadMode
|
1046 | });
|
1047 |
|
1048 | _this5.eventBus.dispatch('documentinit', {
|
1049 | source: _this5
|
1050 | });
|
1051 |
|
1052 | if (!_this5.isViewerEmbedded) {
|
1053 | pdfViewer.focus();
|
1054 | }
|
1055 |
|
1056 | _context8.next = 18;
|
1057 | return Promise.race([pagesPromise, new Promise(function (resolve) {
|
1058 | setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
1059 | })]);
|
1060 |
|
1061 | case 18:
|
1062 | if (!(!initialBookmark && !hash)) {
|
1063 | _context8.next = 20;
|
1064 | break;
|
1065 | }
|
1066 |
|
1067 | return _context8.abrupt("return");
|
1068 |
|
1069 | case 20:
|
1070 | if (!pdfViewer.hasEqualPageSizes) {
|
1071 | _context8.next = 22;
|
1072 | break;
|
1073 | }
|
1074 |
|
1075 | return _context8.abrupt("return");
|
1076 |
|
1077 | case 22:
|
1078 | _this5.initialBookmark = initialBookmark;
|
1079 | pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
1080 |
|
1081 | _this5.setInitialView(hash);
|
1082 |
|
1083 | case 25:
|
1084 | case "end":
|
1085 | return _context8.stop();
|
1086 | }
|
1087 | }
|
1088 | }, _callee8);
|
1089 | }));
|
1090 |
|
1091 | return function (_x4) {
|
1092 | return _ref3.apply(this, arguments);
|
1093 | };
|
1094 | }())["catch"](function () {
|
1095 | _this5.setInitialView();
|
1096 | }).then(function () {
|
1097 | pdfViewer.update();
|
1098 | });
|
1099 | });
|
1100 | pdfDocument.getPageLabels().then(function (labels) {
|
1101 | if (!labels || _app_options.AppOptions.get('disablePageLabels')) {
|
1102 | return;
|
1103 | }
|
1104 |
|
1105 | var i = 0,
|
1106 | numLabels = labels.length;
|
1107 |
|
1108 | if (numLabels !== _this5.pagesCount) {
|
1109 | console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
|
1110 | return;
|
1111 | }
|
1112 |
|
1113 | while (i < numLabels && labels[i] === (i + 1).toString()) {
|
1114 | i++;
|
1115 | }
|
1116 |
|
1117 | if (i === numLabels) {
|
1118 | return;
|
1119 | }
|
1120 |
|
1121 | pdfViewer.setPageLabels(labels);
|
1122 | pdfThumbnailViewer.setPageLabels(labels);
|
1123 |
|
1124 | _this5.toolbar.setPagesCount(pdfDocument.numPages, true);
|
1125 |
|
1126 | _this5.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
1127 | });
|
1128 | pagesPromise.then(function () {
|
1129 | if (!_this5.supportsPrinting) {
|
1130 | return;
|
1131 | }
|
1132 |
|
1133 | pdfDocument.getJavaScript().then(function (javaScript) {
|
1134 | if (!javaScript) {
|
1135 | return;
|
1136 | }
|
1137 |
|
1138 | javaScript.some(function (js) {
|
1139 | if (!js) {
|
1140 | return false;
|
1141 | }
|
1142 |
|
1143 | console.warn('Warning: JavaScript is not supported');
|
1144 |
|
1145 | _this5.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
|
1146 |
|
1147 | return true;
|
1148 | });
|
1149 | var regex = /\bprint\s*\(/;
|
1150 |
|
1151 | for (var i = 0, ii = javaScript.length; i < ii; i++) {
|
1152 | var js = javaScript[i];
|
1153 |
|
1154 | if (js && regex.test(js)) {
|
1155 | setTimeout(function () {
|
1156 | window.print();
|
1157 | });
|
1158 | return;
|
1159 | }
|
1160 | }
|
1161 | });
|
1162 | });
|
1163 | Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
|
1164 | pdfDocument.getOutline().then(function (outline) {
|
1165 | _this5.pdfOutlineViewer.render({
|
1166 | outline: outline
|
1167 | });
|
1168 | });
|
1169 | pdfDocument.getAttachments().then(function (attachments) {
|
1170 | _this5.pdfAttachmentViewer.render({
|
1171 | attachments: attachments
|
1172 | });
|
1173 | });
|
1174 | });
|
1175 | pdfDocument.getMetadata().then(function (_ref5) {
|
1176 | var info = _ref5.info,
|
1177 | metadata = _ref5.metadata,
|
1178 | contentDispositionFilename = _ref5.contentDispositionFilename;
|
1179 | _this5.documentInfo = info;
|
1180 | _this5.metadata = metadata;
|
1181 | _this5.contentDispositionFilename = contentDispositionFilename;
|
1182 | console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (_app_options.AppOptions.get('enableWebGL') ? ' [WebGL]' : '') + ')');
|
1183 | var pdfTitle;
|
1184 |
|
1185 | if (metadata && metadata.has('dc:title')) {
|
1186 | var title = metadata.get('dc:title');
|
1187 |
|
1188 | if (title !== 'Untitled') {
|
1189 | pdfTitle = title;
|
1190 | }
|
1191 | }
|
1192 |
|
1193 | if (!pdfTitle && info && info['Title']) {
|
1194 | pdfTitle = info['Title'];
|
1195 | }
|
1196 |
|
1197 | if (pdfTitle) {
|
1198 | _this5.setTitle("".concat(pdfTitle, " - ").concat(contentDispositionFilename || document.title));
|
1199 | } else if (contentDispositionFilename) {
|
1200 | _this5.setTitle(contentDispositionFilename);
|
1201 | }
|
1202 |
|
1203 | if (info.IsAcroFormPresent) {
|
1204 | console.warn('Warning: AcroForm/XFA is not supported');
|
1205 |
|
1206 | _this5.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
|
1207 | }
|
1208 | });
|
1209 | },
|
1210 | _initializePdfHistory: function _initializePdfHistory(_ref6) {
|
1211 | var fingerprint = _ref6.fingerprint,
|
1212 | viewOnLoad = _ref6.viewOnLoad,
|
1213 | _ref6$initialDest = _ref6.initialDest,
|
1214 | initialDest = _ref6$initialDest === void 0 ? null : _ref6$initialDest;
|
1215 |
|
1216 | if (_app_options.AppOptions.get('disableHistory') || this.isViewerEmbedded) {
|
1217 | return;
|
1218 | }
|
1219 |
|
1220 | this.pdfHistory.initialize({
|
1221 | fingerprint: fingerprint,
|
1222 | resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
|
1223 | updateUrl: _app_options.AppOptions.get('historyUpdateUrl')
|
1224 | });
|
1225 |
|
1226 | if (this.pdfHistory.initialBookmark) {
|
1227 | this.initialBookmark = this.pdfHistory.initialBookmark;
|
1228 | this.initialRotation = this.pdfHistory.initialRotation;
|
1229 | }
|
1230 |
|
1231 | if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
|
1232 | this.initialBookmark = JSON.stringify(initialDest);
|
1233 | this.pdfHistory.push({
|
1234 | explicitDest: initialDest,
|
1235 | pageNumber: null
|
1236 | });
|
1237 | }
|
1238 | },
|
1239 | setInitialView: function setInitialView(storedHash) {
|
1240 | var _this6 = this;
|
1241 |
|
1242 | var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
1243 | rotation = _ref7.rotation,
|
1244 | sidebarView = _ref7.sidebarView,
|
1245 | scrollMode = _ref7.scrollMode,
|
1246 | spreadMode = _ref7.spreadMode;
|
1247 |
|
1248 | var setRotation = function setRotation(angle) {
|
1249 | if ((0, _ui_utils.isValidRotation)(angle)) {
|
1250 | _this6.pdfViewer.pagesRotation = angle;
|
1251 | }
|
1252 | };
|
1253 |
|
1254 | var setViewerModes = function setViewerModes(scroll, spread) {
|
1255 | if ((0, _ui_utils.isValidScrollMode)(scroll)) {
|
1256 | _this6.pdfViewer.scrollMode = scroll;
|
1257 | }
|
1258 |
|
1259 | if ((0, _ui_utils.isValidSpreadMode)(spread)) {
|
1260 | _this6.pdfViewer.spreadMode = spread;
|
1261 | }
|
1262 | };
|
1263 |
|
1264 | this.isInitialViewSet = true;
|
1265 | this.pdfSidebar.setInitialView(sidebarView);
|
1266 | setViewerModes(scrollMode, spreadMode);
|
1267 |
|
1268 | if (this.initialBookmark) {
|
1269 | setRotation(this.initialRotation);
|
1270 | delete this.initialRotation;
|
1271 | this.pdfLinkService.setHash(this.initialBookmark);
|
1272 | this.initialBookmark = null;
|
1273 | } else if (storedHash) {
|
1274 | setRotation(rotation);
|
1275 | this.pdfLinkService.setHash(storedHash);
|
1276 | }
|
1277 |
|
1278 | this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
|
1279 | this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
|
1280 |
|
1281 | if (!this.pdfViewer.currentScaleValue) {
|
1282 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
1283 | }
|
1284 | },
|
1285 | cleanup: function cleanup() {
|
1286 | if (!this.pdfDocument) {
|
1287 | return;
|
1288 | }
|
1289 |
|
1290 | this.pdfViewer.cleanup();
|
1291 | this.pdfThumbnailViewer.cleanup();
|
1292 |
|
1293 | if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
|
1294 | this.pdfDocument.cleanup();
|
1295 | }
|
1296 | },
|
1297 | forceRendering: function forceRendering() {
|
1298 | this.pdfRenderingQueue.printing = this.printing;
|
1299 | this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
|
1300 | this.pdfRenderingQueue.renderHighestPriority();
|
1301 | },
|
1302 | beforePrint: function beforePrint() {
|
1303 | var _this7 = this;
|
1304 |
|
1305 | if (this.printService) {
|
1306 | return;
|
1307 | }
|
1308 |
|
1309 | if (!this.supportsPrinting) {
|
1310 | this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
|
1311 | _this7.error(printMessage);
|
1312 | });
|
1313 | return;
|
1314 | }
|
1315 |
|
1316 | if (!this.pdfViewer.pageViewsReady) {
|
1317 | this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
|
1318 | window.alert(notReadyMessage);
|
1319 | });
|
1320 | return;
|
1321 | }
|
1322 |
|
1323 | var pagesOverview = this.pdfViewer.getPagesOverview();
|
1324 | var printContainer = this.appConfig.printContainer;
|
1325 | var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
|
1326 | this.printService = printService;
|
1327 | this.forceRendering();
|
1328 | printService.layout();
|
1329 | },
|
1330 | afterPrint: function pdfViewSetupAfterPrint() {
|
1331 | if (this.printService) {
|
1332 | this.printService.destroy();
|
1333 | this.printService = null;
|
1334 | }
|
1335 |
|
1336 | this.forceRendering();
|
1337 | },
|
1338 | rotatePages: function rotatePages(delta) {
|
1339 | if (!this.pdfDocument) {
|
1340 | return;
|
1341 | }
|
1342 |
|
1343 | var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
|
1344 | this.pdfViewer.pagesRotation = newRotation;
|
1345 | },
|
1346 | requestPresentationMode: function requestPresentationMode() {
|
1347 | if (!this.pdfPresentationMode) {
|
1348 | return;
|
1349 | }
|
1350 |
|
1351 | this.pdfPresentationMode.request();
|
1352 | },
|
1353 | bindEvents: function bindEvents() {
|
1354 | var eventBus = this.eventBus,
|
1355 | _boundEvents = this._boundEvents;
|
1356 | _boundEvents.beforePrint = this.beforePrint.bind(this);
|
1357 | _boundEvents.afterPrint = this.afterPrint.bind(this);
|
1358 | eventBus.on('resize', webViewerResize);
|
1359 | eventBus.on('hashchange', webViewerHashchange);
|
1360 | eventBus.on('beforeprint', _boundEvents.beforePrint);
|
1361 | eventBus.on('afterprint', _boundEvents.afterPrint);
|
1362 | eventBus.on('pagerendered', webViewerPageRendered);
|
1363 | eventBus.on('textlayerrendered', webViewerTextLayerRendered);
|
1364 | eventBus.on('updateviewarea', webViewerUpdateViewarea);
|
1365 | eventBus.on('pagechanging', webViewerPageChanging);
|
1366 | eventBus.on('scalechanging', webViewerScaleChanging);
|
1367 | eventBus.on('rotationchanging', webViewerRotationChanging);
|
1368 | eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
|
1369 | eventBus.on('pagemode', webViewerPageMode);
|
1370 | eventBus.on('namedaction', webViewerNamedAction);
|
1371 | eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
|
1372 | eventBus.on('presentationmode', webViewerPresentationMode);
|
1373 | eventBus.on('openfile', webViewerOpenFile);
|
1374 | eventBus.on('print', webViewerPrint);
|
1375 | eventBus.on('download', webViewerDownload);
|
1376 | eventBus.on('firstpage', webViewerFirstPage);
|
1377 | eventBus.on('lastpage', webViewerLastPage);
|
1378 | eventBus.on('nextpage', webViewerNextPage);
|
1379 | eventBus.on('previouspage', webViewerPreviousPage);
|
1380 | eventBus.on('zoomin', webViewerZoomIn);
|
1381 | eventBus.on('zoomout', webViewerZoomOut);
|
1382 | eventBus.on('zoomreset', webViewerZoomReset);
|
1383 | eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
|
1384 | eventBus.on('scalechanged', webViewerScaleChanged);
|
1385 | eventBus.on('rotatecw', webViewerRotateCw);
|
1386 | eventBus.on('rotateccw', webViewerRotateCcw);
|
1387 | eventBus.on('switchscrollmode', webViewerSwitchScrollMode);
|
1388 | eventBus.on('scrollmodechanged', webViewerScrollModeChanged);
|
1389 | eventBus.on('switchspreadmode', webViewerSwitchSpreadMode);
|
1390 | eventBus.on('spreadmodechanged', webViewerSpreadModeChanged);
|
1391 | eventBus.on('documentproperties', webViewerDocumentProperties);
|
1392 | eventBus.on('find', webViewerFind);
|
1393 | eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
|
1394 | eventBus.on('updatefindmatchescount', webViewerUpdateFindMatchesCount);
|
1395 | eventBus.on('updatefindcontrolstate', webViewerUpdateFindControlState);
|
1396 | eventBus.on('fileinputchange', webViewerFileInputChange);
|
1397 | },
|
1398 | bindWindowEvents: function bindWindowEvents() {
|
1399 | var eventBus = this.eventBus,
|
1400 | _boundEvents = this._boundEvents;
|
1401 |
|
1402 | _boundEvents.windowResize = function () {
|
1403 | eventBus.dispatch('resize', {
|
1404 | source: window
|
1405 | });
|
1406 | };
|
1407 |
|
1408 | _boundEvents.windowHashChange = function () {
|
1409 | eventBus.dispatch('hashchange', {
|
1410 | source: window,
|
1411 | hash: document.location.hash.substring(1)
|
1412 | });
|
1413 | };
|
1414 |
|
1415 | _boundEvents.windowBeforePrint = function () {
|
1416 | eventBus.dispatch('beforeprint', {
|
1417 | source: window
|
1418 | });
|
1419 | };
|
1420 |
|
1421 | _boundEvents.windowAfterPrint = function () {
|
1422 | eventBus.dispatch('afterprint', {
|
1423 | source: window
|
1424 | });
|
1425 | };
|
1426 |
|
1427 | window.addEventListener('visibilitychange', webViewerVisibilityChange);
|
1428 | window.addEventListener('wheel', webViewerWheel, {
|
1429 | passive: false
|
1430 | });
|
1431 | window.addEventListener('click', webViewerClick);
|
1432 | window.addEventListener('keydown', webViewerKeyDown);
|
1433 | window.addEventListener('resize', _boundEvents.windowResize);
|
1434 | window.addEventListener('hashchange', _boundEvents.windowHashChange);
|
1435 | window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
|
1436 | window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
|
1437 | },
|
1438 | unbindEvents: function unbindEvents() {
|
1439 | var eventBus = this.eventBus,
|
1440 | _boundEvents = this._boundEvents;
|
1441 | eventBus.off('resize', webViewerResize);
|
1442 | eventBus.off('hashchange', webViewerHashchange);
|
1443 | eventBus.off('beforeprint', _boundEvents.beforePrint);
|
1444 | eventBus.off('afterprint', _boundEvents.afterPrint);
|
1445 | eventBus.off('pagerendered', webViewerPageRendered);
|
1446 | eventBus.off('textlayerrendered', webViewerTextLayerRendered);
|
1447 | eventBus.off('updateviewarea', webViewerUpdateViewarea);
|
1448 | eventBus.off('pagechanging', webViewerPageChanging);
|
1449 | eventBus.off('scalechanging', webViewerScaleChanging);
|
1450 | eventBus.off('rotationchanging', webViewerRotationChanging);
|
1451 | eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
|
1452 | eventBus.off('pagemode', webViewerPageMode);
|
1453 | eventBus.off('namedaction', webViewerNamedAction);
|
1454 | eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
|
1455 | eventBus.off('presentationmode', webViewerPresentationMode);
|
1456 | eventBus.off('openfile', webViewerOpenFile);
|
1457 | eventBus.off('print', webViewerPrint);
|
1458 | eventBus.off('download', webViewerDownload);
|
1459 | eventBus.off('firstpage', webViewerFirstPage);
|
1460 | eventBus.off('lastpage', webViewerLastPage);
|
1461 | eventBus.off('nextpage', webViewerNextPage);
|
1462 | eventBus.off('previouspage', webViewerPreviousPage);
|
1463 | eventBus.off('zoomin', webViewerZoomIn);
|
1464 | eventBus.off('zoomout', webViewerZoomOut);
|
1465 | eventBus.off('zoomreset', webViewerZoomReset);
|
1466 | eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
|
1467 | eventBus.off('scalechanged', webViewerScaleChanged);
|
1468 | eventBus.off('rotatecw', webViewerRotateCw);
|
1469 | eventBus.off('rotateccw', webViewerRotateCcw);
|
1470 | eventBus.off('switchscrollmode', webViewerSwitchScrollMode);
|
1471 | eventBus.off('scrollmodechanged', webViewerScrollModeChanged);
|
1472 | eventBus.off('switchspreadmode', webViewerSwitchSpreadMode);
|
1473 | eventBus.off('spreadmodechanged', webViewerSpreadModeChanged);
|
1474 | eventBus.off('documentproperties', webViewerDocumentProperties);
|
1475 | eventBus.off('find', webViewerFind);
|
1476 | eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
|
1477 | eventBus.off('updatefindmatchescount', webViewerUpdateFindMatchesCount);
|
1478 | eventBus.off('updatefindcontrolstate', webViewerUpdateFindControlState);
|
1479 | eventBus.off('fileinputchange', webViewerFileInputChange);
|
1480 | _boundEvents.beforePrint = null;
|
1481 | _boundEvents.afterPrint = null;
|
1482 | },
|
1483 | unbindWindowEvents: function unbindWindowEvents() {
|
1484 | var _boundEvents = this._boundEvents;
|
1485 | window.removeEventListener('visibilitychange', webViewerVisibilityChange);
|
1486 | window.removeEventListener('wheel', webViewerWheel);
|
1487 | window.removeEventListener('click', webViewerClick);
|
1488 | window.removeEventListener('keydown', webViewerKeyDown);
|
1489 | window.removeEventListener('resize', _boundEvents.windowResize);
|
1490 | window.removeEventListener('hashchange', _boundEvents.windowHashChange);
|
1491 | window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
|
1492 | window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
|
1493 | _boundEvents.windowResize = null;
|
1494 | _boundEvents.windowHashChange = null;
|
1495 | _boundEvents.windowBeforePrint = null;
|
1496 | _boundEvents.windowAfterPrint = null;
|
1497 | }
|
1498 | };
|
1499 | exports.PDFViewerApplication = PDFViewerApplication;
|
1500 | var validateFileURL;
|
1501 | {
|
1502 | var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
|
1503 |
|
1504 | validateFileURL = function validateFileURL(file) {
|
1505 | if (file === undefined) {
|
1506 | return;
|
1507 | }
|
1508 |
|
1509 | try {
|
1510 | var viewerOrigin = new _pdf.URL(window.location.href).origin || 'null';
|
1511 |
|
1512 | if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
1513 | return;
|
1514 | }
|
1515 |
|
1516 | var _ref8 = new _pdf.URL(file, window.location.href),
|
1517 | origin = _ref8.origin,
|
1518 | protocol = _ref8.protocol;
|
1519 |
|
1520 | if (origin !== viewerOrigin && protocol !== 'blob:') {
|
1521 | throw new Error('file origin does not match viewer\'s');
|
1522 | }
|
1523 | } catch (ex) {
|
1524 | var message = ex && ex.message;
|
1525 | PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
|
1526 | PDFViewerApplication.error(loadingErrorMessage, {
|
1527 | message: message
|
1528 | });
|
1529 | });
|
1530 | throw ex;
|
1531 | }
|
1532 | };
|
1533 | }
|
1534 |
|
1535 | function loadFakeWorker() {
|
1536 | if (!_pdf.GlobalWorkerOptions.workerSrc) {
|
1537 | _pdf.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get('workerSrc');
|
1538 | }
|
1539 |
|
1540 | return (0, _pdf.loadScript)(_pdf.PDFWorker.getWorkerSrc());
|
1541 | }
|
1542 |
|
1543 | function loadAndEnablePDFBug(enabledTabs) {
|
1544 | var appConfig = PDFViewerApplication.appConfig;
|
1545 | return (0, _pdf.loadScript)(appConfig.debuggerScriptPath).then(function () {
|
1546 | PDFBug.enable(enabledTabs);
|
1547 | PDFBug.init({
|
1548 | OPS: _pdf.OPS,
|
1549 | createObjectURL: _pdf.createObjectURL
|
1550 | }, appConfig.mainContainer);
|
1551 | });
|
1552 | }
|
1553 |
|
1554 | function webViewerInitialized() {
|
1555 | var appConfig = PDFViewerApplication.appConfig;
|
1556 | var file;
|
1557 | var queryString = document.location.search.substring(1);
|
1558 | var params = (0, _ui_utils.parseQueryString)(queryString);
|
1559 | file = 'file' in params ? params.file : _app_options.AppOptions.get('defaultUrl');
|
1560 | validateFileURL(file);
|
1561 | var fileInput = document.createElement('input');
|
1562 | fileInput.id = appConfig.openFileInputName;
|
1563 | fileInput.className = 'fileInput';
|
1564 | fileInput.setAttribute('type', 'file');
|
1565 | fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
|
1566 | document.body.appendChild(fileInput);
|
1567 |
|
1568 | if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
|
1569 | appConfig.toolbar.openFile.setAttribute('hidden', 'true');
|
1570 | appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
|
1571 | } else {
|
1572 | fileInput.value = null;
|
1573 | }
|
1574 |
|
1575 | fileInput.addEventListener('change', function (evt) {
|
1576 | var files = evt.target.files;
|
1577 |
|
1578 | if (!files || files.length === 0) {
|
1579 | return;
|
1580 | }
|
1581 |
|
1582 | PDFViewerApplication.eventBus.dispatch('fileinputchange', {
|
1583 | source: this,
|
1584 | fileInput: evt.target
|
1585 | });
|
1586 | });
|
1587 | appConfig.mainContainer.addEventListener('dragover', function (evt) {
|
1588 | evt.preventDefault();
|
1589 | evt.dataTransfer.dropEffect = 'move';
|
1590 | });
|
1591 | appConfig.mainContainer.addEventListener('drop', function (evt) {
|
1592 | evt.preventDefault();
|
1593 | var files = evt.dataTransfer.files;
|
1594 |
|
1595 | if (!files || files.length === 0) {
|
1596 | return;
|
1597 | }
|
1598 |
|
1599 | PDFViewerApplication.eventBus.dispatch('fileinputchange', {
|
1600 | source: this,
|
1601 | fileInput: evt.dataTransfer
|
1602 | });
|
1603 | });
|
1604 |
|
1605 | if (!PDFViewerApplication.supportsPrinting) {
|
1606 | appConfig.toolbar.print.classList.add('hidden');
|
1607 | appConfig.secondaryToolbar.printButton.classList.add('hidden');
|
1608 | }
|
1609 |
|
1610 | if (!PDFViewerApplication.supportsFullscreen) {
|
1611 | appConfig.toolbar.presentationModeButton.classList.add('hidden');
|
1612 | appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
|
1613 | }
|
1614 |
|
1615 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1616 | appConfig.toolbar.viewFind.classList.add('hidden');
|
1617 | }
|
1618 |
|
1619 | appConfig.mainContainer.addEventListener('transitionend', function (evt) {
|
1620 | if (evt.target === this) {
|
1621 | PDFViewerApplication.eventBus.dispatch('resize', {
|
1622 | source: this
|
1623 | });
|
1624 | }
|
1625 | }, true);
|
1626 | appConfig.sidebar.toggleButton.addEventListener('click', function () {
|
1627 | PDFViewerApplication.pdfSidebar.toggle();
|
1628 | });
|
1629 |
|
1630 | try {
|
1631 | webViewerOpenFileViaURL(file);
|
1632 | } catch (reason) {
|
1633 | PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
|
1634 | PDFViewerApplication.error(msg, reason);
|
1635 | });
|
1636 | }
|
1637 | }
|
1638 |
|
1639 | var webViewerOpenFileViaURL;
|
1640 | {
|
1641 | webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
|
1642 | if (file && file.lastIndexOf('file:', 0) === 0) {
|
1643 | PDFViewerApplication.setTitleUsingUrl(file);
|
1644 | var xhr = new XMLHttpRequest();
|
1645 |
|
1646 | xhr.onload = function () {
|
1647 | PDFViewerApplication.open(new Uint8Array(xhr.response));
|
1648 | };
|
1649 |
|
1650 | xhr.open('GET', file);
|
1651 | xhr.responseType = 'arraybuffer';
|
1652 | xhr.send();
|
1653 | return;
|
1654 | }
|
1655 |
|
1656 | if (file) {
|
1657 | PDFViewerApplication.open(file);
|
1658 | }
|
1659 | };
|
1660 | }
|
1661 |
|
1662 | function webViewerPageRendered(evt) {
|
1663 | var pageNumber = evt.pageNumber;
|
1664 | var pageIndex = pageNumber - 1;
|
1665 | var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
1666 |
|
1667 | if (pageNumber === PDFViewerApplication.page) {
|
1668 | PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
|
1669 | }
|
1670 |
|
1671 | if (!pageView) {
|
1672 | return;
|
1673 | }
|
1674 |
|
1675 | if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
1676 | var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
|
1677 | thumbnailView.setImage(pageView);
|
1678 | }
|
1679 |
|
1680 | if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
|
1681 | Stats.add(pageNumber, pageView.stats);
|
1682 | }
|
1683 |
|
1684 | if (pageView.error) {
|
1685 | PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
|
1686 | PDFViewerApplication.error(msg, pageView.error);
|
1687 | });
|
1688 | }
|
1689 | }
|
1690 |
|
1691 | function webViewerTextLayerRendered(evt) {}
|
1692 |
|
1693 | function webViewerPageMode(evt) {
|
1694 | var mode = evt.mode,
|
1695 | view;
|
1696 |
|
1697 | switch (mode) {
|
1698 | case 'thumbs':
|
1699 | view = _pdf_sidebar.SidebarView.THUMBS;
|
1700 | break;
|
1701 |
|
1702 | case 'bookmarks':
|
1703 | case 'outline':
|
1704 | view = _pdf_sidebar.SidebarView.OUTLINE;
|
1705 | break;
|
1706 |
|
1707 | case 'attachments':
|
1708 | view = _pdf_sidebar.SidebarView.ATTACHMENTS;
|
1709 | break;
|
1710 |
|
1711 | case 'none':
|
1712 | view = _pdf_sidebar.SidebarView.NONE;
|
1713 | break;
|
1714 |
|
1715 | default:
|
1716 | console.error('Invalid "pagemode" hash parameter: ' + mode);
|
1717 | return;
|
1718 | }
|
1719 |
|
1720 | PDFViewerApplication.pdfSidebar.switchView(view, true);
|
1721 | }
|
1722 |
|
1723 | function webViewerNamedAction(evt) {
|
1724 | var action = evt.action;
|
1725 |
|
1726 | switch (action) {
|
1727 | case 'GoToPage':
|
1728 | PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
1729 | break;
|
1730 |
|
1731 | case 'Find':
|
1732 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
1733 | PDFViewerApplication.findBar.toggle();
|
1734 | }
|
1735 |
|
1736 | break;
|
1737 | }
|
1738 | }
|
1739 |
|
1740 | function webViewerPresentationModeChanged(evt) {
|
1741 | var active = evt.active,
|
1742 | switchInProgress = evt.switchInProgress;
|
1743 | PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
|
1744 | }
|
1745 |
|
1746 | function webViewerSidebarViewChanged(evt) {
|
1747 | PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
|
1748 | var store = PDFViewerApplication.store;
|
1749 |
|
1750 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1751 | store.set('sidebarView', evt.view)["catch"](function () {});
|
1752 | }
|
1753 | }
|
1754 |
|
1755 | function webViewerUpdateViewarea(evt) {
|
1756 | var location = evt.location,
|
1757 | store = PDFViewerApplication.store;
|
1758 |
|
1759 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1760 | store.setMultiple({
|
1761 | 'page': location.pageNumber,
|
1762 | 'zoom': location.scale,
|
1763 | 'scrollLeft': location.left,
|
1764 | 'scrollTop': location.top,
|
1765 | 'rotation': location.rotation
|
1766 | })["catch"](function () {});
|
1767 | }
|
1768 |
|
1769 | var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
|
1770 | PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
|
1771 | PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
1772 | var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
|
1773 | var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
|
1774 | PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
|
1775 | }
|
1776 |
|
1777 | function webViewerScrollModeChanged(evt) {
|
1778 | var store = PDFViewerApplication.store;
|
1779 |
|
1780 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1781 | store.set('scrollMode', evt.mode)["catch"](function () {});
|
1782 | }
|
1783 | }
|
1784 |
|
1785 | function webViewerSpreadModeChanged(evt) {
|
1786 | var store = PDFViewerApplication.store;
|
1787 |
|
1788 | if (store && PDFViewerApplication.isInitialViewSet) {
|
1789 | store.set('spreadMode', evt.mode)["catch"](function () {});
|
1790 | }
|
1791 | }
|
1792 |
|
1793 | function webViewerResize() {
|
1794 | var pdfDocument = PDFViewerApplication.pdfDocument,
|
1795 | pdfViewer = PDFViewerApplication.pdfViewer;
|
1796 |
|
1797 | if (!pdfDocument) {
|
1798 | return;
|
1799 | }
|
1800 |
|
1801 | var currentScaleValue = pdfViewer.currentScaleValue;
|
1802 |
|
1803 | if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
|
1804 | pdfViewer.currentScaleValue = currentScaleValue;
|
1805 | }
|
1806 |
|
1807 | pdfViewer.update();
|
1808 | }
|
1809 |
|
1810 | function webViewerHashchange(evt) {
|
1811 | var hash = evt.hash;
|
1812 |
|
1813 | if (!hash) {
|
1814 | return;
|
1815 | }
|
1816 |
|
1817 | if (!PDFViewerApplication.isInitialViewSet) {
|
1818 | PDFViewerApplication.initialBookmark = hash;
|
1819 | } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
|
1820 | PDFViewerApplication.pdfLinkService.setHash(hash);
|
1821 | }
|
1822 | }
|
1823 |
|
1824 | var webViewerFileInputChange;
|
1825 | {
|
1826 | webViewerFileInputChange = function webViewerFileInputChange(evt) {
|
1827 | if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
1828 | return;
|
1829 | }
|
1830 |
|
1831 | var file = evt.fileInput.files[0];
|
1832 |
|
1833 | if (_pdf.URL.createObjectURL && !_app_options.AppOptions.get('disableCreateObjectURL')) {
|
1834 | var url = _pdf.URL.createObjectURL(file);
|
1835 |
|
1836 | if (file.name) {
|
1837 | url = {
|
1838 | url: url,
|
1839 | originalUrl: file.name
|
1840 | };
|
1841 | }
|
1842 |
|
1843 | PDFViewerApplication.open(url);
|
1844 | } else {
|
1845 | PDFViewerApplication.setTitleUsingUrl(file.name);
|
1846 | var fileReader = new FileReader();
|
1847 |
|
1848 | fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
1849 | var buffer = evt.target.result;
|
1850 | PDFViewerApplication.open(new Uint8Array(buffer));
|
1851 | };
|
1852 |
|
1853 | fileReader.readAsArrayBuffer(file);
|
1854 | }
|
1855 |
|
1856 | var appConfig = PDFViewerApplication.appConfig;
|
1857 | appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
|
1858 | appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
|
1859 | appConfig.toolbar.download.setAttribute('hidden', 'true');
|
1860 | appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
|
1861 | };
|
1862 | }
|
1863 |
|
1864 | function webViewerPresentationMode() {
|
1865 | PDFViewerApplication.requestPresentationMode();
|
1866 | }
|
1867 |
|
1868 | function webViewerOpenFile() {
|
1869 | var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
1870 | document.getElementById(openFileInputName).click();
|
1871 | }
|
1872 |
|
1873 | function webViewerPrint() {
|
1874 | window.print();
|
1875 | }
|
1876 |
|
1877 | function webViewerDownload() {
|
1878 | PDFViewerApplication.download();
|
1879 | }
|
1880 |
|
1881 | function webViewerFirstPage() {
|
1882 | if (PDFViewerApplication.pdfDocument) {
|
1883 | PDFViewerApplication.page = 1;
|
1884 | }
|
1885 | }
|
1886 |
|
1887 | function webViewerLastPage() {
|
1888 | if (PDFViewerApplication.pdfDocument) {
|
1889 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
1890 | }
|
1891 | }
|
1892 |
|
1893 | function webViewerNextPage() {
|
1894 | PDFViewerApplication.page++;
|
1895 | }
|
1896 |
|
1897 | function webViewerPreviousPage() {
|
1898 | PDFViewerApplication.page--;
|
1899 | }
|
1900 |
|
1901 | function webViewerZoomIn() {
|
1902 | PDFViewerApplication.zoomIn();
|
1903 | }
|
1904 |
|
1905 | function webViewerZoomOut() {
|
1906 | PDFViewerApplication.zoomOut();
|
1907 | }
|
1908 |
|
1909 | function webViewerZoomReset(evt) {
|
1910 | PDFViewerApplication.zoomReset(evt && evt.ignoreDuplicate);
|
1911 | }
|
1912 |
|
1913 | function webViewerPageNumberChanged(evt) {
|
1914 | var pdfViewer = PDFViewerApplication.pdfViewer;
|
1915 |
|
1916 | if (evt.value !== '') {
|
1917 | pdfViewer.currentPageLabel = evt.value;
|
1918 | }
|
1919 |
|
1920 | if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
|
1921 | PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
1922 | }
|
1923 | }
|
1924 |
|
1925 | function webViewerScaleChanged(evt) {
|
1926 | PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
|
1927 | }
|
1928 |
|
1929 | function webViewerRotateCw() {
|
1930 | PDFViewerApplication.rotatePages(90);
|
1931 | }
|
1932 |
|
1933 | function webViewerRotateCcw() {
|
1934 | PDFViewerApplication.rotatePages(-90);
|
1935 | }
|
1936 |
|
1937 | function webViewerSwitchScrollMode(evt) {
|
1938 | PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
|
1939 | }
|
1940 |
|
1941 | function webViewerSwitchSpreadMode(evt) {
|
1942 | PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
1943 | }
|
1944 |
|
1945 | function webViewerDocumentProperties() {
|
1946 | PDFViewerApplication.pdfDocumentProperties.open();
|
1947 | }
|
1948 |
|
1949 | function webViewerFind(evt) {
|
1950 | PDFViewerApplication.findController.executeCommand('find' + evt.type, {
|
1951 | query: evt.query,
|
1952 | phraseSearch: evt.phraseSearch,
|
1953 | caseSensitive: evt.caseSensitive,
|
1954 | entireWord: evt.entireWord,
|
1955 | highlightAll: evt.highlightAll,
|
1956 | findPrevious: evt.findPrevious
|
1957 | });
|
1958 | }
|
1959 |
|
1960 | function webViewerFindFromUrlHash(evt) {
|
1961 | PDFViewerApplication.findController.executeCommand('find', {
|
1962 | query: evt.query,
|
1963 | phraseSearch: evt.phraseSearch,
|
1964 | caseSensitive: false,
|
1965 | entireWord: false,
|
1966 | highlightAll: true,
|
1967 | findPrevious: false
|
1968 | });
|
1969 | }
|
1970 |
|
1971 | function webViewerUpdateFindMatchesCount(_ref9) {
|
1972 | var matchesCount = _ref9.matchesCount;
|
1973 |
|
1974 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1975 | PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
|
1976 | } else {
|
1977 | PDFViewerApplication.findBar.updateResultsCount(matchesCount);
|
1978 | }
|
1979 | }
|
1980 |
|
1981 | function webViewerUpdateFindControlState(_ref10) {
|
1982 | var state = _ref10.state,
|
1983 | previous = _ref10.previous,
|
1984 | matchesCount = _ref10.matchesCount;
|
1985 |
|
1986 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1987 | PDFViewerApplication.externalServices.updateFindControlState({
|
1988 | result: state,
|
1989 | findPrevious: previous,
|
1990 | matchesCount: matchesCount
|
1991 | });
|
1992 | } else {
|
1993 | PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
|
1994 | }
|
1995 | }
|
1996 |
|
1997 | function webViewerScaleChanging(evt) {
|
1998 | PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
|
1999 | PDFViewerApplication.pdfViewer.update();
|
2000 | }
|
2001 |
|
2002 | function webViewerRotationChanging(evt) {
|
2003 | PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
2004 | PDFViewerApplication.forceRendering();
|
2005 | PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
2006 | }
|
2007 |
|
2008 | function webViewerPageChanging(evt) {
|
2009 | var page = evt.pageNumber;
|
2010 | PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
|
2011 | PDFViewerApplication.secondaryToolbar.setPageNumber(page);
|
2012 |
|
2013 | if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
|
2014 | PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
|
2015 | }
|
2016 |
|
2017 | if (typeof Stats !== 'undefined' && Stats.enabled) {
|
2018 | var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
|
2019 |
|
2020 | if (pageView && pageView.stats) {
|
2021 | Stats.add(page, pageView.stats);
|
2022 | }
|
2023 | }
|
2024 | }
|
2025 |
|
2026 | function webViewerVisibilityChange(evt) {
|
2027 | if (document.visibilityState === 'visible') {
|
2028 | setZoomDisabledTimeout();
|
2029 | }
|
2030 | }
|
2031 |
|
2032 | var zoomDisabledTimeout = null;
|
2033 |
|
2034 | function setZoomDisabledTimeout() {
|
2035 | if (zoomDisabledTimeout) {
|
2036 | clearTimeout(zoomDisabledTimeout);
|
2037 | }
|
2038 |
|
2039 | zoomDisabledTimeout = setTimeout(function () {
|
2040 | zoomDisabledTimeout = null;
|
2041 | }, WHEEL_ZOOM_DISABLED_TIMEOUT);
|
2042 | }
|
2043 |
|
2044 | function webViewerWheel(evt) {
|
2045 | var pdfViewer = PDFViewerApplication.pdfViewer;
|
2046 |
|
2047 | if (pdfViewer.isInPresentationMode) {
|
2048 | return;
|
2049 | }
|
2050 |
|
2051 | if (evt.ctrlKey || evt.metaKey) {
|
2052 | var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
|
2053 |
|
2054 | if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
|
2055 | return;
|
2056 | }
|
2057 |
|
2058 | evt.preventDefault();
|
2059 |
|
2060 | if (zoomDisabledTimeout || document.visibilityState === 'hidden') {
|
2061 | return;
|
2062 | }
|
2063 |
|
2064 | var previousScale = pdfViewer.currentScale;
|
2065 | var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
|
2066 | var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
|
2067 | var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
|
2068 |
|
2069 | if (ticks < 0) {
|
2070 | PDFViewerApplication.zoomOut(-ticks);
|
2071 | } else {
|
2072 | PDFViewerApplication.zoomIn(ticks);
|
2073 | }
|
2074 |
|
2075 | var currentScale = pdfViewer.currentScale;
|
2076 |
|
2077 | if (previousScale !== currentScale) {
|
2078 | var scaleCorrectionFactor = currentScale / previousScale - 1;
|
2079 | var rect = pdfViewer.container.getBoundingClientRect();
|
2080 | var dx = evt.clientX - rect.left;
|
2081 | var dy = evt.clientY - rect.top;
|
2082 | pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
2083 | pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
2084 | }
|
2085 | } else {
|
2086 | setZoomDisabledTimeout();
|
2087 | }
|
2088 | }
|
2089 |
|
2090 | function webViewerClick(evt) {
|
2091 | if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
2092 | return;
|
2093 | }
|
2094 |
|
2095 | var appConfig = PDFViewerApplication.appConfig;
|
2096 |
|
2097 | if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
|
2098 | PDFViewerApplication.secondaryToolbar.close();
|
2099 | }
|
2100 | }
|
2101 |
|
2102 | function webViewerKeyDown(evt) {
|
2103 | if (PDFViewerApplication.overlayManager.active) {
|
2104 | return;
|
2105 | }
|
2106 |
|
2107 | var handled = false,
|
2108 | ensureViewerFocused = false;
|
2109 | var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
|
2110 | var pdfViewer = PDFViewerApplication.pdfViewer;
|
2111 | var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
|
2112 |
|
2113 | if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
2114 | switch (evt.keyCode) {
|
2115 | case 70:
|
2116 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
2117 | PDFViewerApplication.findBar.open();
|
2118 | handled = true;
|
2119 | }
|
2120 |
|
2121 | break;
|
2122 |
|
2123 | case 71:
|
2124 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
2125 | var findState = PDFViewerApplication.findController.state;
|
2126 |
|
2127 | if (findState) {
|
2128 | PDFViewerApplication.findController.executeCommand('findagain', {
|
2129 | query: findState.query,
|
2130 | phraseSearch: findState.phraseSearch,
|
2131 | caseSensitive: findState.caseSensitive,
|
2132 | entireWord: findState.entireWord,
|
2133 | highlightAll: findState.highlightAll,
|
2134 | findPrevious: cmd === 5 || cmd === 12
|
2135 | });
|
2136 | }
|
2137 |
|
2138 | handled = true;
|
2139 | }
|
2140 |
|
2141 | break;
|
2142 |
|
2143 | case 61:
|
2144 | case 107:
|
2145 | case 187:
|
2146 | case 171:
|
2147 | if (!isViewerInPresentationMode) {
|
2148 | PDFViewerApplication.zoomIn();
|
2149 | }
|
2150 |
|
2151 | handled = true;
|
2152 | break;
|
2153 |
|
2154 | case 173:
|
2155 | case 109:
|
2156 | case 189:
|
2157 | if (!isViewerInPresentationMode) {
|
2158 | PDFViewerApplication.zoomOut();
|
2159 | }
|
2160 |
|
2161 | handled = true;
|
2162 | break;
|
2163 |
|
2164 | case 48:
|
2165 | case 96:
|
2166 | if (!isViewerInPresentationMode) {
|
2167 | setTimeout(function () {
|
2168 | PDFViewerApplication.zoomReset();
|
2169 | });
|
2170 | handled = false;
|
2171 | }
|
2172 |
|
2173 | break;
|
2174 |
|
2175 | case 38:
|
2176 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2177 | PDFViewerApplication.page = 1;
|
2178 | handled = true;
|
2179 | ensureViewerFocused = true;
|
2180 | }
|
2181 |
|
2182 | break;
|
2183 |
|
2184 | case 40:
|
2185 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2186 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2187 | handled = true;
|
2188 | ensureViewerFocused = true;
|
2189 | }
|
2190 |
|
2191 | break;
|
2192 | }
|
2193 | }
|
2194 |
|
2195 | if (cmd === 1 || cmd === 8) {
|
2196 | switch (evt.keyCode) {
|
2197 | case 83:
|
2198 | PDFViewerApplication.download();
|
2199 | handled = true;
|
2200 | break;
|
2201 | }
|
2202 | }
|
2203 |
|
2204 | if (cmd === 3 || cmd === 10) {
|
2205 | switch (evt.keyCode) {
|
2206 | case 80:
|
2207 | PDFViewerApplication.requestPresentationMode();
|
2208 | handled = true;
|
2209 | break;
|
2210 |
|
2211 | case 71:
|
2212 | PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
2213 | handled = true;
|
2214 | break;
|
2215 | }
|
2216 | }
|
2217 |
|
2218 | if (handled) {
|
2219 | if (ensureViewerFocused && !isViewerInPresentationMode) {
|
2220 | pdfViewer.focus();
|
2221 | }
|
2222 |
|
2223 | evt.preventDefault();
|
2224 | return;
|
2225 | }
|
2226 |
|
2227 | var curElement = document.activeElement || document.querySelector(':focus');
|
2228 | var curElementTagName = curElement && curElement.tagName.toUpperCase();
|
2229 |
|
2230 | if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
|
2231 | if (evt.keyCode !== 27) {
|
2232 | return;
|
2233 | }
|
2234 | }
|
2235 |
|
2236 | if (cmd === 0) {
|
2237 | var turnPage = 0,
|
2238 | turnOnlyIfPageFit = false;
|
2239 |
|
2240 | switch (evt.keyCode) {
|
2241 | case 38:
|
2242 | case 33:
|
2243 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2244 | turnOnlyIfPageFit = true;
|
2245 | }
|
2246 |
|
2247 | turnPage = -1;
|
2248 | break;
|
2249 |
|
2250 | case 8:
|
2251 | if (!isViewerInPresentationMode) {
|
2252 | turnOnlyIfPageFit = true;
|
2253 | }
|
2254 |
|
2255 | turnPage = -1;
|
2256 | break;
|
2257 |
|
2258 | case 37:
|
2259 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2260 | turnOnlyIfPageFit = true;
|
2261 | }
|
2262 |
|
2263 | case 75:
|
2264 | case 80:
|
2265 | turnPage = -1;
|
2266 | break;
|
2267 |
|
2268 | case 27:
|
2269 | if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
2270 | PDFViewerApplication.secondaryToolbar.close();
|
2271 | handled = true;
|
2272 | }
|
2273 |
|
2274 | if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
|
2275 | PDFViewerApplication.findBar.close();
|
2276 | handled = true;
|
2277 | }
|
2278 |
|
2279 | break;
|
2280 |
|
2281 | case 40:
|
2282 | case 34:
|
2283 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2284 | turnOnlyIfPageFit = true;
|
2285 | }
|
2286 |
|
2287 | turnPage = 1;
|
2288 | break;
|
2289 |
|
2290 | case 13:
|
2291 | case 32:
|
2292 | if (!isViewerInPresentationMode) {
|
2293 | turnOnlyIfPageFit = true;
|
2294 | }
|
2295 |
|
2296 | turnPage = 1;
|
2297 | break;
|
2298 |
|
2299 | case 39:
|
2300 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2301 | turnOnlyIfPageFit = true;
|
2302 | }
|
2303 |
|
2304 | case 74:
|
2305 | case 78:
|
2306 | turnPage = 1;
|
2307 | break;
|
2308 |
|
2309 | case 36:
|
2310 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2311 | PDFViewerApplication.page = 1;
|
2312 | handled = true;
|
2313 | ensureViewerFocused = true;
|
2314 | }
|
2315 |
|
2316 | break;
|
2317 |
|
2318 | case 35:
|
2319 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2320 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2321 | handled = true;
|
2322 | ensureViewerFocused = true;
|
2323 | }
|
2324 |
|
2325 | break;
|
2326 |
|
2327 | case 83:
|
2328 | PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
|
2329 | break;
|
2330 |
|
2331 | case 72:
|
2332 | PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
|
2333 | break;
|
2334 |
|
2335 | case 82:
|
2336 | PDFViewerApplication.rotatePages(90);
|
2337 | break;
|
2338 |
|
2339 | case 115:
|
2340 | PDFViewerApplication.pdfSidebar.toggle();
|
2341 | break;
|
2342 | }
|
2343 |
|
2344 | if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === 'page-fit')) {
|
2345 | if (turnPage > 0) {
|
2346 | if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2347 | PDFViewerApplication.page++;
|
2348 | }
|
2349 | } else {
|
2350 | if (PDFViewerApplication.page > 1) {
|
2351 | PDFViewerApplication.page--;
|
2352 | }
|
2353 | }
|
2354 |
|
2355 | handled = true;
|
2356 | }
|
2357 | }
|
2358 |
|
2359 | if (cmd === 4) {
|
2360 | switch (evt.keyCode) {
|
2361 | case 13:
|
2362 | case 32:
|
2363 | if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
|
2364 | break;
|
2365 | }
|
2366 |
|
2367 | if (PDFViewerApplication.page > 1) {
|
2368 | PDFViewerApplication.page--;
|
2369 | }
|
2370 |
|
2371 | handled = true;
|
2372 | break;
|
2373 |
|
2374 | case 82:
|
2375 | PDFViewerApplication.rotatePages(-90);
|
2376 | break;
|
2377 | }
|
2378 | }
|
2379 |
|
2380 | if (!handled && !isViewerInPresentationMode) {
|
2381 | if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
|
2382 | ensureViewerFocused = true;
|
2383 | }
|
2384 | }
|
2385 |
|
2386 | if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
|
2387 | pdfViewer.focus();
|
2388 | }
|
2389 |
|
2390 | if (handled) {
|
2391 | evt.preventDefault();
|
2392 | }
|
2393 | }
|
2394 |
|
2395 | function apiPageLayoutToSpreadMode(layout) {
|
2396 | switch (layout) {
|
2397 | case 'SinglePage':
|
2398 | case 'OneColumn':
|
2399 | return _ui_utils.SpreadMode.NONE;
|
2400 |
|
2401 | case 'TwoColumnLeft':
|
2402 | case 'TwoPageLeft':
|
2403 | return _ui_utils.SpreadMode.ODD;
|
2404 |
|
2405 | case 'TwoColumnRight':
|
2406 | case 'TwoPageRight':
|
2407 | return _ui_utils.SpreadMode.EVEN;
|
2408 | }
|
2409 |
|
2410 | return _ui_utils.SpreadMode.NONE;
|
2411 | }
|
2412 |
|
2413 | function apiPageModeToSidebarView(mode) {
|
2414 | switch (mode) {
|
2415 | case 'UseNone':
|
2416 | return _pdf_sidebar.SidebarView.NONE;
|
2417 |
|
2418 | case 'UseThumbs':
|
2419 | return _pdf_sidebar.SidebarView.THUMBS;
|
2420 |
|
2421 | case 'UseOutlines':
|
2422 | return _pdf_sidebar.SidebarView.OUTLINE;
|
2423 |
|
2424 | case 'UseAttachments':
|
2425 | return _pdf_sidebar.SidebarView.ATTACHMENTS;
|
2426 |
|
2427 | case 'UseOC':
|
2428 | }
|
2429 |
|
2430 | return _pdf_sidebar.SidebarView.NONE;
|
2431 | }
|
2432 |
|
2433 | var PDFPrintServiceFactory = {
|
2434 | instance: {
|
2435 | supportsPrinting: false,
|
2436 | createPrintService: function createPrintService() {
|
2437 | throw new Error('Not implemented: createPrintService');
|
2438 | }
|
2439 | }
|
2440 | };
|
2441 | exports.PDFPrintServiceFactory = PDFPrintServiceFactory; |
\ | No newline at end of file |