2
0

app.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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. var percent = Math.round(level * 100);
  572. if (percent > this.loadingBar.percent || isNaN(percent)) {
  573. this.loadingBar.percent = percent;
  574. if (_pdf.PDFJS.disableAutoFetch && percent) {
  575. if (this.disableAutoFetchLoadingBarTimeout) {
  576. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  577. this.disableAutoFetchLoadingBarTimeout = null;
  578. }
  579. this.loadingBar.show();
  580. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  581. _this5.loadingBar.hide();
  582. _this5.disableAutoFetchLoadingBarTimeout = null;
  583. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  584. }
  585. }
  586. },
  587. load: function load(pdfDocument, scale) {
  588. var _this6 = this;
  589. scale = scale || _ui_utils.UNKNOWN_SCALE;
  590. this.pdfDocument = pdfDocument;
  591. pdfDocument.getDownloadInfo().then(function () {
  592. _this6.downloadComplete = true;
  593. _this6.loadingBar.hide();
  594. firstPagePromise.then(function () {
  595. _this6.eventBus.dispatch('documentload', { source: _this6 });
  596. });
  597. });
  598. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  599. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  600. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  601. var id = this.documentFingerprint = pdfDocument.fingerprint;
  602. var store = this.store = new _view_history.ViewHistory(id);
  603. var baseDocumentUrl = void 0;
  604. baseDocumentUrl = null;
  605. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  606. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  607. var pdfViewer = this.pdfViewer;
  608. pdfViewer.setDocument(pdfDocument);
  609. var firstPagePromise = pdfViewer.firstPagePromise;
  610. var pagesPromise = pdfViewer.pagesPromise;
  611. var onePageRendered = pdfViewer.onePageRendered;
  612. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  613. pdfThumbnailViewer.setDocument(pdfDocument);
  614. firstPagePromise.then(function (pdfPage) {
  615. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  616. if (!_pdf.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  617. if (!_this6.viewerPrefs['showPreviousViewOnLoad']) {
  618. _this6.pdfHistory.clearHistoryState();
  619. }
  620. _this6.pdfHistory.initialize(_this6.documentFingerprint);
  621. if (_this6.pdfHistory.initialDestination) {
  622. _this6.initialDestination = _this6.pdfHistory.initialDestination;
  623. } else if (_this6.pdfHistory.initialBookmark) {
  624. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  625. }
  626. }
  627. var initialParams = {
  628. destination: _this6.initialDestination,
  629. bookmark: _this6.initialBookmark,
  630. hash: null
  631. };
  632. var storePromise = store.getMultiple({
  633. exists: false,
  634. page: '1',
  635. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  636. scrollLeft: '0',
  637. scrollTop: '0',
  638. sidebarView: _pdf_sidebar.SidebarView.NONE
  639. }).catch(function () {});
  640. Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
  641. var _ref3 = _slicedToArray(_ref2, 2),
  642. _ref3$ = _ref3[0],
  643. values = _ref3$ === undefined ? {} : _ref3$,
  644. pageMode = _ref3[1];
  645. var hash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  646. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  647. if (values.exists && _this6.viewerPrefs['showPreviousViewOnLoad']) {
  648. hash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  649. sidebarView = sidebarView || values.sidebarView | 0;
  650. }
  651. if (pageMode && !_this6.viewerPrefs['disablePageMode']) {
  652. sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
  653. }
  654. return {
  655. hash: hash,
  656. sidebarView: sidebarView
  657. };
  658. }).then(function (_ref4) {
  659. var hash = _ref4.hash,
  660. sidebarView = _ref4.sidebarView;
  661. _this6.setInitialView(hash, {
  662. sidebarView: sidebarView,
  663. scale: scale
  664. });
  665. initialParams.hash = hash;
  666. if (!_this6.isViewerEmbedded) {
  667. pdfViewer.focus();
  668. }
  669. return pagesPromise;
  670. }).then(function () {
  671. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  672. return;
  673. }
  674. if (pdfViewer.hasEqualPageSizes) {
  675. return;
  676. }
  677. _this6.initialDestination = initialParams.destination;
  678. _this6.initialBookmark = initialParams.bookmark;
  679. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  680. _this6.setInitialView(initialParams.hash);
  681. }).then(function () {
  682. pdfViewer.update();
  683. });
  684. });
  685. pdfDocument.getPageLabels().then(function (labels) {
  686. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  687. return;
  688. }
  689. var i = 0,
  690. numLabels = labels.length;
  691. if (numLabels !== _this6.pagesCount) {
  692. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  693. return;
  694. }
  695. while (i < numLabels && labels[i] === (i + 1).toString()) {
  696. i++;
  697. }
  698. if (i === numLabels) {
  699. return;
  700. }
  701. pdfViewer.setPageLabels(labels);
  702. pdfThumbnailViewer.setPageLabels(labels);
  703. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  704. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  705. });
  706. pagesPromise.then(function () {
  707. if (!_this6.supportsPrinting) {
  708. return;
  709. }
  710. pdfDocument.getJavaScript().then(function (javaScript) {
  711. if (javaScript.length) {
  712. console.warn('Warning: JavaScript is not supported');
  713. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  714. }
  715. var regex = /\bprint\s*\(/;
  716. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  717. var js = javaScript[i];
  718. if (js && regex.test(js)) {
  719. setTimeout(function () {
  720. window.print();
  721. });
  722. return;
  723. }
  724. }
  725. });
  726. });
  727. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  728. pdfDocument.getOutline().then(function (outline) {
  729. _this6.pdfOutlineViewer.render({ outline: outline });
  730. });
  731. pdfDocument.getAttachments().then(function (attachments) {
  732. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  733. });
  734. });
  735. pdfDocument.getMetadata().then(function (_ref5) {
  736. var info = _ref5.info,
  737. metadata = _ref5.metadata;
  738. _this6.documentInfo = info;
  739. _this6.metadata = metadata;
  740. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (!_pdf.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  741. var pdfTitle = void 0;
  742. if (metadata && metadata.has('dc:title')) {
  743. var title = metadata.get('dc:title');
  744. if (title !== 'Untitled') {
  745. pdfTitle = title;
  746. }
  747. }
  748. if (!pdfTitle && info && info['Title']) {
  749. pdfTitle = info['Title'];
  750. }
  751. if (pdfTitle) {
  752. _this6.setTitle(pdfTitle + ' - ' + document.title);
  753. }
  754. if (info.IsAcroFormPresent) {
  755. console.warn('Warning: AcroForm/XFA is not supported');
  756. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  757. }
  758. });
  759. },
  760. setInitialView: function setInitialView(storedHash) {
  761. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  762. var _options$scale = options.scale,
  763. scale = _options$scale === undefined ? 0 : _options$scale,
  764. _options$sidebarView = options.sidebarView,
  765. sidebarView = _options$sidebarView === undefined ? _pdf_sidebar.SidebarView.NONE : _options$sidebarView;
  766. this.isInitialViewSet = true;
  767. this.pdfSidebar.setInitialView(sidebarView);
  768. if (this.initialDestination) {
  769. this.pdfLinkService.navigateTo(this.initialDestination);
  770. this.initialDestination = null;
  771. } else if (this.initialBookmark) {
  772. this.pdfLinkService.setHash(this.initialBookmark);
  773. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  774. this.initialBookmark = null;
  775. } else if (storedHash) {
  776. this.pdfLinkService.setHash(storedHash);
  777. } else if (scale) {
  778. this.pdfViewer.currentScaleValue = scale;
  779. this.page = 1;
  780. }
  781. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  782. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  783. if (!this.pdfViewer.currentScaleValue) {
  784. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  785. }
  786. },
  787. cleanup: function cleanup() {
  788. if (!this.pdfDocument) {
  789. return;
  790. }
  791. this.pdfViewer.cleanup();
  792. this.pdfThumbnailViewer.cleanup();
  793. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  794. this.pdfDocument.cleanup();
  795. }
  796. },
  797. forceRendering: function forceRendering() {
  798. this.pdfRenderingQueue.printing = this.printing;
  799. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  800. this.pdfRenderingQueue.renderHighestPriority();
  801. },
  802. beforePrint: function beforePrint() {
  803. var _this7 = this;
  804. if (this.printService) {
  805. return;
  806. }
  807. if (!this.supportsPrinting) {
  808. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  809. _this7.error(printMessage);
  810. });
  811. return;
  812. }
  813. if (!this.pdfViewer.pageViewsReady) {
  814. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  815. window.alert(notReadyMessage);
  816. });
  817. return;
  818. }
  819. var pagesOverview = this.pdfViewer.getPagesOverview();
  820. var printContainer = this.appConfig.printContainer;
  821. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  822. this.printService = printService;
  823. this.forceRendering();
  824. printService.layout();
  825. },
  826. afterPrint: function pdfViewSetupAfterPrint() {
  827. if (this.printService) {
  828. this.printService.destroy();
  829. this.printService = null;
  830. }
  831. this.forceRendering();
  832. },
  833. rotatePages: function rotatePages(delta) {
  834. if (!this.pdfDocument) {
  835. return;
  836. }
  837. var pdfViewer = this.pdfViewer,
  838. pdfThumbnailViewer = this.pdfThumbnailViewer;
  839. var pageNumber = pdfViewer.currentPageNumber;
  840. var newRotation = (pdfViewer.pagesRotation + 360 + delta) % 360;
  841. pdfViewer.pagesRotation = newRotation;
  842. pdfThumbnailViewer.pagesRotation = newRotation;
  843. this.forceRendering();
  844. pdfViewer.currentPageNumber = pageNumber;
  845. },
  846. requestPresentationMode: function requestPresentationMode() {
  847. if (!this.pdfPresentationMode) {
  848. return;
  849. }
  850. this.pdfPresentationMode.request();
  851. },
  852. bindEvents: function bindEvents() {
  853. var eventBus = this.eventBus,
  854. _boundEvents = this._boundEvents;
  855. _boundEvents.beforePrint = this.beforePrint.bind(this);
  856. _boundEvents.afterPrint = this.afterPrint.bind(this);
  857. eventBus.on('resize', webViewerResize);
  858. eventBus.on('hashchange', webViewerHashchange);
  859. eventBus.on('beforeprint', _boundEvents.beforePrint);
  860. eventBus.on('afterprint', _boundEvents.afterPrint);
  861. eventBus.on('pagerendered', webViewerPageRendered);
  862. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  863. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  864. eventBus.on('pagechanging', webViewerPageChanging);
  865. eventBus.on('scalechanging', webViewerScaleChanging);
  866. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  867. eventBus.on('pagemode', webViewerPageMode);
  868. eventBus.on('namedaction', webViewerNamedAction);
  869. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  870. eventBus.on('presentationmode', webViewerPresentationMode);
  871. eventBus.on('openfile', webViewerOpenFile);
  872. eventBus.on('print', webViewerPrint);
  873. eventBus.on('download', webViewerDownload);
  874. eventBus.on('firstpage', webViewerFirstPage);
  875. eventBus.on('lastpage', webViewerLastPage);
  876. eventBus.on('nextpage', webViewerNextPage);
  877. eventBus.on('previouspage', webViewerPreviousPage);
  878. eventBus.on('zoomin', webViewerZoomIn);
  879. eventBus.on('zoomout', webViewerZoomOut);
  880. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  881. eventBus.on('scalechanged', webViewerScaleChanged);
  882. eventBus.on('rotatecw', webViewerRotateCw);
  883. eventBus.on('rotateccw', webViewerRotateCcw);
  884. eventBus.on('documentproperties', webViewerDocumentProperties);
  885. eventBus.on('find', webViewerFind);
  886. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  887. eventBus.on('fileinputchange', webViewerFileInputChange);
  888. },
  889. bindWindowEvents: function bindWindowEvents() {
  890. var eventBus = this.eventBus,
  891. _boundEvents = this._boundEvents;
  892. _boundEvents.windowResize = function () {
  893. eventBus.dispatch('resize');
  894. };
  895. _boundEvents.windowHashChange = function () {
  896. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  897. };
  898. _boundEvents.windowBeforePrint = function () {
  899. eventBus.dispatch('beforeprint');
  900. };
  901. _boundEvents.windowAfterPrint = function () {
  902. eventBus.dispatch('afterprint');
  903. };
  904. window.addEventListener('wheel', webViewerWheel);
  905. window.addEventListener('click', webViewerClick);
  906. window.addEventListener('keydown', webViewerKeyDown);
  907. window.addEventListener('resize', _boundEvents.windowResize);
  908. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  909. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  910. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  911. _boundEvents.windowChange = function (evt) {
  912. var files = evt.target.files;
  913. if (!files || files.length === 0) {
  914. return;
  915. }
  916. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  917. };
  918. window.addEventListener('change', _boundEvents.windowChange);
  919. },
  920. unbindEvents: function unbindEvents() {
  921. var eventBus = this.eventBus,
  922. _boundEvents = this._boundEvents;
  923. eventBus.off('resize', webViewerResize);
  924. eventBus.off('hashchange', webViewerHashchange);
  925. eventBus.off('beforeprint', _boundEvents.beforePrint);
  926. eventBus.off('afterprint', _boundEvents.afterPrint);
  927. eventBus.off('pagerendered', webViewerPageRendered);
  928. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  929. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  930. eventBus.off('pagechanging', webViewerPageChanging);
  931. eventBus.off('scalechanging', webViewerScaleChanging);
  932. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  933. eventBus.off('pagemode', webViewerPageMode);
  934. eventBus.off('namedaction', webViewerNamedAction);
  935. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  936. eventBus.off('presentationmode', webViewerPresentationMode);
  937. eventBus.off('openfile', webViewerOpenFile);
  938. eventBus.off('print', webViewerPrint);
  939. eventBus.off('download', webViewerDownload);
  940. eventBus.off('firstpage', webViewerFirstPage);
  941. eventBus.off('lastpage', webViewerLastPage);
  942. eventBus.off('nextpage', webViewerNextPage);
  943. eventBus.off('previouspage', webViewerPreviousPage);
  944. eventBus.off('zoomin', webViewerZoomIn);
  945. eventBus.off('zoomout', webViewerZoomOut);
  946. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  947. eventBus.off('scalechanged', webViewerScaleChanged);
  948. eventBus.off('rotatecw', webViewerRotateCw);
  949. eventBus.off('rotateccw', webViewerRotateCcw);
  950. eventBus.off('documentproperties', webViewerDocumentProperties);
  951. eventBus.off('find', webViewerFind);
  952. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  953. eventBus.off('fileinputchange', webViewerFileInputChange);
  954. _boundEvents.beforePrint = null;
  955. _boundEvents.afterPrint = null;
  956. },
  957. unbindWindowEvents: function unbindWindowEvents() {
  958. var _boundEvents = this._boundEvents;
  959. window.removeEventListener('wheel', webViewerWheel);
  960. window.removeEventListener('click', webViewerClick);
  961. window.removeEventListener('keydown', webViewerKeyDown);
  962. window.removeEventListener('resize', _boundEvents.windowResize);
  963. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  964. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  965. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  966. window.removeEventListener('change', _boundEvents.windowChange);
  967. _boundEvents.windowChange = null;
  968. _boundEvents.windowResize = null;
  969. _boundEvents.windowHashChange = null;
  970. _boundEvents.windowBeforePrint = null;
  971. _boundEvents.windowAfterPrint = null;
  972. }
  973. };
  974. var validateFileURL = void 0;
  975. {
  976. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  977. validateFileURL = function validateFileURL(file) {
  978. if (file === undefined) {
  979. return;
  980. }
  981. try {
  982. var viewerOrigin = new URL(window.location.href).origin || 'null';
  983. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  984. return;
  985. }
  986. var fileOrigin = new URL(file, window.location.href).origin;
  987. if (fileOrigin !== viewerOrigin) {
  988. throw new Error('file origin does not match viewer\'s');
  989. }
  990. } catch (ex) {
  991. var message = ex && ex.message;
  992. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  993. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  994. });
  995. throw ex;
  996. }
  997. };
  998. }
  999. function loadAndEnablePDFBug(enabledTabs) {
  1000. return new Promise(function (resolve, reject) {
  1001. var appConfig = PDFViewerApplication.appConfig;
  1002. var script = document.createElement('script');
  1003. script.src = appConfig.debuggerScriptPath;
  1004. script.onload = function () {
  1005. PDFBug.enable(enabledTabs);
  1006. PDFBug.init({
  1007. PDFJS: _pdf.PDFJS,
  1008. OPS: _pdf.OPS
  1009. }, appConfig.mainContainer);
  1010. resolve();
  1011. };
  1012. script.onerror = function () {
  1013. reject(new Error('Cannot load debugger at ' + script.src));
  1014. };
  1015. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1016. });
  1017. }
  1018. function webViewerInitialized() {
  1019. var appConfig = PDFViewerApplication.appConfig;
  1020. var file = void 0;
  1021. var queryString = document.location.search.substring(1);
  1022. var params = (0, _ui_utils.parseQueryString)(queryString);
  1023. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1024. validateFileURL(file);
  1025. var waitForBeforeOpening = [];
  1026. var fileInput = document.createElement('input');
  1027. fileInput.id = appConfig.openFileInputName;
  1028. fileInput.className = 'fileInput';
  1029. fileInput.setAttribute('type', 'file');
  1030. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1031. document.body.appendChild(fileInput);
  1032. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1033. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1034. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1035. } else {
  1036. fileInput.value = null;
  1037. }
  1038. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  1039. var hash = document.location.hash.substring(1);
  1040. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  1041. if ('disableworker' in hashParams) {
  1042. _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  1043. }
  1044. if ('disablerange' in hashParams) {
  1045. _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  1046. }
  1047. if ('disablestream' in hashParams) {
  1048. _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  1049. }
  1050. if ('disableautofetch' in hashParams) {
  1051. _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  1052. }
  1053. if ('disablefontface' in hashParams) {
  1054. _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  1055. }
  1056. if ('disablehistory' in hashParams) {
  1057. _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  1058. }
  1059. if ('webgl' in hashParams) {
  1060. _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  1061. }
  1062. if ('useonlycsszoom' in hashParams) {
  1063. _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  1064. }
  1065. if ('verbosity' in hashParams) {
  1066. _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
  1067. }
  1068. if ('ignorecurrentpositiononzoom' in hashParams) {
  1069. _pdf.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  1070. }
  1071. if ('textlayer' in hashParams) {
  1072. switch (hashParams['textlayer']) {
  1073. case 'off':
  1074. _pdf.PDFJS.disableTextLayer = true;
  1075. break;
  1076. case 'visible':
  1077. case 'shadow':
  1078. case 'hover':
  1079. var viewer = appConfig.viewerContainer;
  1080. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  1081. break;
  1082. }
  1083. }
  1084. if ('pdfbug' in hashParams) {
  1085. _pdf.PDFJS.pdfBug = true;
  1086. var pdfBug = hashParams['pdfbug'];
  1087. var enabled = pdfBug.split(',');
  1088. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  1089. }
  1090. }
  1091. if (!PDFViewerApplication.supportsPrinting) {
  1092. appConfig.toolbar.print.classList.add('hidden');
  1093. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1094. }
  1095. if (!PDFViewerApplication.supportsFullscreen) {
  1096. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1097. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1098. }
  1099. if (PDFViewerApplication.supportsIntegratedFind) {
  1100. appConfig.toolbar.viewFind.classList.add('hidden');
  1101. }
  1102. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (evt) {
  1103. if (evt.target === this) {
  1104. PDFViewerApplication.eventBus.dispatch('resize');
  1105. }
  1106. }, true);
  1107. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1108. PDFViewerApplication.pdfSidebar.toggle();
  1109. });
  1110. Promise.all(waitForBeforeOpening).then(function () {
  1111. webViewerOpenFileViaURL(file);
  1112. }).catch(function (reason) {
  1113. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
  1114. PDFViewerApplication.error(msg, reason);
  1115. });
  1116. });
  1117. }
  1118. var webViewerOpenFileViaURL = void 0;
  1119. {
  1120. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1121. if (file && file.lastIndexOf('file:', 0) === 0) {
  1122. PDFViewerApplication.setTitleUsingUrl(file);
  1123. var xhr = new XMLHttpRequest();
  1124. xhr.onload = function () {
  1125. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1126. };
  1127. try {
  1128. xhr.open('GET', file);
  1129. xhr.responseType = 'arraybuffer';
  1130. xhr.send();
  1131. } catch (ex) {
  1132. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1133. PDFViewerApplication.error(msg, ex);
  1134. });
  1135. }
  1136. return;
  1137. }
  1138. if (file) {
  1139. PDFViewerApplication.open(file);
  1140. }
  1141. };
  1142. }
  1143. function webViewerPageRendered(evt) {
  1144. var pageNumber = evt.pageNumber;
  1145. var pageIndex = pageNumber - 1;
  1146. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1147. if (pageNumber === PDFViewerApplication.page) {
  1148. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1149. }
  1150. if (!pageView) {
  1151. return;
  1152. }
  1153. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1154. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1155. thumbnailView.setImage(pageView);
  1156. }
  1157. if (_pdf.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1158. Stats.add(pageNumber, pageView.stats);
  1159. }
  1160. if (pageView.error) {
  1161. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1162. PDFViewerApplication.error(msg, pageView.error);
  1163. });
  1164. }
  1165. }
  1166. function webViewerTextLayerRendered(evt) {}
  1167. function webViewerPageMode(evt) {
  1168. var mode = evt.mode,
  1169. view = void 0;
  1170. switch (mode) {
  1171. case 'thumbs':
  1172. view = _pdf_sidebar.SidebarView.THUMBS;
  1173. break;
  1174. case 'bookmarks':
  1175. case 'outline':
  1176. view = _pdf_sidebar.SidebarView.OUTLINE;
  1177. break;
  1178. case 'attachments':
  1179. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1180. break;
  1181. case 'none':
  1182. view = _pdf_sidebar.SidebarView.NONE;
  1183. break;
  1184. default:
  1185. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1186. return;
  1187. }
  1188. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1189. }
  1190. function webViewerNamedAction(evt) {
  1191. var action = evt.action;
  1192. switch (action) {
  1193. case 'GoToPage':
  1194. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1195. break;
  1196. case 'Find':
  1197. if (!PDFViewerApplication.supportsIntegratedFind) {
  1198. PDFViewerApplication.findBar.toggle();
  1199. }
  1200. break;
  1201. }
  1202. }
  1203. function webViewerPresentationModeChanged(evt) {
  1204. var active = evt.active,
  1205. switchInProgress = evt.switchInProgress;
  1206. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
  1207. }
  1208. function webViewerSidebarViewChanged(evt) {
  1209. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1210. var store = PDFViewerApplication.store;
  1211. if (store && PDFViewerApplication.isInitialViewSet) {
  1212. store.set('sidebarView', evt.view).catch(function () {});
  1213. }
  1214. }
  1215. function webViewerUpdateViewarea(evt) {
  1216. var location = evt.location,
  1217. store = PDFViewerApplication.store;
  1218. if (store && PDFViewerApplication.isInitialViewSet) {
  1219. store.setMultiple({
  1220. 'exists': true,
  1221. 'page': location.pageNumber,
  1222. 'zoom': location.scale,
  1223. 'scrollLeft': location.left,
  1224. 'scrollTop': location.top
  1225. }).catch(function () {});
  1226. }
  1227. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1228. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1229. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1230. PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  1231. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1232. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1233. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1234. }
  1235. function webViewerResize() {
  1236. var pdfDocument = PDFViewerApplication.pdfDocument,
  1237. pdfViewer = PDFViewerApplication.pdfViewer;
  1238. if (!pdfDocument) {
  1239. return;
  1240. }
  1241. var currentScaleValue = pdfViewer.currentScaleValue;
  1242. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1243. pdfViewer.currentScaleValue = currentScaleValue;
  1244. }
  1245. pdfViewer.update();
  1246. }
  1247. function webViewerHashchange(evt) {
  1248. if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
  1249. var hash = evt.hash;
  1250. if (!hash) {
  1251. return;
  1252. }
  1253. if (!PDFViewerApplication.isInitialViewSet) {
  1254. PDFViewerApplication.initialBookmark = hash;
  1255. } else {
  1256. PDFViewerApplication.pdfLinkService.setHash(hash);
  1257. }
  1258. }
  1259. }
  1260. var webViewerFileInputChange = void 0;
  1261. {
  1262. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  1263. var file = evt.fileInput.files[0];
  1264. if (!_pdf.PDFJS.disableCreateObjectURL && URL.createObjectURL) {
  1265. PDFViewerApplication.open(URL.createObjectURL(file));
  1266. } else {
  1267. var fileReader = new FileReader();
  1268. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1269. var buffer = evt.target.result;
  1270. PDFViewerApplication.open(new Uint8Array(buffer));
  1271. };
  1272. fileReader.readAsArrayBuffer(file);
  1273. }
  1274. PDFViewerApplication.setTitleUsingUrl(file.name);
  1275. var appConfig = PDFViewerApplication.appConfig;
  1276. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1277. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1278. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1279. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1280. };
  1281. }
  1282. function webViewerPresentationMode() {
  1283. PDFViewerApplication.requestPresentationMode();
  1284. }
  1285. function webViewerOpenFile() {
  1286. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1287. document.getElementById(openFileInputName).click();
  1288. }
  1289. function webViewerPrint() {
  1290. window.print();
  1291. }
  1292. function webViewerDownload() {
  1293. PDFViewerApplication.download();
  1294. }
  1295. function webViewerFirstPage() {
  1296. if (PDFViewerApplication.pdfDocument) {
  1297. PDFViewerApplication.page = 1;
  1298. }
  1299. }
  1300. function webViewerLastPage() {
  1301. if (PDFViewerApplication.pdfDocument) {
  1302. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1303. }
  1304. }
  1305. function webViewerNextPage() {
  1306. PDFViewerApplication.page++;
  1307. }
  1308. function webViewerPreviousPage() {
  1309. PDFViewerApplication.page--;
  1310. }
  1311. function webViewerZoomIn() {
  1312. PDFViewerApplication.zoomIn();
  1313. }
  1314. function webViewerZoomOut() {
  1315. PDFViewerApplication.zoomOut();
  1316. }
  1317. function webViewerPageNumberChanged(evt) {
  1318. var pdfViewer = PDFViewerApplication.pdfViewer;
  1319. pdfViewer.currentPageLabel = evt.value;
  1320. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1321. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1322. }
  1323. }
  1324. function webViewerScaleChanged(evt) {
  1325. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1326. }
  1327. function webViewerRotateCw() {
  1328. PDFViewerApplication.rotatePages(90);
  1329. }
  1330. function webViewerRotateCcw() {
  1331. PDFViewerApplication.rotatePages(-90);
  1332. }
  1333. function webViewerDocumentProperties() {
  1334. PDFViewerApplication.pdfDocumentProperties.open();
  1335. }
  1336. function webViewerFind(evt) {
  1337. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  1338. query: evt.query,
  1339. phraseSearch: evt.phraseSearch,
  1340. caseSensitive: evt.caseSensitive,
  1341. highlightAll: evt.highlightAll,
  1342. findPrevious: evt.findPrevious
  1343. });
  1344. }
  1345. function webViewerFindFromUrlHash(evt) {
  1346. PDFViewerApplication.findController.executeCommand('find', {
  1347. query: evt.query,
  1348. phraseSearch: evt.phraseSearch,
  1349. caseSensitive: false,
  1350. highlightAll: true,
  1351. findPrevious: false
  1352. });
  1353. }
  1354. function webViewerScaleChanging(evt) {
  1355. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1356. PDFViewerApplication.pdfViewer.update();
  1357. }
  1358. function webViewerPageChanging(evt) {
  1359. var page = evt.pageNumber;
  1360. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1361. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1362. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1363. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1364. }
  1365. if (_pdf.PDFJS.pdfBug && Stats.enabled) {
  1366. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1367. if (pageView.stats) {
  1368. Stats.add(page, pageView.stats);
  1369. }
  1370. }
  1371. }
  1372. var zoomDisabled = false,
  1373. zoomDisabledTimeout = void 0;
  1374. function webViewerWheel(evt) {
  1375. var pdfViewer = PDFViewerApplication.pdfViewer;
  1376. if (pdfViewer.isInPresentationMode) {
  1377. return;
  1378. }
  1379. if (evt.ctrlKey || evt.metaKey) {
  1380. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1381. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1382. return;
  1383. }
  1384. evt.preventDefault();
  1385. if (zoomDisabled) {
  1386. return;
  1387. }
  1388. var previousScale = pdfViewer.currentScale;
  1389. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1390. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1391. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1392. if (ticks < 0) {
  1393. PDFViewerApplication.zoomOut(-ticks);
  1394. } else {
  1395. PDFViewerApplication.zoomIn(ticks);
  1396. }
  1397. var currentScale = pdfViewer.currentScale;
  1398. if (previousScale !== currentScale) {
  1399. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1400. var rect = pdfViewer.container.getBoundingClientRect();
  1401. var dx = evt.clientX - rect.left;
  1402. var dy = evt.clientY - rect.top;
  1403. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1404. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1405. }
  1406. } else {
  1407. zoomDisabled = true;
  1408. clearTimeout(zoomDisabledTimeout);
  1409. zoomDisabledTimeout = setTimeout(function () {
  1410. zoomDisabled = false;
  1411. }, 1000);
  1412. }
  1413. }
  1414. function webViewerClick(evt) {
  1415. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1416. return;
  1417. }
  1418. var appConfig = PDFViewerApplication.appConfig;
  1419. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1420. PDFViewerApplication.secondaryToolbar.close();
  1421. }
  1422. }
  1423. function webViewerKeyDown(evt) {
  1424. if (PDFViewerApplication.overlayManager.active) {
  1425. return;
  1426. }
  1427. var handled = false,
  1428. ensureViewerFocused = false;
  1429. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1430. var pdfViewer = PDFViewerApplication.pdfViewer;
  1431. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1432. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1433. switch (evt.keyCode) {
  1434. case 70:
  1435. if (!PDFViewerApplication.supportsIntegratedFind) {
  1436. PDFViewerApplication.findBar.open();
  1437. handled = true;
  1438. }
  1439. break;
  1440. case 71:
  1441. if (!PDFViewerApplication.supportsIntegratedFind) {
  1442. var findState = PDFViewerApplication.findController.state;
  1443. if (findState) {
  1444. PDFViewerApplication.findController.executeCommand('findagain', {
  1445. query: findState.query,
  1446. phraseSearch: findState.phraseSearch,
  1447. caseSensitive: findState.caseSensitive,
  1448. highlightAll: findState.highlightAll,
  1449. findPrevious: cmd === 5 || cmd === 12
  1450. });
  1451. }
  1452. handled = true;
  1453. }
  1454. break;
  1455. case 61:
  1456. case 107:
  1457. case 187:
  1458. case 171:
  1459. if (!isViewerInPresentationMode) {
  1460. PDFViewerApplication.zoomIn();
  1461. }
  1462. handled = true;
  1463. break;
  1464. case 173:
  1465. case 109:
  1466. case 189:
  1467. if (!isViewerInPresentationMode) {
  1468. PDFViewerApplication.zoomOut();
  1469. }
  1470. handled = true;
  1471. break;
  1472. case 48:
  1473. case 96:
  1474. if (!isViewerInPresentationMode) {
  1475. setTimeout(function () {
  1476. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1477. });
  1478. handled = false;
  1479. }
  1480. break;
  1481. case 38:
  1482. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1483. PDFViewerApplication.page = 1;
  1484. handled = true;
  1485. ensureViewerFocused = true;
  1486. }
  1487. break;
  1488. case 40:
  1489. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1490. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1491. handled = true;
  1492. ensureViewerFocused = true;
  1493. }
  1494. break;
  1495. }
  1496. }
  1497. if (cmd === 1 || cmd === 8) {
  1498. switch (evt.keyCode) {
  1499. case 83:
  1500. PDFViewerApplication.download();
  1501. handled = true;
  1502. break;
  1503. }
  1504. }
  1505. if (cmd === 3 || cmd === 10) {
  1506. switch (evt.keyCode) {
  1507. case 80:
  1508. PDFViewerApplication.requestPresentationMode();
  1509. handled = true;
  1510. break;
  1511. case 71:
  1512. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1513. handled = true;
  1514. break;
  1515. }
  1516. }
  1517. if (handled) {
  1518. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1519. pdfViewer.focus();
  1520. }
  1521. evt.preventDefault();
  1522. return;
  1523. }
  1524. var curElement = document.activeElement || document.querySelector(':focus');
  1525. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1526. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1527. if (evt.keyCode !== 27) {
  1528. return;
  1529. }
  1530. }
  1531. if (cmd === 0) {
  1532. switch (evt.keyCode) {
  1533. case 38:
  1534. case 33:
  1535. case 8:
  1536. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1537. break;
  1538. }
  1539. case 37:
  1540. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1541. break;
  1542. }
  1543. case 75:
  1544. case 80:
  1545. if (PDFViewerApplication.page > 1) {
  1546. PDFViewerApplication.page--;
  1547. }
  1548. handled = true;
  1549. break;
  1550. case 27:
  1551. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1552. PDFViewerApplication.secondaryToolbar.close();
  1553. handled = true;
  1554. }
  1555. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1556. PDFViewerApplication.findBar.close();
  1557. handled = true;
  1558. }
  1559. break;
  1560. case 40:
  1561. case 34:
  1562. case 32:
  1563. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1564. break;
  1565. }
  1566. case 39:
  1567. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1568. break;
  1569. }
  1570. case 74:
  1571. case 78:
  1572. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1573. PDFViewerApplication.page++;
  1574. }
  1575. handled = true;
  1576. break;
  1577. case 36:
  1578. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1579. PDFViewerApplication.page = 1;
  1580. handled = true;
  1581. ensureViewerFocused = true;
  1582. }
  1583. break;
  1584. case 35:
  1585. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1586. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1587. handled = true;
  1588. ensureViewerFocused = true;
  1589. }
  1590. break;
  1591. case 83:
  1592. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1593. break;
  1594. case 72:
  1595. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1596. break;
  1597. case 82:
  1598. PDFViewerApplication.rotatePages(90);
  1599. break;
  1600. }
  1601. }
  1602. if (cmd === 4) {
  1603. switch (evt.keyCode) {
  1604. case 32:
  1605. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1606. break;
  1607. }
  1608. if (PDFViewerApplication.page > 1) {
  1609. PDFViewerApplication.page--;
  1610. }
  1611. handled = true;
  1612. break;
  1613. case 82:
  1614. PDFViewerApplication.rotatePages(-90);
  1615. break;
  1616. }
  1617. }
  1618. if (!handled && !isViewerInPresentationMode) {
  1619. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1620. ensureViewerFocused = true;
  1621. }
  1622. }
  1623. if (cmd === 2) {
  1624. switch (evt.keyCode) {
  1625. case 37:
  1626. if (isViewerInPresentationMode) {
  1627. PDFViewerApplication.pdfHistory.back();
  1628. handled = true;
  1629. }
  1630. break;
  1631. case 39:
  1632. if (isViewerInPresentationMode) {
  1633. PDFViewerApplication.pdfHistory.forward();
  1634. handled = true;
  1635. }
  1636. break;
  1637. }
  1638. }
  1639. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1640. pdfViewer.focus();
  1641. }
  1642. if (handled) {
  1643. evt.preventDefault();
  1644. }
  1645. }
  1646. function apiPageModeToSidebarView(mode) {
  1647. switch (mode) {
  1648. case 'UseNone':
  1649. return _pdf_sidebar.SidebarView.NONE;
  1650. case 'UseThumbs':
  1651. return _pdf_sidebar.SidebarView.THUMBS;
  1652. case 'UseOutlines':
  1653. return _pdf_sidebar.SidebarView.OUTLINE;
  1654. case 'UseAttachments':
  1655. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  1656. case 'UseOC':
  1657. }
  1658. return _pdf_sidebar.SidebarView.NONE;
  1659. }
  1660. var PDFPrintServiceFactory = {
  1661. instance: {
  1662. supportsPrinting: false,
  1663. createPrintService: function createPrintService() {
  1664. throw new Error('Not implemented: createPrintService');
  1665. }
  1666. }
  1667. };
  1668. exports.PDFViewerApplication = PDFViewerApplication;
  1669. exports.DefaultExternalServices = DefaultExternalServices;
  1670. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;