2
0

app.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  20. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  21. var _ui_utils = require('./ui_utils');
  22. var _pdf = require('../pdf');
  23. var _pdf_cursor_tools = require('./pdf_cursor_tools');
  24. var _pdf_rendering_queue = require('./pdf_rendering_queue');
  25. var _pdf_sidebar = require('./pdf_sidebar');
  26. var _pdf_viewer = require('./pdf_viewer');
  27. var _dom_events = require('./dom_events');
  28. var _overlay_manager = require('./overlay_manager');
  29. var _password_prompt = require('./password_prompt');
  30. var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
  31. var _pdf_document_properties = require('./pdf_document_properties');
  32. var _pdf_find_bar = require('./pdf_find_bar');
  33. var _pdf_find_controller = require('./pdf_find_controller');
  34. var _pdf_history = require('./pdf_history');
  35. var _pdf_link_service = require('./pdf_link_service');
  36. var _pdf_outline_viewer = require('./pdf_outline_viewer');
  37. var _pdf_presentation_mode = require('./pdf_presentation_mode');
  38. var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
  39. var _secondary_toolbar = require('./secondary_toolbar');
  40. var _toolbar = require('./toolbar');
  41. var _view_history = require('./view_history');
  42. var DEFAULT_SCALE_DELTA = 1.1;
  43. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  44. function configure(PDFJS) {
  45. PDFJS.imageResourcesPath = './images/';
  46. PDFJS.workerSrc = '../build/pdf.worker.js';
  47. PDFJS.cMapUrl = '../web/cmaps/';
  48. PDFJS.cMapPacked = true;
  49. }
  50. var DefaultExternalServices = {
  51. updateFindControlState: function updateFindControlState(data) {},
  52. initPassiveLoading: function initPassiveLoading(callbacks) {},
  53. fallback: function fallback(data, callback) {},
  54. reportTelemetry: function reportTelemetry(data) {},
  55. createDownloadManager: function createDownloadManager() {
  56. throw new Error('Not implemented: createDownloadManager');
  57. },
  58. createPreferences: function createPreferences() {
  59. throw new Error('Not implemented: createPreferences');
  60. },
  61. createL10n: function createL10n() {
  62. throw new Error('Not implemented: createL10n');
  63. },
  64. supportsIntegratedFind: false,
  65. supportsDocumentFonts: true,
  66. supportsDocumentColors: true,
  67. supportedMouseWheelZoomModifierKeys: {
  68. ctrlKey: true,
  69. metaKey: true
  70. }
  71. };
  72. var PDFViewerApplication = {
  73. initialBookmark: document.location.hash.substring(1),
  74. initialDestination: null,
  75. initialized: false,
  76. fellback: false,
  77. appConfig: null,
  78. pdfDocument: null,
  79. pdfLoadingTask: null,
  80. printService: null,
  81. pdfViewer: null,
  82. pdfThumbnailViewer: null,
  83. pdfRenderingQueue: null,
  84. pdfPresentationMode: null,
  85. pdfDocumentProperties: null,
  86. pdfLinkService: null,
  87. pdfHistory: null,
  88. pdfSidebar: null,
  89. pdfOutlineViewer: null,
  90. pdfAttachmentViewer: null,
  91. pdfCursorTools: null,
  92. store: null,
  93. downloadManager: null,
  94. overlayManager: null,
  95. preferences: null,
  96. toolbar: null,
  97. secondaryToolbar: null,
  98. eventBus: null,
  99. l10n: null,
  100. isInitialViewSet: false,
  101. downloadComplete: false,
  102. viewerPrefs: {
  103. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  104. pdfBugEnabled: false,
  105. showPreviousViewOnLoad: true,
  106. defaultZoomValue: '',
  107. disablePageMode: false,
  108. disablePageLabels: false,
  109. renderer: 'canvas',
  110. enhanceTextSelection: false,
  111. renderInteractiveForms: false,
  112. enablePrintAutoRotate: false
  113. },
  114. isViewerEmbedded: window.parent !== window,
  115. url: '',
  116. baseUrl: '',
  117. externalServices: DefaultExternalServices,
  118. _boundEvents: {},
  119. initialize: function initialize(appConfig) {
  120. var _this = this;
  121. this.preferences = this.externalServices.createPreferences();
  122. configure(_pdf.PDFJS);
  123. this.appConfig = appConfig;
  124. return this._readPreferences().then(function () {
  125. return _this._initializeL10n();
  126. }).then(function () {
  127. return _this._initializeViewerComponents();
  128. }).then(function () {
  129. _this.bindEvents();
  130. _this.bindWindowEvents();
  131. var appContainer = appConfig.appContainer || document.documentElement;
  132. _this.l10n.translate(appContainer).then(function () {
  133. _this.eventBus.dispatch('localized');
  134. });
  135. if (_this.isViewerEmbedded && !_pdf.PDFJS.isExternalLinkTargetSet()) {
  136. _pdf.PDFJS.externalLinkTarget = _pdf.PDFJS.LinkTarget.TOP;
  137. }
  138. _this.initialized = true;
  139. });
  140. },
  141. _readPreferences: function _readPreferences() {
  142. var preferences = this.preferences,
  143. viewerPrefs = this.viewerPrefs;
  144. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  145. _pdf.PDFJS.disableWebGL = !value;
  146. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  147. viewerPrefs['sidebarViewOnLoad'] = value;
  148. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  149. viewerPrefs['pdfBugEnabled'] = value;
  150. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  151. viewerPrefs['showPreviousViewOnLoad'] = value;
  152. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  153. viewerPrefs['defaultZoomValue'] = value;
  154. }), preferences.get('enhanceTextSelection').then(function resolved(value) {
  155. viewerPrefs['enhanceTextSelection'] = value;
  156. }), preferences.get('disableTextLayer').then(function resolved(value) {
  157. if (_pdf.PDFJS.disableTextLayer === true) {
  158. return;
  159. }
  160. _pdf.PDFJS.disableTextLayer = value;
  161. }), preferences.get('disableRange').then(function resolved(value) {
  162. if (_pdf.PDFJS.disableRange === true) {
  163. return;
  164. }
  165. _pdf.PDFJS.disableRange = value;
  166. }), preferences.get('disableStream').then(function resolved(value) {
  167. if (_pdf.PDFJS.disableStream === true) {
  168. return;
  169. }
  170. _pdf.PDFJS.disableStream = value;
  171. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  172. _pdf.PDFJS.disableAutoFetch = value;
  173. }), preferences.get('disableFontFace').then(function resolved(value) {
  174. if (_pdf.PDFJS.disableFontFace === true) {
  175. return;
  176. }
  177. _pdf.PDFJS.disableFontFace = value;
  178. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  179. _pdf.PDFJS.useOnlyCssZoom = value;
  180. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  181. if (_pdf.PDFJS.isExternalLinkTargetSet()) {
  182. return;
  183. }
  184. _pdf.PDFJS.externalLinkTarget = value;
  185. }), preferences.get('renderer').then(function resolved(value) {
  186. viewerPrefs['renderer'] = value;
  187. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  188. viewerPrefs['renderInteractiveForms'] = value;
  189. }), preferences.get('disablePageMode').then(function resolved(value) {
  190. viewerPrefs['disablePageMode'] = value;
  191. }), preferences.get('disablePageLabels').then(function resolved(value) {
  192. viewerPrefs['disablePageLabels'] = value;
  193. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  194. viewerPrefs['enablePrintAutoRotate'] = value;
  195. })]).catch(function (reason) {});
  196. },
  197. _initializeL10n: function _initializeL10n() {
  198. if (this.viewerPrefs['pdfBugEnabled']) {
  199. var hash = document.location.hash.substring(1);
  200. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  201. if ('locale' in hashParams) {
  202. _pdf.PDFJS.locale = hashParams['locale'];
  203. }
  204. }
  205. this.l10n = this.externalServices.createL10n();
  206. return this.l10n.getDirection().then(function (dir) {
  207. document.getElementsByTagName('html')[0].dir = dir;
  208. });
  209. },
  210. _initializeViewerComponents: function _initializeViewerComponents() {
  211. var _this2 = this;
  212. var appConfig = this.appConfig;
  213. return new Promise(function (resolve, reject) {
  214. _this2.overlayManager = new _overlay_manager.OverlayManager();
  215. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  216. _this2.eventBus = eventBus;
  217. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  218. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  219. _this2.pdfRenderingQueue = pdfRenderingQueue;
  220. var pdfLinkService = new _pdf_link_service.PDFLinkService({ eventBus: eventBus });
  221. _this2.pdfLinkService = pdfLinkService;
  222. var downloadManager = _this2.externalServices.createDownloadManager();
  223. _this2.downloadManager = downloadManager;
  224. var container = appConfig.mainContainer;
  225. var viewer = appConfig.viewerContainer;
  226. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  227. container: container,
  228. viewer: viewer,
  229. eventBus: eventBus,
  230. renderingQueue: pdfRenderingQueue,
  231. linkService: pdfLinkService,
  232. downloadManager: downloadManager,
  233. renderer: _this2.viewerPrefs['renderer'],
  234. l10n: _this2.l10n,
  235. enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
  236. renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
  237. enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
  238. });
  239. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  240. pdfLinkService.setViewer(_this2.pdfViewer);
  241. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  242. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  243. container: thumbnailContainer,
  244. renderingQueue: pdfRenderingQueue,
  245. linkService: pdfLinkService,
  246. l10n: _this2.l10n
  247. });
  248. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  249. _this2.pdfHistory = new _pdf_history.PDFHistory({
  250. linkService: pdfLinkService,
  251. eventBus: eventBus
  252. });
  253. pdfLinkService.setHistory(_this2.pdfHistory);
  254. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  255. _this2.findController.onUpdateResultsCount = function (matchCount) {
  256. if (_this2.supportsIntegratedFind) {
  257. return;
  258. }
  259. _this2.findBar.updateResultsCount(matchCount);
  260. };
  261. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  262. if (_this2.supportsIntegratedFind) {
  263. _this2.externalServices.updateFindControlState({
  264. result: state,
  265. findPrevious: previous
  266. });
  267. } else {
  268. _this2.findBar.updateUIState(state, previous, matchCount);
  269. }
  270. };
  271. _this2.pdfViewer.setFindController(_this2.findController);
  272. var findBarConfig = Object.create(appConfig.findBar);
  273. findBarConfig.findController = _this2.findController;
  274. findBarConfig.eventBus = eventBus;
  275. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
  276. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
  277. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  278. container: container,
  279. eventBus: eventBus,
  280. preferences: _this2.preferences
  281. });
  282. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
  283. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  284. if (_this2.supportsFullscreen) {
  285. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  286. container: container,
  287. viewer: viewer,
  288. pdfViewer: _this2.pdfViewer,
  289. eventBus: eventBus,
  290. contextMenuItems: appConfig.fullscreen
  291. });
  292. }
  293. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
  294. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  295. container: appConfig.sidebar.outlineView,
  296. eventBus: eventBus,
  297. linkService: pdfLinkService
  298. });
  299. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  300. container: appConfig.sidebar.attachmentsView,
  301. eventBus: eventBus,
  302. downloadManager: downloadManager
  303. });
  304. var sidebarConfig = Object.create(appConfig.sidebar);
  305. sidebarConfig.pdfViewer = _this2.pdfViewer;
  306. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  307. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  308. sidebarConfig.eventBus = eventBus;
  309. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
  310. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  311. resolve(undefined);
  312. });
  313. },
  314. run: function run(config) {
  315. this.initialize(config).then(webViewerInitialized);
  316. },
  317. zoomIn: function zoomIn(ticks) {
  318. var newScale = this.pdfViewer.currentScale;
  319. do {
  320. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  321. newScale = Math.ceil(newScale * 10) / 10;
  322. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  323. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  324. this.pdfViewer.currentScaleValue = newScale;
  325. },
  326. zoomOut: function zoomOut(ticks) {
  327. var newScale = this.pdfViewer.currentScale;
  328. do {
  329. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  330. newScale = Math.floor(newScale * 10) / 10;
  331. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  332. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  333. this.pdfViewer.currentScaleValue = newScale;
  334. },
  335. get pagesCount() {
  336. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  337. },
  338. get pageRotation() {
  339. return this.pdfViewer.pagesRotation;
  340. },
  341. set page(val) {
  342. this.pdfViewer.currentPageNumber = val;
  343. },
  344. get page() {
  345. return this.pdfViewer.currentPageNumber;
  346. },
  347. get printing() {
  348. return !!this.printService;
  349. },
  350. get supportsPrinting() {
  351. return PDFPrintServiceFactory.instance.supportsPrinting;
  352. },
  353. get supportsFullscreen() {
  354. var support = void 0;
  355. var doc = document.documentElement;
  356. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  357. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  358. support = false;
  359. }
  360. if (support && _pdf.PDFJS.disableFullscreen === true) {
  361. support = false;
  362. }
  363. return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
  364. },
  365. get supportsIntegratedFind() {
  366. return this.externalServices.supportsIntegratedFind;
  367. },
  368. get supportsDocumentFonts() {
  369. return this.externalServices.supportsDocumentFonts;
  370. },
  371. get supportsDocumentColors() {
  372. return this.externalServices.supportsDocumentColors;
  373. },
  374. get loadingBar() {
  375. var bar = new _ui_utils.ProgressBar('#loadingBar');
  376. return (0, _pdf.shadow)(this, 'loadingBar', bar);
  377. },
  378. get supportedMouseWheelZoomModifierKeys() {
  379. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  380. },
  381. initPassiveLoading: function initPassiveLoading() {
  382. throw new Error('Not implemented: initPassiveLoading');
  383. },
  384. setTitleUsingUrl: function setTitleUsingUrl(url) {
  385. this.url = url;
  386. this.baseUrl = url.split('#')[0];
  387. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  388. if (!title) {
  389. try {
  390. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  391. } catch (ex) {
  392. title = url;
  393. }
  394. }
  395. this.setTitle(title);
  396. },
  397. setTitle: function setTitle(title) {
  398. if (this.isViewerEmbedded) {
  399. return;
  400. }
  401. document.title = title;
  402. },
  403. close: function close() {
  404. var errorWrapper = this.appConfig.errorWrapper.container;
  405. errorWrapper.setAttribute('hidden', 'true');
  406. if (!this.pdfLoadingTask) {
  407. return Promise.resolve();
  408. }
  409. var promise = this.pdfLoadingTask.destroy();
  410. this.pdfLoadingTask = null;
  411. if (this.pdfDocument) {
  412. this.pdfDocument = null;
  413. this.pdfThumbnailViewer.setDocument(null);
  414. this.pdfViewer.setDocument(null);
  415. this.pdfLinkService.setDocument(null, null);
  416. this.pdfDocumentProperties.setDocument(null, null);
  417. }
  418. this.store = null;
  419. this.isInitialViewSet = false;
  420. this.downloadComplete = false;
  421. this.pdfSidebar.reset();
  422. this.pdfOutlineViewer.reset();
  423. this.pdfAttachmentViewer.reset();
  424. this.findController.reset();
  425. this.findBar.reset();
  426. this.toolbar.reset();
  427. this.secondaryToolbar.reset();
  428. if (typeof PDFBug !== 'undefined') {
  429. PDFBug.cleanup();
  430. }
  431. return promise;
  432. },
  433. open: function open(file, args) {
  434. var _this3 = this;
  435. if (arguments.length > 2 || typeof args === 'number') {
  436. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  437. }
  438. if (this.pdfLoadingTask) {
  439. return this.close().then(function () {
  440. _this3.preferences.reload();
  441. return _this3.open(file, args);
  442. });
  443. }
  444. var parameters = Object.create(null);
  445. if (typeof file === 'string') {
  446. this.setTitleUsingUrl(file);
  447. parameters.url = file;
  448. } else if (file && 'byteLength' in file) {
  449. parameters.data = file;
  450. } else if (file.url && file.originalUrl) {
  451. this.setTitleUsingUrl(file.originalUrl);
  452. parameters.url = file.url;
  453. }
  454. if (args) {
  455. for (var prop in args) {
  456. if (!_pdf.PDFJS.pdfjsNext && prop === 'scale') {
  457. console.error('Call of open() with obsolete "scale" argument, ' + 'please use the "defaultZoomValue" preference instead.');
  458. continue;
  459. } else if (prop === 'length') {
  460. this.pdfDocumentProperties.setFileSize(args[prop]);
  461. }
  462. parameters[prop] = args[prop];
  463. }
  464. }
  465. var loadingTask = (0, _pdf.getDocument)(parameters);
  466. this.pdfLoadingTask = loadingTask;
  467. loadingTask.onPassword = function (updateCallback, reason) {
  468. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  469. _this3.passwordPrompt.open();
  470. };
  471. loadingTask.onProgress = function (_ref) {
  472. var loaded = _ref.loaded,
  473. total = _ref.total;
  474. _this3.progress(loaded / total);
  475. };
  476. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  477. return loadingTask.promise.then(function (pdfDocument) {
  478. _this3.load(pdfDocument);
  479. }, function (exception) {
  480. var message = exception && exception.message;
  481. var loadingErrorMessage = void 0;
  482. if (exception instanceof _pdf.InvalidPDFException) {
  483. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  484. } else if (exception instanceof _pdf.MissingPDFException) {
  485. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  486. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  487. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  488. } else {
  489. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  490. }
  491. return loadingErrorMessage.then(function (msg) {
  492. _this3.error(msg, { message: message });
  493. throw new Error(msg);
  494. });
  495. });
  496. },
  497. download: function download() {
  498. var _this4 = this;
  499. function downloadByUrl() {
  500. downloadManager.downloadUrl(url, filename);
  501. }
  502. var url = this.baseUrl;
  503. var filename = (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  504. var downloadManager = this.downloadManager;
  505. downloadManager.onerror = function (err) {
  506. _this4.error('PDF failed to download: ' + err);
  507. };
  508. if (!this.pdfDocument || !this.downloadComplete) {
  509. downloadByUrl();
  510. return;
  511. }
  512. this.pdfDocument.getData().then(function (data) {
  513. var blob = (0, _pdf.createBlob)(data, 'application/pdf');
  514. downloadManager.download(blob, url, filename);
  515. }).catch(downloadByUrl);
  516. },
  517. fallback: function fallback(featureId) {},
  518. error: function error(message, moreInfo) {
  519. var moreInfoText = [this.l10n.get('error_version_info', {
  520. version: _pdf.version || '?',
  521. build: _pdf.build || '?'
  522. }, 'PDF.js v{{version}} (build: {{build}})')];
  523. if (moreInfo) {
  524. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  525. if (moreInfo.stack) {
  526. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  527. } else {
  528. if (moreInfo.filename) {
  529. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  530. }
  531. if (moreInfo.lineNumber) {
  532. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  533. }
  534. }
  535. }
  536. var errorWrapperConfig = this.appConfig.errorWrapper;
  537. var errorWrapper = errorWrapperConfig.container;
  538. errorWrapper.removeAttribute('hidden');
  539. var errorMessage = errorWrapperConfig.errorMessage;
  540. errorMessage.textContent = message;
  541. var closeButton = errorWrapperConfig.closeButton;
  542. closeButton.onclick = function () {
  543. errorWrapper.setAttribute('hidden', 'true');
  544. };
  545. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  546. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  547. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  548. moreInfoButton.onclick = function () {
  549. errorMoreInfo.removeAttribute('hidden');
  550. moreInfoButton.setAttribute('hidden', 'true');
  551. lessInfoButton.removeAttribute('hidden');
  552. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  553. };
  554. lessInfoButton.onclick = function () {
  555. errorMoreInfo.setAttribute('hidden', 'true');
  556. moreInfoButton.removeAttribute('hidden');
  557. lessInfoButton.setAttribute('hidden', 'true');
  558. };
  559. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  560. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  561. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  562. moreInfoButton.removeAttribute('hidden');
  563. lessInfoButton.setAttribute('hidden', 'true');
  564. Promise.all(moreInfoText).then(function (parts) {
  565. errorMoreInfo.value = parts.join('\n');
  566. });
  567. },
  568. progress: function progress(level) {
  569. var _this5 = this;
  570. if (this.downloadComplete) {
  571. return;
  572. }
  573. var percent = Math.round(level * 100);
  574. if (percent > this.loadingBar.percent || isNaN(percent)) {
  575. this.loadingBar.percent = percent;
  576. if (_pdf.PDFJS.disableAutoFetch && percent) {
  577. if (this.disableAutoFetchLoadingBarTimeout) {
  578. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  579. this.disableAutoFetchLoadingBarTimeout = null;
  580. }
  581. this.loadingBar.show();
  582. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  583. _this5.loadingBar.hide();
  584. _this5.disableAutoFetchLoadingBarTimeout = null;
  585. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  586. }
  587. }
  588. },
  589. load: function load(pdfDocument) {
  590. var _this6 = this;
  591. this.pdfDocument = pdfDocument;
  592. pdfDocument.getDownloadInfo().then(function () {
  593. _this6.downloadComplete = true;
  594. _this6.loadingBar.hide();
  595. firstPagePromise.then(function () {
  596. _this6.eventBus.dispatch('documentload', { source: _this6 });
  597. });
  598. });
  599. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  600. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  601. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  602. var id = this.documentFingerprint = pdfDocument.fingerprint;
  603. var store = this.store = new _view_history.ViewHistory(id);
  604. var baseDocumentUrl = void 0;
  605. baseDocumentUrl = null;
  606. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  607. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  608. var pdfViewer = this.pdfViewer;
  609. pdfViewer.setDocument(pdfDocument);
  610. var firstPagePromise = pdfViewer.firstPagePromise;
  611. var pagesPromise = pdfViewer.pagesPromise;
  612. var onePageRendered = pdfViewer.onePageRendered;
  613. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  614. pdfThumbnailViewer.setDocument(pdfDocument);
  615. firstPagePromise.then(function (pdfPage) {
  616. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  617. if (!_pdf.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  618. if (!_this6.viewerPrefs['showPreviousViewOnLoad']) {
  619. _this6.pdfHistory.clearHistoryState();
  620. }
  621. _this6.pdfHistory.initialize(_this6.documentFingerprint);
  622. if (_this6.pdfHistory.initialDestination) {
  623. _this6.initialDestination = _this6.pdfHistory.initialDestination;
  624. } else if (_this6.pdfHistory.initialBookmark) {
  625. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  626. }
  627. }
  628. var initialParams = {
  629. destination: _this6.initialDestination,
  630. bookmark: _this6.initialBookmark,
  631. hash: null
  632. };
  633. var storePromise = store.getMultiple({
  634. exists: false,
  635. page: '1',
  636. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  637. scrollLeft: '0',
  638. scrollTop: '0',
  639. sidebarView: _pdf_sidebar.SidebarView.NONE
  640. }).catch(function () {});
  641. Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
  642. var _ref3 = _slicedToArray(_ref2, 2),
  643. _ref3$ = _ref3[0],
  644. values = _ref3$ === undefined ? {} : _ref3$,
  645. pageMode = _ref3[1];
  646. var hash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  647. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  648. if (values.exists && _this6.viewerPrefs['showPreviousViewOnLoad']) {
  649. hash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  650. sidebarView = sidebarView || values.sidebarView | 0;
  651. }
  652. if (pageMode && !_this6.viewerPrefs['disablePageMode']) {
  653. sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
  654. }
  655. return {
  656. hash: hash,
  657. sidebarView: sidebarView
  658. };
  659. }).then(function (_ref4) {
  660. var hash = _ref4.hash,
  661. sidebarView = _ref4.sidebarView;
  662. _this6.setInitialView(hash, { sidebarView: sidebarView });
  663. initialParams.hash = hash;
  664. if (!_this6.isViewerEmbedded) {
  665. pdfViewer.focus();
  666. }
  667. return pagesPromise;
  668. }).then(function () {
  669. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  670. return;
  671. }
  672. if (pdfViewer.hasEqualPageSizes) {
  673. return;
  674. }
  675. _this6.initialDestination = initialParams.destination;
  676. _this6.initialBookmark = initialParams.bookmark;
  677. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  678. _this6.setInitialView(initialParams.hash);
  679. }).then(function () {
  680. pdfViewer.update();
  681. });
  682. });
  683. pdfDocument.getPageLabels().then(function (labels) {
  684. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  685. return;
  686. }
  687. var i = 0,
  688. numLabels = labels.length;
  689. if (numLabels !== _this6.pagesCount) {
  690. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  691. return;
  692. }
  693. while (i < numLabels && labels[i] === (i + 1).toString()) {
  694. i++;
  695. }
  696. if (i === numLabels) {
  697. return;
  698. }
  699. pdfViewer.setPageLabels(labels);
  700. pdfThumbnailViewer.setPageLabels(labels);
  701. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  702. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  703. });
  704. pagesPromise.then(function () {
  705. if (!_this6.supportsPrinting) {
  706. return;
  707. }
  708. pdfDocument.getJavaScript().then(function (javaScript) {
  709. if (javaScript.length) {
  710. console.warn('Warning: JavaScript is not supported');
  711. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  712. }
  713. var regex = /\bprint\s*\(/;
  714. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  715. var js = javaScript[i];
  716. if (js && regex.test(js)) {
  717. setTimeout(function () {
  718. window.print();
  719. });
  720. return;
  721. }
  722. }
  723. });
  724. });
  725. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  726. pdfDocument.getOutline().then(function (outline) {
  727. _this6.pdfOutlineViewer.render({ outline: outline });
  728. });
  729. pdfDocument.getAttachments().then(function (attachments) {
  730. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  731. });
  732. });
  733. pdfDocument.getMetadata().then(function (_ref5) {
  734. var info = _ref5.info,
  735. metadata = _ref5.metadata;
  736. _this6.documentInfo = info;
  737. _this6.metadata = metadata;
  738. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (!_pdf.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  739. var pdfTitle = void 0;
  740. if (metadata && metadata.has('dc:title')) {
  741. var title = metadata.get('dc:title');
  742. if (title !== 'Untitled') {
  743. pdfTitle = title;
  744. }
  745. }
  746. if (!pdfTitle && info && info['Title']) {
  747. pdfTitle = info['Title'];
  748. }
  749. if (pdfTitle) {
  750. _this6.setTitle(pdfTitle + ' - ' + document.title);
  751. }
  752. if (info.IsAcroFormPresent) {
  753. console.warn('Warning: AcroForm/XFA is not supported');
  754. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  755. }
  756. });
  757. },
  758. setInitialView: function setInitialView(storedHash) {
  759. var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  760. sidebarView = _ref6.sidebarView;
  761. this.isInitialViewSet = true;
  762. this.pdfSidebar.setInitialView(sidebarView);
  763. if (this.initialDestination) {
  764. this.pdfLinkService.navigateTo(this.initialDestination);
  765. this.initialDestination = null;
  766. } else if (this.initialBookmark) {
  767. this.pdfLinkService.setHash(this.initialBookmark);
  768. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  769. this.initialBookmark = null;
  770. } else if (storedHash) {
  771. this.pdfLinkService.setHash(storedHash);
  772. }
  773. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  774. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  775. if (!this.pdfViewer.currentScaleValue) {
  776. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  777. }
  778. },
  779. cleanup: function cleanup() {
  780. if (!this.pdfDocument) {
  781. return;
  782. }
  783. this.pdfViewer.cleanup();
  784. this.pdfThumbnailViewer.cleanup();
  785. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  786. this.pdfDocument.cleanup();
  787. }
  788. },
  789. forceRendering: function forceRendering() {
  790. this.pdfRenderingQueue.printing = this.printing;
  791. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  792. this.pdfRenderingQueue.renderHighestPriority();
  793. },
  794. beforePrint: function beforePrint() {
  795. var _this7 = this;
  796. if (this.printService) {
  797. return;
  798. }
  799. if (!this.supportsPrinting) {
  800. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  801. _this7.error(printMessage);
  802. });
  803. return;
  804. }
  805. if (!this.pdfViewer.pageViewsReady) {
  806. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  807. window.alert(notReadyMessage);
  808. });
  809. return;
  810. }
  811. var pagesOverview = this.pdfViewer.getPagesOverview();
  812. var printContainer = this.appConfig.printContainer;
  813. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  814. this.printService = printService;
  815. this.forceRendering();
  816. printService.layout();
  817. },
  818. afterPrint: function pdfViewSetupAfterPrint() {
  819. if (this.printService) {
  820. this.printService.destroy();
  821. this.printService = null;
  822. }
  823. this.forceRendering();
  824. },
  825. rotatePages: function rotatePages(delta) {
  826. if (!this.pdfDocument) {
  827. return;
  828. }
  829. var pdfViewer = this.pdfViewer,
  830. pdfThumbnailViewer = this.pdfThumbnailViewer;
  831. var pageNumber = pdfViewer.currentPageNumber;
  832. var newRotation = (pdfViewer.pagesRotation + 360 + delta) % 360;
  833. pdfViewer.pagesRotation = newRotation;
  834. pdfThumbnailViewer.pagesRotation = newRotation;
  835. this.forceRendering();
  836. pdfViewer.currentPageNumber = pageNumber;
  837. },
  838. requestPresentationMode: function requestPresentationMode() {
  839. if (!this.pdfPresentationMode) {
  840. return;
  841. }
  842. this.pdfPresentationMode.request();
  843. },
  844. bindEvents: function bindEvents() {
  845. var eventBus = this.eventBus,
  846. _boundEvents = this._boundEvents;
  847. _boundEvents.beforePrint = this.beforePrint.bind(this);
  848. _boundEvents.afterPrint = this.afterPrint.bind(this);
  849. eventBus.on('resize', webViewerResize);
  850. eventBus.on('hashchange', webViewerHashchange);
  851. eventBus.on('beforeprint', _boundEvents.beforePrint);
  852. eventBus.on('afterprint', _boundEvents.afterPrint);
  853. eventBus.on('pagerendered', webViewerPageRendered);
  854. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  855. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  856. eventBus.on('pagechanging', webViewerPageChanging);
  857. eventBus.on('scalechanging', webViewerScaleChanging);
  858. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  859. eventBus.on('pagemode', webViewerPageMode);
  860. eventBus.on('namedaction', webViewerNamedAction);
  861. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  862. eventBus.on('presentationmode', webViewerPresentationMode);
  863. eventBus.on('openfile', webViewerOpenFile);
  864. eventBus.on('print', webViewerPrint);
  865. eventBus.on('download', webViewerDownload);
  866. eventBus.on('firstpage', webViewerFirstPage);
  867. eventBus.on('lastpage', webViewerLastPage);
  868. eventBus.on('nextpage', webViewerNextPage);
  869. eventBus.on('previouspage', webViewerPreviousPage);
  870. eventBus.on('zoomin', webViewerZoomIn);
  871. eventBus.on('zoomout', webViewerZoomOut);
  872. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  873. eventBus.on('scalechanged', webViewerScaleChanged);
  874. eventBus.on('rotatecw', webViewerRotateCw);
  875. eventBus.on('rotateccw', webViewerRotateCcw);
  876. eventBus.on('documentproperties', webViewerDocumentProperties);
  877. eventBus.on('find', webViewerFind);
  878. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  879. eventBus.on('fileinputchange', webViewerFileInputChange);
  880. },
  881. bindWindowEvents: function bindWindowEvents() {
  882. var eventBus = this.eventBus,
  883. _boundEvents = this._boundEvents;
  884. _boundEvents.windowResize = function () {
  885. eventBus.dispatch('resize');
  886. };
  887. _boundEvents.windowHashChange = function () {
  888. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  889. };
  890. _boundEvents.windowBeforePrint = function () {
  891. eventBus.dispatch('beforeprint');
  892. };
  893. _boundEvents.windowAfterPrint = function () {
  894. eventBus.dispatch('afterprint');
  895. };
  896. window.addEventListener('wheel', webViewerWheel);
  897. window.addEventListener('click', webViewerClick);
  898. window.addEventListener('keydown', webViewerKeyDown);
  899. window.addEventListener('resize', _boundEvents.windowResize);
  900. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  901. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  902. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  903. _boundEvents.windowChange = function (evt) {
  904. var files = evt.target.files;
  905. if (!files || files.length === 0) {
  906. return;
  907. }
  908. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  909. };
  910. window.addEventListener('change', _boundEvents.windowChange);
  911. },
  912. unbindEvents: function unbindEvents() {
  913. var eventBus = this.eventBus,
  914. _boundEvents = this._boundEvents;
  915. eventBus.off('resize', webViewerResize);
  916. eventBus.off('hashchange', webViewerHashchange);
  917. eventBus.off('beforeprint', _boundEvents.beforePrint);
  918. eventBus.off('afterprint', _boundEvents.afterPrint);
  919. eventBus.off('pagerendered', webViewerPageRendered);
  920. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  921. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  922. eventBus.off('pagechanging', webViewerPageChanging);
  923. eventBus.off('scalechanging', webViewerScaleChanging);
  924. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  925. eventBus.off('pagemode', webViewerPageMode);
  926. eventBus.off('namedaction', webViewerNamedAction);
  927. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  928. eventBus.off('presentationmode', webViewerPresentationMode);
  929. eventBus.off('openfile', webViewerOpenFile);
  930. eventBus.off('print', webViewerPrint);
  931. eventBus.off('download', webViewerDownload);
  932. eventBus.off('firstpage', webViewerFirstPage);
  933. eventBus.off('lastpage', webViewerLastPage);
  934. eventBus.off('nextpage', webViewerNextPage);
  935. eventBus.off('previouspage', webViewerPreviousPage);
  936. eventBus.off('zoomin', webViewerZoomIn);
  937. eventBus.off('zoomout', webViewerZoomOut);
  938. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  939. eventBus.off('scalechanged', webViewerScaleChanged);
  940. eventBus.off('rotatecw', webViewerRotateCw);
  941. eventBus.off('rotateccw', webViewerRotateCcw);
  942. eventBus.off('documentproperties', webViewerDocumentProperties);
  943. eventBus.off('find', webViewerFind);
  944. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  945. eventBus.off('fileinputchange', webViewerFileInputChange);
  946. _boundEvents.beforePrint = null;
  947. _boundEvents.afterPrint = null;
  948. },
  949. unbindWindowEvents: function unbindWindowEvents() {
  950. var _boundEvents = this._boundEvents;
  951. window.removeEventListener('wheel', webViewerWheel);
  952. window.removeEventListener('click', webViewerClick);
  953. window.removeEventListener('keydown', webViewerKeyDown);
  954. window.removeEventListener('resize', _boundEvents.windowResize);
  955. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  956. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  957. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  958. window.removeEventListener('change', _boundEvents.windowChange);
  959. _boundEvents.windowChange = null;
  960. _boundEvents.windowResize = null;
  961. _boundEvents.windowHashChange = null;
  962. _boundEvents.windowBeforePrint = null;
  963. _boundEvents.windowAfterPrint = null;
  964. }
  965. };
  966. var validateFileURL = void 0;
  967. {
  968. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  969. validateFileURL = function validateFileURL(file) {
  970. if (file === undefined) {
  971. return;
  972. }
  973. try {
  974. var viewerOrigin = new URL(window.location.href).origin || 'null';
  975. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  976. return;
  977. }
  978. var fileOrigin = new URL(file, window.location.href).origin;
  979. if (fileOrigin !== viewerOrigin) {
  980. throw new Error('file origin does not match viewer\'s');
  981. }
  982. } catch (ex) {
  983. var message = ex && ex.message;
  984. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  985. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  986. });
  987. throw ex;
  988. }
  989. };
  990. }
  991. function loadAndEnablePDFBug(enabledTabs) {
  992. return new Promise(function (resolve, reject) {
  993. var appConfig = PDFViewerApplication.appConfig;
  994. var script = document.createElement('script');
  995. script.src = appConfig.debuggerScriptPath;
  996. script.onload = function () {
  997. PDFBug.enable(enabledTabs);
  998. PDFBug.init({
  999. PDFJS: _pdf.PDFJS,
  1000. OPS: _pdf.OPS
  1001. }, appConfig.mainContainer);
  1002. resolve();
  1003. };
  1004. script.onerror = function () {
  1005. reject(new Error('Cannot load debugger at ' + script.src));
  1006. };
  1007. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1008. });
  1009. }
  1010. function webViewerInitialized() {
  1011. var appConfig = PDFViewerApplication.appConfig;
  1012. var file = void 0;
  1013. var queryString = document.location.search.substring(1);
  1014. var params = (0, _ui_utils.parseQueryString)(queryString);
  1015. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1016. validateFileURL(file);
  1017. var waitForBeforeOpening = [];
  1018. var fileInput = document.createElement('input');
  1019. fileInput.id = appConfig.openFileInputName;
  1020. fileInput.className = 'fileInput';
  1021. fileInput.setAttribute('type', 'file');
  1022. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1023. document.body.appendChild(fileInput);
  1024. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1025. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1026. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1027. } else {
  1028. fileInput.value = null;
  1029. }
  1030. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  1031. var hash = document.location.hash.substring(1);
  1032. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  1033. if ('disableworker' in hashParams) {
  1034. _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  1035. }
  1036. if ('disablerange' in hashParams) {
  1037. _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  1038. }
  1039. if ('disablestream' in hashParams) {
  1040. _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  1041. }
  1042. if ('disableautofetch' in hashParams) {
  1043. _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  1044. }
  1045. if ('disablefontface' in hashParams) {
  1046. _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  1047. }
  1048. if ('disablehistory' in hashParams) {
  1049. _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  1050. }
  1051. if ('webgl' in hashParams) {
  1052. _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  1053. }
  1054. if ('useonlycsszoom' in hashParams) {
  1055. _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  1056. }
  1057. if ('verbosity' in hashParams) {
  1058. _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
  1059. }
  1060. if ('ignorecurrentpositiononzoom' in hashParams) {
  1061. _pdf.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  1062. }
  1063. if ('textlayer' in hashParams) {
  1064. switch (hashParams['textlayer']) {
  1065. case 'off':
  1066. _pdf.PDFJS.disableTextLayer = true;
  1067. break;
  1068. case 'visible':
  1069. case 'shadow':
  1070. case 'hover':
  1071. var viewer = appConfig.viewerContainer;
  1072. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  1073. break;
  1074. }
  1075. }
  1076. if ('pdfbug' in hashParams) {
  1077. _pdf.PDFJS.pdfBug = true;
  1078. var pdfBug = hashParams['pdfbug'];
  1079. var enabled = pdfBug.split(',');
  1080. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  1081. }
  1082. }
  1083. if (!PDFViewerApplication.supportsPrinting) {
  1084. appConfig.toolbar.print.classList.add('hidden');
  1085. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1086. }
  1087. if (!PDFViewerApplication.supportsFullscreen) {
  1088. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1089. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1090. }
  1091. if (PDFViewerApplication.supportsIntegratedFind) {
  1092. appConfig.toolbar.viewFind.classList.add('hidden');
  1093. }
  1094. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (evt) {
  1095. if (evt.target === this) {
  1096. PDFViewerApplication.eventBus.dispatch('resize');
  1097. }
  1098. }, true);
  1099. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1100. PDFViewerApplication.pdfSidebar.toggle();
  1101. });
  1102. Promise.all(waitForBeforeOpening).then(function () {
  1103. webViewerOpenFileViaURL(file);
  1104. }).catch(function (reason) {
  1105. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
  1106. PDFViewerApplication.error(msg, reason);
  1107. });
  1108. });
  1109. }
  1110. var webViewerOpenFileViaURL = void 0;
  1111. {
  1112. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1113. if (file && file.lastIndexOf('file:', 0) === 0) {
  1114. PDFViewerApplication.setTitleUsingUrl(file);
  1115. var xhr = new XMLHttpRequest();
  1116. xhr.onload = function () {
  1117. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1118. };
  1119. try {
  1120. xhr.open('GET', file);
  1121. xhr.responseType = 'arraybuffer';
  1122. xhr.send();
  1123. } catch (ex) {
  1124. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1125. PDFViewerApplication.error(msg, ex);
  1126. });
  1127. }
  1128. return;
  1129. }
  1130. if (file) {
  1131. PDFViewerApplication.open(file);
  1132. }
  1133. };
  1134. }
  1135. function webViewerPageRendered(evt) {
  1136. var pageNumber = evt.pageNumber;
  1137. var pageIndex = pageNumber - 1;
  1138. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1139. if (pageNumber === PDFViewerApplication.page) {
  1140. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1141. }
  1142. if (!pageView) {
  1143. return;
  1144. }
  1145. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1146. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1147. thumbnailView.setImage(pageView);
  1148. }
  1149. if (_pdf.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1150. Stats.add(pageNumber, pageView.stats);
  1151. }
  1152. if (pageView.error) {
  1153. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1154. PDFViewerApplication.error(msg, pageView.error);
  1155. });
  1156. }
  1157. }
  1158. function webViewerTextLayerRendered(evt) {}
  1159. function webViewerPageMode(evt) {
  1160. var mode = evt.mode,
  1161. view = void 0;
  1162. switch (mode) {
  1163. case 'thumbs':
  1164. view = _pdf_sidebar.SidebarView.THUMBS;
  1165. break;
  1166. case 'bookmarks':
  1167. case 'outline':
  1168. view = _pdf_sidebar.SidebarView.OUTLINE;
  1169. break;
  1170. case 'attachments':
  1171. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1172. break;
  1173. case 'none':
  1174. view = _pdf_sidebar.SidebarView.NONE;
  1175. break;
  1176. default:
  1177. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1178. return;
  1179. }
  1180. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1181. }
  1182. function webViewerNamedAction(evt) {
  1183. var action = evt.action;
  1184. switch (action) {
  1185. case 'GoToPage':
  1186. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1187. break;
  1188. case 'Find':
  1189. if (!PDFViewerApplication.supportsIntegratedFind) {
  1190. PDFViewerApplication.findBar.toggle();
  1191. }
  1192. break;
  1193. }
  1194. }
  1195. function webViewerPresentationModeChanged(evt) {
  1196. var active = evt.active,
  1197. switchInProgress = evt.switchInProgress;
  1198. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _pdf_viewer.PresentationModeState.CHANGING : active ? _pdf_viewer.PresentationModeState.FULLSCREEN : _pdf_viewer.PresentationModeState.NORMAL;
  1199. }
  1200. function webViewerSidebarViewChanged(evt) {
  1201. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1202. var store = PDFViewerApplication.store;
  1203. if (store && PDFViewerApplication.isInitialViewSet) {
  1204. store.set('sidebarView', evt.view).catch(function () {});
  1205. }
  1206. }
  1207. function webViewerUpdateViewarea(evt) {
  1208. var location = evt.location,
  1209. store = PDFViewerApplication.store;
  1210. if (store && PDFViewerApplication.isInitialViewSet) {
  1211. store.setMultiple({
  1212. 'exists': true,
  1213. 'page': location.pageNumber,
  1214. 'zoom': location.scale,
  1215. 'scrollLeft': location.left,
  1216. 'scrollTop': location.top
  1217. }).catch(function () {});
  1218. }
  1219. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1220. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1221. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1222. PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  1223. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1224. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1225. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1226. }
  1227. function webViewerResize() {
  1228. var pdfDocument = PDFViewerApplication.pdfDocument,
  1229. pdfViewer = PDFViewerApplication.pdfViewer;
  1230. if (!pdfDocument) {
  1231. return;
  1232. }
  1233. var currentScaleValue = pdfViewer.currentScaleValue;
  1234. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1235. pdfViewer.currentScaleValue = currentScaleValue;
  1236. }
  1237. 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. function apiPageModeToSidebarView(mode) {
  1639. switch (mode) {
  1640. case 'UseNone':
  1641. return _pdf_sidebar.SidebarView.NONE;
  1642. case 'UseThumbs':
  1643. return _pdf_sidebar.SidebarView.THUMBS;
  1644. case 'UseOutlines':
  1645. return _pdf_sidebar.SidebarView.OUTLINE;
  1646. case 'UseAttachments':
  1647. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  1648. case 'UseOC':
  1649. }
  1650. return _pdf_sidebar.SidebarView.NONE;
  1651. }
  1652. var PDFPrintServiceFactory = {
  1653. instance: {
  1654. supportsPrinting: false,
  1655. createPrintService: function createPrintService() {
  1656. throw new Error('Not implemented: createPrintService');
  1657. }
  1658. }
  1659. };
  1660. exports.PDFViewerApplication = PDFViewerApplication;
  1661. exports.DefaultExternalServices = DefaultExternalServices;
  1662. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;