pdf_viewer.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.PDFViewer = undefined;
  20. 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; }; }();
  21. var _ui_utils = require('./ui_utils');
  22. var _base_viewer = require('./base_viewer');
  23. var _pdf = require('../pdf');
  24. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25. 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; }
  26. 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; }
  27. var PDFViewer = function (_BaseViewer) {
  28. _inherits(PDFViewer, _BaseViewer);
  29. function PDFViewer() {
  30. _classCallCheck(this, PDFViewer);
  31. return _possibleConstructorReturn(this, (PDFViewer.__proto__ || Object.getPrototypeOf(PDFViewer)).apply(this, arguments));
  32. }
  33. _createClass(PDFViewer, [{
  34. key: '_scrollIntoView',
  35. value: function _scrollIntoView(_ref) {
  36. var pageDiv = _ref.pageDiv,
  37. _ref$pageSpot = _ref.pageSpot,
  38. pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot;
  39. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  40. }
  41. }, {
  42. key: '_getVisiblePages',
  43. value: function _getVisiblePages() {
  44. if (!this.isInPresentationMode) {
  45. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
  46. }
  47. var currentPage = this._pages[this._currentPageNumber - 1];
  48. var visible = [{
  49. id: currentPage.id,
  50. view: currentPage
  51. }];
  52. return {
  53. first: currentPage,
  54. last: currentPage,
  55. views: visible
  56. };
  57. }
  58. }, {
  59. key: 'update',
  60. value: function update() {
  61. var visible = this._getVisiblePages();
  62. var visiblePages = visible.views,
  63. numVisiblePages = visiblePages.length;
  64. if (numVisiblePages === 0) {
  65. return;
  66. }
  67. this._resizeBuffer(numVisiblePages);
  68. this.renderingQueue.renderHighestPriority(visible);
  69. var currentId = this._currentPageNumber;
  70. var stillFullyVisible = false;
  71. for (var i = 0; i < numVisiblePages; ++i) {
  72. var page = visiblePages[i];
  73. if (page.percent < 100) {
  74. break;
  75. }
  76. if (page.id === currentId) {
  77. stillFullyVisible = true;
  78. break;
  79. }
  80. }
  81. if (!stillFullyVisible) {
  82. currentId = visiblePages[0].id;
  83. }
  84. if (!this.isInPresentationMode) {
  85. this._setCurrentPageNumber(currentId);
  86. }
  87. this._updateLocation(visible.first);
  88. this.eventBus.dispatch('updateviewarea', {
  89. source: this,
  90. location: this._location
  91. });
  92. }
  93. }, {
  94. key: '_setDocumentViewerElement',
  95. get: function get() {
  96. return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this.viewer);
  97. }
  98. }]);
  99. return PDFViewer;
  100. }(_base_viewer.BaseViewer);
  101. exports.PDFViewer = PDFViewer;