2
0

app.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  20. var _ui_utils = require('./ui_utils');
  21. var _pdf = require('../pdf');
  22. var _pdf_cursor_tools = require('./pdf_cursor_tools');
  23. var _pdf_rendering_queue = require('./pdf_rendering_queue');
  24. var _pdf_sidebar = require('./pdf_sidebar');
  25. var _pdf_viewer = require('./pdf_viewer');
  26. var _dom_events = require('./dom_events');
  27. var _overlay_manager = require('./overlay_manager');
  28. var _password_prompt = require('./password_prompt');
  29. var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
  30. var _pdf_document_properties = require('./pdf_document_properties');
  31. var _pdf_find_bar = require('./pdf_find_bar');
  32. var _pdf_find_controller = require('./pdf_find_controller');
  33. var _pdf_history = require('./pdf_history');
  34. var _pdf_link_service = require('./pdf_link_service');
  35. var _pdf_outline_viewer = require('./pdf_outline_viewer');
  36. var _pdf_presentation_mode = require('./pdf_presentation_mode');
  37. var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
  38. var _secondary_toolbar = require('./secondary_toolbar');
  39. var _toolbar = require('./toolbar');
  40. var _view_history = require('./view_history');
  41. var DEFAULT_SCALE_DELTA = 1.1;
  42. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  43. function configure(PDFJS) {
  44. PDFJS.imageResourcesPath = './images/';
  45. PDFJS.workerSrc = '../build/pdf.worker.js';
  46. PDFJS.cMapUrl = '../web/cmaps/';
  47. PDFJS.cMapPacked = true;
  48. }
  49. var DefaultExternalServices = {
  50. updateFindControlState: function updateFindControlState(data) {},
  51. initPassiveLoading: function initPassiveLoading(callbacks) {},
  52. fallback: function fallback(data, callback) {},
  53. reportTelemetry: function reportTelemetry(data) {},
  54. createDownloadManager: function createDownloadManager() {
  55. throw new Error('Not implemented: createDownloadManager');
  56. },
  57. createPreferences: function createPreferences() {
  58. throw new Error('Not implemented: createPreferences');
  59. },
  60. createL10n: function createL10n() {
  61. throw new Error('Not implemented: createL10n');
  62. },
  63. supportsIntegratedFind: false,
  64. supportsDocumentFonts: true,
  65. supportsDocumentColors: true,
  66. supportedMouseWheelZoomModifierKeys: {
  67. ctrlKey: true,
  68. metaKey: true
  69. }
  70. };
  71. var PDFViewerApplication = {
  72. initialBookmark: document.location.hash.substring(1),
  73. initialDestination: null,
  74. initialized: false,
  75. fellback: false,
  76. appConfig: null,
  77. pdfDocument: null,
  78. pdfLoadingTask: null,
  79. printService: null,
  80. pdfViewer: null,
  81. pdfThumbnailViewer: null,
  82. pdfRenderingQueue: null,
  83. pdfPresentationMode: null,
  84. pdfDocumentProperties: null,
  85. pdfLinkService: null,
  86. pdfHistory: null,
  87. pdfSidebar: null,
  88. pdfOutlineViewer: null,
  89. pdfAttachmentViewer: null,
  90. pdfCursorTools: null,
  91. store: null,
  92. downloadManager: null,
  93. overlayManager: null,
  94. preferences: null,
  95. toolbar: null,
  96. secondaryToolbar: null,
  97. eventBus: null,
  98. l10n: null,
  99. isInitialViewSet: false,
  100. downloadComplete: false,
  101. viewerPrefs: {
  102. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  103. pdfBugEnabled: false,
  104. showPreviousViewOnLoad: true,
  105. defaultZoomValue: '',
  106. disablePageLabels: false,
  107. renderer: 'canvas',
  108. enhanceTextSelection: false,
  109. renderInteractiveForms: false,
  110. enablePrintAutoRotate: false
  111. },
  112. isViewerEmbedded: window.parent !== window,
  113. url: '',
  114. baseUrl: '',
  115. externalServices: DefaultExternalServices,
  116. _boundEvents: {},
  117. initialize: function initialize(appConfig) {
  118. var _this = this;
  119. this.preferences = this.externalServices.createPreferences();
  120. configure(_pdf.PDFJS);
  121. this.appConfig = appConfig;
  122. return this._readPreferences().then(function () {
  123. return _this._initializeL10n();
  124. }).then(function () {
  125. return _this._initializeViewerComponents();
  126. }).then(function () {
  127. _this.bindEvents();
  128. _this.bindWindowEvents();
  129. var appContainer = appConfig.appContainer || document.documentElement;
  130. _this.l10n.translate(appContainer).then(function () {
  131. _this.eventBus.dispatch('localized');
  132. });
  133. if (_this.isViewerEmbedded && !_pdf.PDFJS.isExternalLinkTargetSet()) {
  134. _pdf.PDFJS.externalLinkTarget = _pdf.PDFJS.LinkTarget.TOP;
  135. }
  136. _this.initialized = true;
  137. });
  138. },
  139. _readPreferences: function _readPreferences() {
  140. var preferences = this.preferences,
  141. viewerPrefs = this.viewerPrefs;
  142. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  143. _pdf.PDFJS.disableWebGL = !value;
  144. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  145. viewerPrefs['sidebarViewOnLoad'] = value;
  146. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  147. viewerPrefs['pdfBugEnabled'] = value;
  148. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  149. viewerPrefs['showPreviousViewOnLoad'] = value;
  150. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  151. viewerPrefs['defaultZoomValue'] = value;
  152. }), preferences.get('enhanceTextSelection').then(function resolved(value) {
  153. viewerPrefs['enhanceTextSelection'] = value;
  154. }), preferences.get('disableTextLayer').then(function resolved(value) {
  155. if (_pdf.PDFJS.disableTextLayer === true) {
  156. return;
  157. }
  158. _pdf.PDFJS.disableTextLayer = value;
  159. }), preferences.get('disableRange').then(function resolved(value) {
  160. if (_pdf.PDFJS.disableRange === true) {
  161. return;
  162. }
  163. _pdf.PDFJS.disableRange = value;
  164. }), preferences.get('disableStream').then(function resolved(value) {
  165. if (_pdf.PDFJS.disableStream === true) {
  166. return;
  167. }
  168. _pdf.PDFJS.disableStream = value;
  169. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  170. _pdf.PDFJS.disableAutoFetch = value;
  171. }), preferences.get('disableFontFace').then(function resolved(value) {
  172. if (_pdf.PDFJS.disableFontFace === true) {
  173. return;
  174. }
  175. _pdf.PDFJS.disableFontFace = value;
  176. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  177. _pdf.PDFJS.useOnlyCssZoom = value;
  178. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  179. if (_pdf.PDFJS.isExternalLinkTargetSet()) {
  180. return;
  181. }
  182. _pdf.PDFJS.externalLinkTarget = value;
  183. }), preferences.get('renderer').then(function resolved(value) {
  184. viewerPrefs['renderer'] = value;
  185. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  186. viewerPrefs['renderInteractiveForms'] = value;
  187. }), preferences.get('disablePageLabels').then(function resolved(value) {
  188. viewerPrefs['disablePageLabels'] = value;
  189. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  190. viewerPrefs['enablePrintAutoRotate'] = value;
  191. })]).catch(function (reason) {});
  192. },
  193. _initializeL10n: function _initializeL10n() {
  194. if (this.viewerPrefs['pdfBugEnabled']) {
  195. var hash = document.location.hash.substring(1);
  196. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  197. if ('locale' in hashParams) {
  198. _pdf.PDFJS.locale = hashParams['locale'];
  199. }
  200. }
  201. this.l10n = this.externalServices.createL10n();
  202. return this.l10n.getDirection().then(function (dir) {
  203. document.getElementsByTagName('html')[0].dir = dir;
  204. });
  205. },
  206. _initializeViewerComponents: function _initializeViewerComponents() {
  207. var _this2 = this;
  208. var appConfig = this.appConfig;
  209. return new Promise(function (resolve, reject) {
  210. _this2.overlayManager = new _overlay_manager.OverlayManager();
  211. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  212. _this2.eventBus = eventBus;
  213. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  214. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  215. _this2.pdfRenderingQueue = pdfRenderingQueue;
  216. var pdfLinkService = new _pdf_link_service.PDFLinkService({ eventBus: eventBus });
  217. _this2.pdfLinkService = pdfLinkService;
  218. var downloadManager = _this2.externalServices.createDownloadManager();
  219. _this2.downloadManager = downloadManager;
  220. var container = appConfig.mainContainer;
  221. var viewer = appConfig.viewerContainer;
  222. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  223. container: container,
  224. viewer: viewer,
  225. eventBus: eventBus,
  226. renderingQueue: pdfRenderingQueue,
  227. linkService: pdfLinkService,
  228. downloadManager: downloadManager,
  229. renderer: _this2.viewerPrefs['renderer'],
  230. l10n: _this2.l10n,
  231. enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
  232. renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
  233. enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
  234. });
  235. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  236. pdfLinkService.setViewer(_this2.pdfViewer);
  237. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  238. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  239. container: thumbnailContainer,
  240. renderingQueue: pdfRenderingQueue,
  241. linkService: pdfLinkService,
  242. l10n: _this2.l10n
  243. });
  244. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  245. _this2.pdfHistory = new _pdf_history.PDFHistory({
  246. linkService: pdfLinkService,
  247. eventBus: eventBus
  248. });
  249. pdfLinkService.setHistory(_this2.pdfHistory);
  250. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  251. _this2.findController.onUpdateResultsCount = function (matchCount) {
  252. if (_this2.supportsIntegratedFind) {
  253. return;
  254. }
  255. _this2.findBar.updateResultsCount(matchCount);
  256. };
  257. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  258. if (_this2.supportsIntegratedFind) {
  259. _this2.externalServices.updateFindControlState({
  260. result: state,
  261. findPrevious: previous
  262. });
  263. } else {
  264. _this2.findBar.updateUIState(state, previous, matchCount);
  265. }
  266. };
  267. _this2.pdfViewer.setFindController(_this2.findController);
  268. var findBarConfig = Object.create(appConfig.findBar);
  269. findBarConfig.findController = _this2.findController;
  270. findBarConfig.eventBus = eventBus;
  271. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
  272. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
  273. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  274. container: container,
  275. eventBus: eventBus,
  276. preferences: _this2.preferences
  277. });
  278. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
  279. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  280. if (_this2.supportsFullscreen) {
  281. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  282. container: container,
  283. viewer: viewer,
  284. pdfViewer: _this2.pdfViewer,
  285. eventBus: eventBus,
  286. contextMenuItems: appConfig.fullscreen
  287. });
  288. }
  289. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
  290. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  291. container: appConfig.sidebar.outlineView,
  292. eventBus: eventBus,
  293. linkService: pdfLinkService
  294. });
  295. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  296. container: appConfig.sidebar.attachmentsView,
  297. eventBus: eventBus,
  298. downloadManager: downloadManager
  299. });
  300. var sidebarConfig = Object.create(appConfig.sidebar);
  301. sidebarConfig.pdfViewer = _this2.pdfViewer;
  302. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  303. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  304. sidebarConfig.eventBus = eventBus;
  305. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
  306. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  307. resolve(undefined);
  308. });
  309. },
  310. run: function run(config) {
  311. this.initialize(config).then(webViewerInitialized);
  312. },
  313. zoomIn: function zoomIn(ticks) {
  314. var newScale = this.pdfViewer.currentScale;
  315. do {
  316. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  317. newScale = Math.ceil(newScale * 10) / 10;
  318. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  319. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  320. this.pdfViewer.currentScaleValue = newScale;
  321. },
  322. zoomOut: function zoomOut(ticks) {
  323. var newScale = this.pdfViewer.currentScale;
  324. do {
  325. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  326. newScale = Math.floor(newScale * 10) / 10;
  327. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  328. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  329. this.pdfViewer.currentScaleValue = newScale;
  330. },
  331. get pagesCount() {
  332. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  333. },
  334. get pageRotation() {
  335. return this.pdfViewer.pagesRotation;
  336. },
  337. set page(val) {
  338. this.pdfViewer.currentPageNumber = val;
  339. },
  340. get page() {
  341. return this.pdfViewer.currentPageNumber;
  342. },
  343. get printing() {
  344. return !!this.printService;
  345. },
  346. get supportsPrinting() {
  347. return PDFPrintServiceFactory.instance.supportsPrinting;
  348. },
  349. get supportsFullscreen() {
  350. var support = void 0;
  351. var doc = document.documentElement;
  352. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  353. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  354. support = false;
  355. }
  356. if (support && _pdf.PDFJS.disableFullscreen === true) {
  357. support = false;
  358. }
  359. return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
  360. },
  361. get supportsIntegratedFind() {
  362. return this.externalServices.supportsIntegratedFind;
  363. },
  364. get supportsDocumentFonts() {
  365. return this.externalServices.supportsDocumentFonts;
  366. },
  367. get supportsDocumentColors() {
  368. return this.externalServices.supportsDocumentColors;
  369. },
  370. get loadingBar() {
  371. var bar = new _ui_utils.ProgressBar('#loadingBar');
  372. return (0, _pdf.shadow)(this, 'loadingBar', bar);
  373. },
  374. get supportedMouseWheelZoomModifierKeys() {
  375. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  376. },
  377. initPassiveLoading: function initPassiveLoading() {
  378. throw new Error('Not implemented: initPassiveLoading');
  379. },
  380. setTitleUsingUrl: function setTitleUsingUrl(url) {
  381. this.url = url;
  382. this.baseUrl = url.split('#')[0];
  383. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  384. if (!title) {
  385. try {
  386. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  387. } catch (ex) {
  388. title = url;
  389. }
  390. }
  391. this.setTitle(title);
  392. },
  393. setTitle: function setTitle(title) {
  394. if (this.isViewerEmbedded) {
  395. return;
  396. }
  397. document.title = title;
  398. },
  399. close: function close() {
  400. var errorWrapper = this.appConfig.errorWrapper.container;
  401. errorWrapper.setAttribute('hidden', 'true');
  402. if (!this.pdfLoadingTask) {
  403. return Promise.resolve();
  404. }
  405. var promise = this.pdfLoadingTask.destroy();
  406. this.pdfLoadingTask = null;
  407. if (this.pdfDocument) {
  408. this.pdfDocument = null;
  409. this.pdfThumbnailViewer.setDocument(null);
  410. this.pdfViewer.setDocument(null);
  411. this.pdfLinkService.setDocument(null, null);
  412. this.pdfDocumentProperties.setDocument(null, null);
  413. }
  414. this.store = null;
  415. this.isInitialViewSet = false;
  416. this.downloadComplete = false;
  417. this.pdfSidebar.reset();
  418. this.pdfOutlineViewer.reset();
  419. this.pdfAttachmentViewer.reset();
  420. this.findController.reset();
  421. this.findBar.reset();
  422. this.toolbar.reset();
  423. this.secondaryToolbar.reset();
  424. if (typeof PDFBug !== 'undefined') {
  425. PDFBug.cleanup();
  426. }
  427. return promise;
  428. },
  429. open: function open(file, args) {
  430. var _this3 = this;
  431. if (arguments.length > 2 || typeof args === 'number') {
  432. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  433. }
  434. if (this.pdfLoadingTask) {
  435. return this.close().then(function () {
  436. _this3.preferences.reload();
  437. return _this3.open(file, args);
  438. });
  439. }
  440. var parameters = Object.create(null),
  441. scale = void 0;
  442. if (typeof file === 'string') {
  443. this.setTitleUsingUrl(file);
  444. parameters.url = file;
  445. } else if (file && 'byteLength' in file) {
  446. parameters.data = file;
  447. } else if (file.url && file.originalUrl) {
  448. this.setTitleUsingUrl(file.originalUrl);
  449. parameters.url = file.url;
  450. }
  451. if (args) {
  452. for (var prop in args) {
  453. parameters[prop] = args[prop];
  454. }
  455. if (args.scale) {
  456. scale = args.scale;
  457. }
  458. if (args.length) {
  459. this.pdfDocumentProperties.setFileSize(args.length);
  460. }
  461. }
  462. var loadingTask = (0, _pdf.getDocument)(parameters);
  463. this.pdfLoadingTask = loadingTask;
  464. loadingTask.onPassword = function (updateCallback, reason) {
  465. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  466. _this3.passwordPrompt.open();
  467. };
  468. loadingTask.onProgress = function (_ref) {
  469. var loaded = _ref.loaded,
  470. total = _ref.total;
  471. _this3.progress(loaded / total);
  472. };
  473. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  474. return loadingTask.promise.then(function (pdfDocument) {
  475. _this3.load(pdfDocument, scale);
  476. }, function (exception) {
  477. var message = exception && exception.message;
  478. var loadingErrorMessage = void 0;
  479. if (exception instanceof _pdf.InvalidPDFException) {
  480. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  481. } else if (exception instanceof _pdf.MissingPDFException) {
  482. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  483. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  484. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  485. } else {
  486. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  487. }
  488. return loadingErrorMessage.then(function (msg) {
  489. _this3.error(msg, { message: message });
  490. throw new Error(msg);
  491. });
  492. });
  493. },
  494. download: function download() {
  495. var _this4 = this;
  496. function downloadByUrl() {
  497. downloadManager.downloadUrl(url, filename);
  498. }
  499. var url = this.baseUrl;
  500. var filename = (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  501. var downloadManager = this.downloadManager;
  502. downloadManager.onerror = function (err) {
  503. _this4.error('PDF failed to download: ' + err);
  504. };
  505. if (!this.pdfDocument || !this.downloadComplete) {
  506. downloadByUrl();
  507. return;
  508. }
  509. this.pdfDocument.getData().then(function (data) {
  510. var blob = (0, _pdf.createBlob)(data, 'application/pdf');
  511. downloadManager.download(blob, url, filename);
  512. }).catch(downloadByUrl);
  513. },
  514. fallback: function fallback(featureId) {},
  515. error: function error(message, moreInfo) {
  516. var moreInfoText = [this.l10n.get('error_version_info', {
  517. version: _pdf.version || '?',
  518. build: _pdf.build || '?'
  519. }, 'PDF.js v{{version}} (build: {{build}})')];
  520. if (moreInfo) {
  521. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  522. if (moreInfo.stack) {
  523. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  524. } else {
  525. if (moreInfo.filename) {
  526. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  527. }
  528. if (moreInfo.lineNumber) {
  529. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  530. }
  531. }
  532. }
  533. var errorWrapperConfig = this.appConfig.errorWrapper;
  534. var errorWrapper = errorWrapperConfig.container;
  535. errorWrapper.removeAttribute('hidden');
  536. var errorMessage = errorWrapperConfig.errorMessage;
  537. errorMessage.textContent = message;
  538. var closeButton = errorWrapperConfig.closeButton;
  539. closeButton.onclick = function () {
  540. errorWrapper.setAttribute('hidden', 'true');
  541. };
  542. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  543. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  544. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  545. moreInfoButton.onclick = function () {
  546. errorMoreInfo.removeAttribute('hidden');
  547. moreInfoButton.setAttribute('hidden', 'true');
  548. lessInfoButton.removeAttribute('hidden');
  549. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  550. };
  551. lessInfoButton.onclick = function () {
  552. errorMoreInfo.setAttribute('hidden', 'true');
  553. moreInfoButton.removeAttribute('hidden');
  554. lessInfoButton.setAttribute('hidden', 'true');
  555. };
  556. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  557. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  558. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  559. moreInfoButton.removeAttribute('hidden');
  560. lessInfoButton.setAttribute('hidden', 'true');
  561. Promise.all(moreInfoText).then(function (parts) {
  562. errorMoreInfo.value = parts.join('\n');
  563. });
  564. },
  565. progress: function progress(level) {
  566. var _this5 = this;
  567. var percent = Math.round(level * 100);
  568. if (percent > this.loadingBar.percent || isNaN(percent)) {
  569. this.loadingBar.percent = percent;
  570. if (_pdf.PDFJS.disableAutoFetch && percent) {
  571. if (this.disableAutoFetchLoadingBarTimeout) {
  572. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  573. this.disableAutoFetchLoadingBarTimeout = null;
  574. }
  575. this.loadingBar.show();
  576. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  577. _this5.loadingBar.hide();
  578. _this5.disableAutoFetchLoadingBarTimeout = null;
  579. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  580. }
  581. }
  582. },
  583. load: function load(pdfDocument, scale) {
  584. var _this6 = this;
  585. scale = scale || _ui_utils.UNKNOWN_SCALE;
  586. this.pdfDocument = pdfDocument;
  587. pdfDocument.getDownloadInfo().then(function () {
  588. _this6.downloadComplete = true;
  589. _this6.loadingBar.hide();
  590. firstPagePromise.then(function () {
  591. _this6.eventBus.dispatch('documentload', { source: _this6 });
  592. });
  593. });
  594. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  595. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  596. var id = this.documentFingerprint = pdfDocument.fingerprint;
  597. var store = this.store = new _view_history.ViewHistory(id);
  598. var baseDocumentUrl = void 0;
  599. baseDocumentUrl = null;
  600. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  601. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  602. var pdfViewer = this.pdfViewer;
  603. pdfViewer.setDocument(pdfDocument);
  604. var firstPagePromise = pdfViewer.firstPagePromise;
  605. var pagesPromise = pdfViewer.pagesPromise;
  606. var onePageRendered = pdfViewer.onePageRendered;
  607. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  608. pdfThumbnailViewer.setDocument(pdfDocument);
  609. firstPagePromise.then(function (pdfPage) {
  610. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  611. if (!_pdf.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  612. if (!_this6.viewerPrefs['showPreviousViewOnLoad']) {
  613. _this6.pdfHistory.clearHistoryState();
  614. }
  615. _this6.pdfHistory.initialize(_this6.documentFingerprint);
  616. if (_this6.pdfHistory.initialDestination) {
  617. _this6.initialDestination = _this6.pdfHistory.initialDestination;
  618. } else if (_this6.pdfHistory.initialBookmark) {
  619. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  620. }
  621. }
  622. var initialParams = {
  623. destination: _this6.initialDestination,
  624. bookmark: _this6.initialBookmark,
  625. hash: null
  626. };
  627. var storedHash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  628. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  629. new Promise(function (resolve, reject) {
  630. if (!_this6.viewerPrefs['showPreviousViewOnLoad']) {
  631. resolve();
  632. return;
  633. }
  634. store.getMultiple({
  635. exists: false,
  636. page: '1',
  637. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  638. scrollLeft: '0',
  639. scrollTop: '0',
  640. sidebarView: _pdf_sidebar.SidebarView.NONE
  641. }).then(function (values) {
  642. if (!values.exists) {
  643. resolve();
  644. return;
  645. }
  646. storedHash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  647. sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'] || values.sidebarView | 0;
  648. resolve();
  649. }).catch(resolve);
  650. }).then(function () {
  651. _this6.setInitialView(storedHash, {
  652. sidebarView: sidebarView,
  653. scale: scale
  654. });
  655. initialParams.hash = storedHash;
  656. if (!_this6.isViewerEmbedded) {
  657. pdfViewer.focus();
  658. }
  659. return pagesPromise;
  660. }).then(function () {
  661. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  662. return;
  663. }
  664. if (pdfViewer.hasEqualPageSizes) {
  665. return;
  666. }
  667. _this6.initialDestination = initialParams.destination;
  668. _this6.initialBookmark = initialParams.bookmark;
  669. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  670. _this6.setInitialView(initialParams.hash);
  671. }).then(function () {
  672. pdfViewer.update();
  673. });
  674. });
  675. pdfDocument.getPageLabels().then(function (labels) {
  676. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  677. return;
  678. }
  679. var i = 0,
  680. numLabels = labels.length;
  681. if (numLabels !== _this6.pagesCount) {
  682. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  683. return;
  684. }
  685. while (i < numLabels && labels[i] === (i + 1).toString()) {
  686. i++;
  687. }
  688. if (i === numLabels) {
  689. return;
  690. }
  691. pdfViewer.setPageLabels(labels);
  692. pdfThumbnailViewer.setPageLabels(labels);
  693. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  694. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  695. });
  696. pagesPromise.then(function () {
  697. if (!_this6.supportsPrinting) {
  698. return;
  699. }
  700. pdfDocument.getJavaScript().then(function (javaScript) {
  701. if (javaScript.length) {
  702. console.warn('Warning: JavaScript is not supported');
  703. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  704. }
  705. var regex = /\bprint\s*\(/;
  706. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  707. var js = javaScript[i];
  708. if (js && regex.test(js)) {
  709. setTimeout(function () {
  710. window.print();
  711. });
  712. return;
  713. }
  714. }
  715. });
  716. });
  717. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  718. pdfDocument.getOutline().then(function (outline) {
  719. _this6.pdfOutlineViewer.render({ outline: outline });
  720. });
  721. pdfDocument.getAttachments().then(function (attachments) {
  722. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  723. });
  724. });
  725. pdfDocument.getMetadata().then(function (_ref2) {
  726. var info = _ref2.info,
  727. metadata = _ref2.metadata;
  728. _this6.documentInfo = info;
  729. _this6.metadata = metadata;
  730. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (!_pdf.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  731. var pdfTitle = void 0;
  732. if (metadata && metadata.has('dc:title')) {
  733. var title = metadata.get('dc:title');
  734. if (title !== 'Untitled') {
  735. pdfTitle = title;
  736. }
  737. }
  738. if (!pdfTitle && info && info['Title']) {
  739. pdfTitle = info['Title'];
  740. }
  741. if (pdfTitle) {
  742. _this6.setTitle(pdfTitle + ' - ' + document.title);
  743. }
  744. if (info.IsAcroFormPresent) {
  745. console.warn('Warning: AcroForm/XFA is not supported');
  746. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  747. }
  748. });
  749. },
  750. setInitialView: function setInitialView(storedHash) {
  751. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  752. var _options$scale = options.scale,
  753. scale = _options$scale === undefined ? 0 : _options$scale,
  754. _options$sidebarView = options.sidebarView,
  755. sidebarView = _options$sidebarView === undefined ? _pdf_sidebar.SidebarView.NONE : _options$sidebarView;
  756. this.isInitialViewSet = true;
  757. this.pdfSidebar.setInitialView(sidebarView);
  758. if (this.initialDestination) {
  759. this.pdfLinkService.navigateTo(this.initialDestination);
  760. this.initialDestination = null;
  761. } else if (this.initialBookmark) {
  762. this.pdfLinkService.setHash(this.initialBookmark);
  763. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  764. this.initialBookmark = null;
  765. } else if (storedHash) {
  766. this.pdfLinkService.setHash(storedHash);
  767. } else if (scale) {
  768. this.pdfViewer.currentScaleValue = scale;
  769. this.page = 1;
  770. }
  771. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  772. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  773. if (!this.pdfViewer.currentScaleValue) {
  774. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  775. }
  776. },
  777. cleanup: function cleanup() {
  778. if (!this.pdfDocument) {
  779. return;
  780. }
  781. this.pdfViewer.cleanup();
  782. this.pdfThumbnailViewer.cleanup();
  783. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  784. this.pdfDocument.cleanup();
  785. }
  786. },
  787. forceRendering: function forceRendering() {
  788. this.pdfRenderingQueue.printing = this.printing;
  789. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  790. this.pdfRenderingQueue.renderHighestPriority();
  791. },
  792. beforePrint: function beforePrint() {
  793. var _this7 = this;
  794. if (this.printService) {
  795. return;
  796. }
  797. if (!this.supportsPrinting) {
  798. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  799. _this7.error(printMessage);
  800. });
  801. return;
  802. }
  803. if (!this.pdfViewer.pageViewsReady) {
  804. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  805. window.alert(notReadyMessage);
  806. });
  807. return;
  808. }
  809. var pagesOverview = this.pdfViewer.getPagesOverview();
  810. var printContainer = this.appConfig.printContainer;
  811. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  812. this.printService = printService;
  813. this.forceRendering();
  814. printService.layout();
  815. },
  816. afterPrint: function pdfViewSetupAfterPrint() {
  817. if (this.printService) {
  818. this.printService.destroy();
  819. this.printService = null;
  820. }
  821. this.forceRendering();
  822. },
  823. rotatePages: function rotatePages(delta) {
  824. if (!this.pdfDocument) {
  825. return;
  826. }
  827. var pdfViewer = this.pdfViewer,
  828. pdfThumbnailViewer = this.pdfThumbnailViewer;
  829. var pageNumber = pdfViewer.currentPageNumber;
  830. var newRotation = (pdfViewer.pagesRotation + 360 + delta) % 360;
  831. pdfViewer.pagesRotation = newRotation;
  832. pdfThumbnailViewer.pagesRotation = newRotation;
  833. this.forceRendering();
  834. pdfViewer.currentPageNumber = pageNumber;
  835. },
  836. requestPresentationMode: function requestPresentationMode() {
  837. if (!this.pdfPresentationMode) {
  838. return;
  839. }
  840. this.pdfPresentationMode.request();
  841. },
  842. bindEvents: function bindEvents() {
  843. var eventBus = this.eventBus,
  844. _boundEvents = this._boundEvents;
  845. _boundEvents.beforePrint = this.beforePrint.bind(this);
  846. _boundEvents.afterPrint = this.afterPrint.bind(this);
  847. eventBus.on('resize', webViewerResize);
  848. eventBus.on('hashchange', webViewerHashchange);
  849. eventBus.on('beforeprint', _boundEvents.beforePrint);
  850. eventBus.on('afterprint', _boundEvents.afterPrint);
  851. eventBus.on('pagerendered', webViewerPageRendered);
  852. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  853. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  854. eventBus.on('pagechanging', webViewerPageChanging);
  855. eventBus.on('scalechanging', webViewerScaleChanging);
  856. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  857. eventBus.on('pagemode', webViewerPageMode);
  858. eventBus.on('namedaction', webViewerNamedAction);
  859. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  860. eventBus.on('presentationmode', webViewerPresentationMode);
  861. eventBus.on('openfile', webViewerOpenFile);
  862. eventBus.on('print', webViewerPrint);
  863. eventBus.on('download', webViewerDownload);
  864. eventBus.on('firstpage', webViewerFirstPage);
  865. eventBus.on('lastpage', webViewerLastPage);
  866. eventBus.on('nextpage', webViewerNextPage);
  867. eventBus.on('previouspage', webViewerPreviousPage);
  868. eventBus.on('zoomin', webViewerZoomIn);
  869. eventBus.on('zoomout', webViewerZoomOut);
  870. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  871. eventBus.on('scalechanged', webViewerScaleChanged);
  872. eventBus.on('rotatecw', webViewerRotateCw);
  873. eventBus.on('rotateccw', webViewerRotateCcw);
  874. eventBus.on('documentproperties', webViewerDocumentProperties);
  875. eventBus.on('find', webViewerFind);
  876. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  877. eventBus.on('fileinputchange', webViewerFileInputChange);
  878. },
  879. bindWindowEvents: function bindWindowEvents() {
  880. var eventBus = this.eventBus,
  881. _boundEvents = this._boundEvents;
  882. _boundEvents.windowResize = function () {
  883. eventBus.dispatch('resize');
  884. };
  885. _boundEvents.windowHashChange = function () {
  886. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  887. };
  888. _boundEvents.windowBeforePrint = function () {
  889. eventBus.dispatch('beforeprint');
  890. };
  891. _boundEvents.windowAfterPrint = function () {
  892. eventBus.dispatch('afterprint');
  893. };
  894. window.addEventListener('wheel', webViewerWheel);
  895. window.addEventListener('click', webViewerClick);
  896. window.addEventListener('keydown', webViewerKeyDown);
  897. window.addEventListener('resize', _boundEvents.windowResize);
  898. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  899. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  900. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  901. _boundEvents.windowChange = function (evt) {
  902. var files = evt.target.files;
  903. if (!files || files.length === 0) {
  904. return;
  905. }
  906. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  907. };
  908. window.addEventListener('change', _boundEvents.windowChange);
  909. },
  910. unbindEvents: function unbindEvents() {
  911. var eventBus = this.eventBus,
  912. _boundEvents = this._boundEvents;
  913. eventBus.off('resize', webViewerResize);
  914. eventBus.off('hashchange', webViewerHashchange);
  915. eventBus.off('beforeprint', _boundEvents.beforePrint);
  916. eventBus.off('afterprint', _boundEvents.afterPrint);
  917. eventBus.off('pagerendered', webViewerPageRendered);
  918. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  919. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  920. eventBus.off('pagechanging', webViewerPageChanging);
  921. eventBus.off('scalechanging', webViewerScaleChanging);
  922. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  923. eventBus.off('pagemode', webViewerPageMode);
  924. eventBus.off('namedaction', webViewerNamedAction);
  925. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  926. eventBus.off('presentationmode', webViewerPresentationMode);
  927. eventBus.off('openfile', webViewerOpenFile);
  928. eventBus.off('print', webViewerPrint);
  929. eventBus.off('download', webViewerDownload);
  930. eventBus.off('firstpage', webViewerFirstPage);
  931. eventBus.off('lastpage', webViewerLastPage);
  932. eventBus.off('nextpage', webViewerNextPage);
  933. eventBus.off('previouspage', webViewerPreviousPage);
  934. eventBus.off('zoomin', webViewerZoomIn);
  935. eventBus.off('zoomout', webViewerZoomOut);
  936. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  937. eventBus.off('scalechanged', webViewerScaleChanged);
  938. eventBus.off('rotatecw', webViewerRotateCw);
  939. eventBus.off('rotateccw', webViewerRotateCcw);
  940. eventBus.off('documentproperties', webViewerDocumentProperties);
  941. eventBus.off('find', webViewerFind);
  942. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  943. eventBus.off('fileinputchange', webViewerFileInputChange);
  944. _boundEvents.beforePrint = null;
  945. _boundEvents.afterPrint = null;
  946. },
  947. unbindWindowEvents: function unbindWindowEvents() {
  948. var _boundEvents = this._boundEvents;
  949. window.removeEventListener('wheel', webViewerWheel);
  950. window.removeEventListener('click', webViewerClick);
  951. window.removeEventListener('keydown', webViewerKeyDown);
  952. window.removeEventListener('resize', _boundEvents.windowResize);
  953. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  954. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  955. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  956. window.removeEventListener('change', _boundEvents.windowChange);
  957. _boundEvents.windowChange = null;
  958. _boundEvents.windowResize = null;
  959. _boundEvents.windowHashChange = null;
  960. _boundEvents.windowBeforePrint = null;
  961. _boundEvents.windowAfterPrint = null;
  962. }
  963. };
  964. var validateFileURL = void 0;
  965. {
  966. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  967. validateFileURL = function validateFileURL(file) {
  968. if (file === undefined) {
  969. return;
  970. }
  971. try {
  972. var viewerOrigin = new URL(window.location.href).origin || 'null';
  973. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  974. return;
  975. }
  976. var fileOrigin = new URL(file, window.location.href).origin;
  977. if (fileOrigin !== viewerOrigin) {
  978. throw new Error('file origin does not match viewer\'s');
  979. }
  980. } catch (ex) {
  981. var message = ex && ex.message;
  982. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  983. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  984. });
  985. throw ex;
  986. }
  987. };
  988. }
  989. function loadAndEnablePDFBug(enabledTabs) {
  990. return new Promise(function (resolve, reject) {
  991. var appConfig = PDFViewerApplication.appConfig;
  992. var script = document.createElement('script');
  993. script.src = appConfig.debuggerScriptPath;
  994. script.onload = function () {
  995. PDFBug.enable(enabledTabs);
  996. PDFBug.init({
  997. PDFJS: _pdf.PDFJS,
  998. OPS: _pdf.OPS
  999. }, appConfig.mainContainer);
  1000. resolve();
  1001. };
  1002. script.onerror = function () {
  1003. reject(new Error('Cannot load debugger at ' + script.src));
  1004. };
  1005. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1006. });
  1007. }
  1008. function webViewerInitialized() {
  1009. var appConfig = PDFViewerApplication.appConfig;
  1010. var file = void 0;
  1011. var queryString = document.location.search.substring(1);
  1012. var params = (0, _ui_utils.parseQueryString)(queryString);
  1013. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1014. validateFileURL(file);
  1015. var waitForBeforeOpening = [];
  1016. var fileInput = document.createElement('input');
  1017. fileInput.id = appConfig.openFileInputName;
  1018. fileInput.className = 'fileInput';
  1019. fileInput.setAttribute('type', 'file');
  1020. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1021. document.body.appendChild(fileInput);
  1022. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1023. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1024. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1025. } else {
  1026. fileInput.value = null;
  1027. }
  1028. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  1029. var hash = document.location.hash.substring(1);
  1030. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  1031. if ('disableworker' in hashParams) {
  1032. _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  1033. }
  1034. if ('disablerange' in hashParams) {
  1035. _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  1036. }
  1037. if ('disablestream' in hashParams) {
  1038. _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  1039. }
  1040. if ('disableautofetch' in hashParams) {
  1041. _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  1042. }
  1043. if ('disablefontface' in hashParams) {
  1044. _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  1045. }
  1046. if ('disablehistory' in hashParams) {
  1047. _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  1048. }
  1049. if ('webgl' in hashParams) {
  1050. _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  1051. }
  1052. if ('useonlycsszoom' in hashParams) {
  1053. _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  1054. }
  1055. if ('verbosity' in hashParams) {
  1056. _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
  1057. }
  1058. if ('ignorecurrentpositiononzoom' in hashParams) {
  1059. _pdf.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  1060. }
  1061. if ('textlayer' in hashParams) {
  1062. switch (hashParams['textlayer']) {
  1063. case 'off':
  1064. _pdf.PDFJS.disableTextLayer = true;
  1065. break;
  1066. case 'visible':
  1067. case 'shadow':
  1068. case 'hover':
  1069. var viewer = appConfig.viewerContainer;
  1070. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  1071. break;
  1072. }
  1073. }
  1074. if ('pdfbug' in hashParams) {
  1075. _pdf.PDFJS.pdfBug = true;
  1076. var pdfBug = hashParams['pdfbug'];
  1077. var enabled = pdfBug.split(',');
  1078. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  1079. }
  1080. }
  1081. if (!PDFViewerApplication.supportsPrinting) {
  1082. appConfig.toolbar.print.classList.add('hidden');
  1083. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1084. }
  1085. if (!PDFViewerApplication.supportsFullscreen) {
  1086. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1087. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1088. }
  1089. if (PDFViewerApplication.supportsIntegratedFind) {
  1090. appConfig.toolbar.viewFind.classList.add('hidden');
  1091. }
  1092. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (evt) {
  1093. if (evt.target === this) {
  1094. PDFViewerApplication.eventBus.dispatch('resize');
  1095. }
  1096. }, true);
  1097. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1098. PDFViewerApplication.pdfSidebar.toggle();
  1099. });
  1100. Promise.all(waitForBeforeOpening).then(function () {
  1101. webViewerOpenFileViaURL(file);
  1102. }).catch(function (reason) {
  1103. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
  1104. PDFViewerApplication.error(msg, reason);
  1105. });
  1106. });
  1107. }
  1108. var webViewerOpenFileViaURL = void 0;
  1109. {
  1110. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1111. if (file && file.lastIndexOf('file:', 0) === 0) {
  1112. PDFViewerApplication.setTitleUsingUrl(file);
  1113. var xhr = new XMLHttpRequest();
  1114. xhr.onload = function () {
  1115. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1116. };
  1117. try {
  1118. xhr.open('GET', file);
  1119. xhr.responseType = 'arraybuffer';
  1120. xhr.send();
  1121. } catch (ex) {
  1122. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1123. PDFViewerApplication.error(msg, ex);
  1124. });
  1125. }
  1126. return;
  1127. }
  1128. if (file) {
  1129. PDFViewerApplication.open(file);
  1130. }
  1131. };
  1132. }
  1133. function webViewerPageRendered(evt) {
  1134. var pageNumber = evt.pageNumber;
  1135. var pageIndex = pageNumber - 1;
  1136. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1137. if (pageNumber === PDFViewerApplication.page) {
  1138. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1139. }
  1140. if (!pageView) {
  1141. return;
  1142. }
  1143. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1144. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1145. thumbnailView.setImage(pageView);
  1146. }
  1147. if (_pdf.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1148. Stats.add(pageNumber, pageView.stats);
  1149. }
  1150. if (pageView.error) {
  1151. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1152. PDFViewerApplication.error(msg, pageView.error);
  1153. });
  1154. }
  1155. }
  1156. function webViewerTextLayerRendered(evt) {}
  1157. function webViewerPageMode(evt) {
  1158. var mode = evt.mode,
  1159. view = void 0;
  1160. switch (mode) {
  1161. case 'thumbs':
  1162. view = _pdf_sidebar.SidebarView.THUMBS;
  1163. break;
  1164. case 'bookmarks':
  1165. case 'outline':
  1166. view = _pdf_sidebar.SidebarView.OUTLINE;
  1167. break;
  1168. case 'attachments':
  1169. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1170. break;
  1171. case 'none':
  1172. view = _pdf_sidebar.SidebarView.NONE;
  1173. break;
  1174. default:
  1175. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1176. return;
  1177. }
  1178. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1179. }
  1180. function webViewerNamedAction(evt) {
  1181. var action = evt.action;
  1182. switch (action) {
  1183. case 'GoToPage':
  1184. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1185. break;
  1186. case 'Find':
  1187. if (!PDFViewerApplication.supportsIntegratedFind) {
  1188. PDFViewerApplication.findBar.toggle();
  1189. }
  1190. break;
  1191. }
  1192. }
  1193. function webViewerPresentationModeChanged(evt) {
  1194. var active = evt.active,
  1195. switchInProgress = evt.switchInProgress;
  1196. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
  1197. }
  1198. function webViewerSidebarViewChanged(evt) {
  1199. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1200. var store = PDFViewerApplication.store;
  1201. if (store && PDFViewerApplication.isInitialViewSet) {
  1202. store.set('sidebarView', evt.view).catch(function () {});
  1203. }
  1204. }
  1205. function webViewerUpdateViewarea(evt) {
  1206. var location = evt.location,
  1207. store = PDFViewerApplication.store;
  1208. if (store && PDFViewerApplication.isInitialViewSet) {
  1209. store.setMultiple({
  1210. 'exists': true,
  1211. 'page': location.pageNumber,
  1212. 'zoom': location.scale,
  1213. 'scrollLeft': location.left,
  1214. 'scrollTop': location.top
  1215. }).catch(function () {});
  1216. }
  1217. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1218. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1219. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1220. PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  1221. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1222. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1223. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1224. }
  1225. function webViewerResize() {
  1226. var pdfDocument = PDFViewerApplication.pdfDocument,
  1227. pdfViewer = PDFViewerApplication.pdfViewer;
  1228. if (!pdfDocument) {
  1229. return;
  1230. }
  1231. var currentScaleValue = pdfViewer.currentScaleValue;
  1232. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1233. pdfViewer.currentScaleValue = currentScaleValue;
  1234. }
  1235. pdfViewer.update();
  1236. }
  1237. function webViewerHashchange(evt) {
  1238. if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
  1239. var hash = evt.hash;
  1240. if (!hash) {
  1241. return;
  1242. }
  1243. if (!PDFViewerApplication.isInitialViewSet) {
  1244. PDFViewerApplication.initialBookmark = hash;
  1245. } else {
  1246. PDFViewerApplication.pdfLinkService.setHash(hash);
  1247. }
  1248. }
  1249. }
  1250. var webViewerFileInputChange = void 0;
  1251. {
  1252. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  1253. var file = evt.fileInput.files[0];
  1254. if (!_pdf.PDFJS.disableCreateObjectURL && URL.createObjectURL) {
  1255. PDFViewerApplication.open(URL.createObjectURL(file));
  1256. } else {
  1257. var fileReader = new FileReader();
  1258. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1259. var buffer = evt.target.result;
  1260. PDFViewerApplication.open(new Uint8Array(buffer));
  1261. };
  1262. fileReader.readAsArrayBuffer(file);
  1263. }
  1264. PDFViewerApplication.setTitleUsingUrl(file.name);
  1265. var appConfig = PDFViewerApplication.appConfig;
  1266. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1267. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1268. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1269. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1270. };
  1271. }
  1272. function webViewerPresentationMode() {
  1273. PDFViewerApplication.requestPresentationMode();
  1274. }
  1275. function webViewerOpenFile() {
  1276. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1277. document.getElementById(openFileInputName).click();
  1278. }
  1279. function webViewerPrint() {
  1280. window.print();
  1281. }
  1282. function webViewerDownload() {
  1283. PDFViewerApplication.download();
  1284. }
  1285. function webViewerFirstPage() {
  1286. if (PDFViewerApplication.pdfDocument) {
  1287. PDFViewerApplication.page = 1;
  1288. }
  1289. }
  1290. function webViewerLastPage() {
  1291. if (PDFViewerApplication.pdfDocument) {
  1292. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1293. }
  1294. }
  1295. function webViewerNextPage() {
  1296. PDFViewerApplication.page++;
  1297. }
  1298. function webViewerPreviousPage() {
  1299. PDFViewerApplication.page--;
  1300. }
  1301. function webViewerZoomIn() {
  1302. PDFViewerApplication.zoomIn();
  1303. }
  1304. function webViewerZoomOut() {
  1305. PDFViewerApplication.zoomOut();
  1306. }
  1307. function webViewerPageNumberChanged(evt) {
  1308. var pdfViewer = PDFViewerApplication.pdfViewer;
  1309. pdfViewer.currentPageLabel = evt.value;
  1310. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1311. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1312. }
  1313. }
  1314. function webViewerScaleChanged(evt) {
  1315. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1316. }
  1317. function webViewerRotateCw() {
  1318. PDFViewerApplication.rotatePages(90);
  1319. }
  1320. function webViewerRotateCcw() {
  1321. PDFViewerApplication.rotatePages(-90);
  1322. }
  1323. function webViewerDocumentProperties() {
  1324. PDFViewerApplication.pdfDocumentProperties.open();
  1325. }
  1326. function webViewerFind(evt) {
  1327. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  1328. query: evt.query,
  1329. phraseSearch: evt.phraseSearch,
  1330. caseSensitive: evt.caseSensitive,
  1331. highlightAll: evt.highlightAll,
  1332. findPrevious: evt.findPrevious
  1333. });
  1334. }
  1335. function webViewerFindFromUrlHash(evt) {
  1336. PDFViewerApplication.findController.executeCommand('find', {
  1337. query: evt.query,
  1338. phraseSearch: evt.phraseSearch,
  1339. caseSensitive: false,
  1340. highlightAll: true,
  1341. findPrevious: false
  1342. });
  1343. }
  1344. function webViewerScaleChanging(evt) {
  1345. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1346. PDFViewerApplication.pdfViewer.update();
  1347. }
  1348. function webViewerPageChanging(evt) {
  1349. var page = evt.pageNumber;
  1350. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1351. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1352. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1353. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1354. }
  1355. if (_pdf.PDFJS.pdfBug && Stats.enabled) {
  1356. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1357. if (pageView.stats) {
  1358. Stats.add(page, pageView.stats);
  1359. }
  1360. }
  1361. }
  1362. var zoomDisabled = false,
  1363. zoomDisabledTimeout = void 0;
  1364. function webViewerWheel(evt) {
  1365. var pdfViewer = PDFViewerApplication.pdfViewer;
  1366. if (pdfViewer.isInPresentationMode) {
  1367. return;
  1368. }
  1369. if (evt.ctrlKey || evt.metaKey) {
  1370. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1371. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1372. return;
  1373. }
  1374. evt.preventDefault();
  1375. if (zoomDisabled) {
  1376. return;
  1377. }
  1378. var previousScale = pdfViewer.currentScale;
  1379. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1380. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1381. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1382. if (ticks < 0) {
  1383. PDFViewerApplication.zoomOut(-ticks);
  1384. } else {
  1385. PDFViewerApplication.zoomIn(ticks);
  1386. }
  1387. var currentScale = pdfViewer.currentScale;
  1388. if (previousScale !== currentScale) {
  1389. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1390. var rect = pdfViewer.container.getBoundingClientRect();
  1391. var dx = evt.clientX - rect.left;
  1392. var dy = evt.clientY - rect.top;
  1393. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1394. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1395. }
  1396. } else {
  1397. zoomDisabled = true;
  1398. clearTimeout(zoomDisabledTimeout);
  1399. zoomDisabledTimeout = setTimeout(function () {
  1400. zoomDisabled = false;
  1401. }, 1000);
  1402. }
  1403. }
  1404. function webViewerClick(evt) {
  1405. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1406. return;
  1407. }
  1408. var appConfig = PDFViewerApplication.appConfig;
  1409. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1410. PDFViewerApplication.secondaryToolbar.close();
  1411. }
  1412. }
  1413. function webViewerKeyDown(evt) {
  1414. if (PDFViewerApplication.overlayManager.active) {
  1415. return;
  1416. }
  1417. var handled = false,
  1418. ensureViewerFocused = false;
  1419. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1420. var pdfViewer = PDFViewerApplication.pdfViewer;
  1421. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1422. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1423. switch (evt.keyCode) {
  1424. case 70:
  1425. if (!PDFViewerApplication.supportsIntegratedFind) {
  1426. PDFViewerApplication.findBar.open();
  1427. handled = true;
  1428. }
  1429. break;
  1430. case 71:
  1431. if (!PDFViewerApplication.supportsIntegratedFind) {
  1432. var findState = PDFViewerApplication.findController.state;
  1433. if (findState) {
  1434. PDFViewerApplication.findController.executeCommand('findagain', {
  1435. query: findState.query,
  1436. phraseSearch: findState.phraseSearch,
  1437. caseSensitive: findState.caseSensitive,
  1438. highlightAll: findState.highlightAll,
  1439. findPrevious: cmd === 5 || cmd === 12
  1440. });
  1441. }
  1442. handled = true;
  1443. }
  1444. break;
  1445. case 61:
  1446. case 107:
  1447. case 187:
  1448. case 171:
  1449. if (!isViewerInPresentationMode) {
  1450. PDFViewerApplication.zoomIn();
  1451. }
  1452. handled = true;
  1453. break;
  1454. case 173:
  1455. case 109:
  1456. case 189:
  1457. if (!isViewerInPresentationMode) {
  1458. PDFViewerApplication.zoomOut();
  1459. }
  1460. handled = true;
  1461. break;
  1462. case 48:
  1463. case 96:
  1464. if (!isViewerInPresentationMode) {
  1465. setTimeout(function () {
  1466. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1467. });
  1468. handled = false;
  1469. }
  1470. break;
  1471. case 38:
  1472. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1473. PDFViewerApplication.page = 1;
  1474. handled = true;
  1475. ensureViewerFocused = true;
  1476. }
  1477. break;
  1478. case 40:
  1479. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1480. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1481. handled = true;
  1482. ensureViewerFocused = true;
  1483. }
  1484. break;
  1485. }
  1486. }
  1487. if (cmd === 1 || cmd === 8) {
  1488. switch (evt.keyCode) {
  1489. case 83:
  1490. PDFViewerApplication.download();
  1491. handled = true;
  1492. break;
  1493. }
  1494. }
  1495. if (cmd === 3 || cmd === 10) {
  1496. switch (evt.keyCode) {
  1497. case 80:
  1498. PDFViewerApplication.requestPresentationMode();
  1499. handled = true;
  1500. break;
  1501. case 71:
  1502. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1503. handled = true;
  1504. break;
  1505. }
  1506. }
  1507. if (handled) {
  1508. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1509. pdfViewer.focus();
  1510. }
  1511. evt.preventDefault();
  1512. return;
  1513. }
  1514. var curElement = document.activeElement || document.querySelector(':focus');
  1515. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1516. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1517. if (evt.keyCode !== 27) {
  1518. return;
  1519. }
  1520. }
  1521. if (cmd === 0) {
  1522. switch (evt.keyCode) {
  1523. case 38:
  1524. case 33:
  1525. case 8:
  1526. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1527. break;
  1528. }
  1529. case 37:
  1530. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1531. break;
  1532. }
  1533. case 75:
  1534. case 80:
  1535. if (PDFViewerApplication.page > 1) {
  1536. PDFViewerApplication.page--;
  1537. }
  1538. handled = true;
  1539. break;
  1540. case 27:
  1541. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1542. PDFViewerApplication.secondaryToolbar.close();
  1543. handled = true;
  1544. }
  1545. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1546. PDFViewerApplication.findBar.close();
  1547. handled = true;
  1548. }
  1549. break;
  1550. case 40:
  1551. case 34:
  1552. case 32:
  1553. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1554. break;
  1555. }
  1556. case 39:
  1557. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1558. break;
  1559. }
  1560. case 74:
  1561. case 78:
  1562. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1563. PDFViewerApplication.page++;
  1564. }
  1565. handled = true;
  1566. break;
  1567. case 36:
  1568. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1569. PDFViewerApplication.page = 1;
  1570. handled = true;
  1571. ensureViewerFocused = true;
  1572. }
  1573. break;
  1574. case 35:
  1575. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1576. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1577. handled = true;
  1578. ensureViewerFocused = true;
  1579. }
  1580. break;
  1581. case 83:
  1582. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1583. break;
  1584. case 72:
  1585. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1586. break;
  1587. case 82:
  1588. PDFViewerApplication.rotatePages(90);
  1589. break;
  1590. }
  1591. }
  1592. if (cmd === 4) {
  1593. switch (evt.keyCode) {
  1594. case 32:
  1595. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1596. break;
  1597. }
  1598. if (PDFViewerApplication.page > 1) {
  1599. PDFViewerApplication.page--;
  1600. }
  1601. handled = true;
  1602. break;
  1603. case 82:
  1604. PDFViewerApplication.rotatePages(-90);
  1605. break;
  1606. }
  1607. }
  1608. if (!handled && !isViewerInPresentationMode) {
  1609. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1610. ensureViewerFocused = true;
  1611. }
  1612. }
  1613. if (cmd === 2) {
  1614. switch (evt.keyCode) {
  1615. case 37:
  1616. if (isViewerInPresentationMode) {
  1617. PDFViewerApplication.pdfHistory.back();
  1618. handled = true;
  1619. }
  1620. break;
  1621. case 39:
  1622. if (isViewerInPresentationMode) {
  1623. PDFViewerApplication.pdfHistory.forward();
  1624. handled = true;
  1625. }
  1626. break;
  1627. }
  1628. }
  1629. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1630. pdfViewer.focus();
  1631. }
  1632. if (handled) {
  1633. evt.preventDefault();
  1634. }
  1635. }
  1636. var PDFPrintServiceFactory = {
  1637. instance: {
  1638. supportsPrinting: false,
  1639. createPrintService: function createPrintService() {
  1640. throw new Error('Not implemented: createPrintService');
  1641. }
  1642. }
  1643. };
  1644. exports.PDFViewerApplication = PDFViewerApplication;
  1645. exports.DefaultExternalServices = DefaultExternalServices;
  1646. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;