pdf_viewer.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.PDFViewer = undefined;
  27. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  28. var _ui_utils = require('./ui_utils');
  29. var _base_viewer = require('./base_viewer');
  30. var _pdf = require('../pdf');
  31. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  32. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  33. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  34. var PDFViewer = function (_BaseViewer) {
  35. _inherits(PDFViewer, _BaseViewer);
  36. function PDFViewer() {
  37. _classCallCheck(this, PDFViewer);
  38. return _possibleConstructorReturn(this, (PDFViewer.__proto__ || Object.getPrototypeOf(PDFViewer)).apply(this, arguments));
  39. }
  40. _createClass(PDFViewer, [{
  41. key: '_scrollIntoView',
  42. value: function _scrollIntoView(_ref) {
  43. var pageDiv = _ref.pageDiv,
  44. _ref$pageSpot = _ref.pageSpot,
  45. pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot;
  46. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  47. }
  48. }, {
  49. key: '_getVisiblePages',
  50. value: function _getVisiblePages() {
  51. if (!this.isInPresentationMode) {
  52. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
  53. }
  54. var currentPage = this._pages[this._currentPageNumber - 1];
  55. var visible = [{
  56. id: currentPage.id,
  57. view: currentPage
  58. }];
  59. return {
  60. first: currentPage,
  61. last: currentPage,
  62. views: visible
  63. };
  64. }
  65. }, {
  66. key: 'update',
  67. value: function update() {
  68. var visible = this._getVisiblePages();
  69. var visiblePages = visible.views,
  70. numVisiblePages = visiblePages.length;
  71. if (numVisiblePages === 0) {
  72. return;
  73. }
  74. this._resizeBuffer(numVisiblePages);
  75. this.renderingQueue.renderHighestPriority(visible);
  76. var currentId = this._currentPageNumber;
  77. var stillFullyVisible = false;
  78. for (var i = 0; i < numVisiblePages; ++i) {
  79. var page = visiblePages[i];
  80. if (page.percent < 100) {
  81. break;
  82. }
  83. if (page.id === currentId) {
  84. stillFullyVisible = true;
  85. break;
  86. }
  87. }
  88. if (!stillFullyVisible) {
  89. currentId = visiblePages[0].id;
  90. }
  91. if (!this.isInPresentationMode) {
  92. this._setCurrentPageNumber(currentId);
  93. }
  94. this._updateLocation(visible.first);
  95. this.eventBus.dispatch('updateviewarea', {
  96. source: this,
  97. location: this._location
  98. });
  99. }
  100. }, {
  101. key: '_setDocumentViewerElement',
  102. get: function get() {
  103. return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this.viewer);
  104. }
  105. }]);
  106. return PDFViewer;
  107. }(_base_viewer.BaseViewer);
  108. exports.PDFViewer = PDFViewer;