app.js 61 KB

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