app.js 63 KB

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