app.js 58 KB

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