UNPKG

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