app.js 63 KB

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