1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PDFSinglePageViewer = undefined;
|
28 |
|
29 | 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; }; }();
|
30 |
|
31 | var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
32 |
|
33 | var _base_viewer = require('./base_viewer');
|
34 |
|
35 | var _ui_utils = require('./ui_utils');
|
36 |
|
37 | var _pdf = require('../pdf');
|
38 |
|
39 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
40 |
|
41 | 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; }
|
42 |
|
43 | 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; }
|
44 |
|
45 | var PDFSinglePageViewer = function (_BaseViewer) {
|
46 | _inherits(PDFSinglePageViewer, _BaseViewer);
|
47 |
|
48 | function PDFSinglePageViewer(options) {
|
49 | _classCallCheck(this, PDFSinglePageViewer);
|
50 |
|
51 | var _this = _possibleConstructorReturn(this, (PDFSinglePageViewer.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer)).call(this, options));
|
52 |
|
53 | _this.eventBus.on('pagesinit', function (evt) {
|
54 | _this._ensurePageViewVisible();
|
55 | });
|
56 | return _this;
|
57 | }
|
58 |
|
59 | _createClass(PDFSinglePageViewer, [{
|
60 | key: '_resetView',
|
61 | value: function _resetView() {
|
62 | _get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_resetView', this).call(this);
|
63 | this._previousPageNumber = 1;
|
64 | this._shadowViewer = document.createDocumentFragment();
|
65 | }
|
66 | }, {
|
67 | key: '_ensurePageViewVisible',
|
68 | value: function _ensurePageViewVisible() {
|
69 | var pageView = this._pages[this._currentPageNumber - 1];
|
70 | var previousPageView = this._pages[this._previousPageNumber - 1];
|
71 | var viewerNodes = this.viewer.childNodes;
|
72 | switch (viewerNodes.length) {
|
73 | case 0:
|
74 | this.viewer.appendChild(pageView.div);
|
75 | break;
|
76 | case 1:
|
77 | if (viewerNodes[0] !== previousPageView.div) {
|
78 | throw new Error('_ensurePageViewVisible: Unexpected previously visible page.');
|
79 | }
|
80 | if (pageView === previousPageView) {
|
81 | break;
|
82 | }
|
83 | this._shadowViewer.appendChild(previousPageView.div);
|
84 | this.viewer.appendChild(pageView.div);
|
85 | this.container.scrollTop = 0;
|
86 | break;
|
87 | default:
|
88 | throw new Error('_ensurePageViewVisible: Only one page should be visible at a time.');
|
89 | }
|
90 | this._previousPageNumber = this._currentPageNumber;
|
91 | }
|
92 | }, {
|
93 | key: '_scrollUpdate',
|
94 | value: function _scrollUpdate() {
|
95 | if (this._updateScrollDown) {
|
96 | this._updateScrollDown();
|
97 | }
|
98 | _get(PDFSinglePageViewer.prototype.__proto__ || Object.getPrototypeOf(PDFSinglePageViewer.prototype), '_scrollUpdate', this).call(this);
|
99 | }
|
100 | }, {
|
101 | key: '_scrollIntoView',
|
102 | value: function _scrollIntoView(_ref) {
|
103 | var _this2 = this;
|
104 |
|
105 | var pageDiv = _ref.pageDiv,
|
106 | _ref$pageSpot = _ref.pageSpot,
|
107 | pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot,
|
108 | _ref$pageNumber = _ref.pageNumber,
|
109 | pageNumber = _ref$pageNumber === undefined ? null : _ref$pageNumber;
|
110 |
|
111 | if (pageNumber) {
|
112 | this._setCurrentPageNumber(pageNumber);
|
113 | }
|
114 | var scrolledDown = this._currentPageNumber >= this._previousPageNumber;
|
115 | var previousLocation = this._location;
|
116 | this._ensurePageViewVisible();
|
117 | (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
|
118 | this._updateScrollDown = function () {
|
119 | _this2.scroll.down = scrolledDown;
|
120 | delete _this2._updateScrollDown;
|
121 | };
|
122 | setTimeout(function () {
|
123 | if (_this2._location === previousLocation) {
|
124 | if (_this2._updateScrollDown) {
|
125 | _this2._updateScrollDown();
|
126 | }
|
127 | _this2.update();
|
128 | }
|
129 | }, 0);
|
130 | }
|
131 | }, {
|
132 | key: '_getVisiblePages',
|
133 | value: function _getVisiblePages() {
|
134 | if (!this.pagesCount) {
|
135 | return { views: [] };
|
136 | }
|
137 | var pageView = this._pages[this._currentPageNumber - 1];
|
138 | var element = pageView.div;
|
139 | var view = {
|
140 | id: pageView.id,
|
141 | x: element.offsetLeft + element.clientLeft,
|
142 | y: element.offsetTop + element.clientTop,
|
143 | view: pageView
|
144 | };
|
145 | return {
|
146 | first: view,
|
147 | last: view,
|
148 | views: [view]
|
149 | };
|
150 | }
|
151 | }, {
|
152 | key: 'update',
|
153 | value: function update() {
|
154 | var visible = this._getVisiblePages();
|
155 | var visiblePages = visible.views,
|
156 | numVisiblePages = visiblePages.length;
|
157 | if (numVisiblePages === 0) {
|
158 | return;
|
159 | }
|
160 | this._resizeBuffer(numVisiblePages);
|
161 | this.renderingQueue.renderHighestPriority(visible);
|
162 | this._updateLocation(visible.first);
|
163 | this.eventBus.dispatch('updateviewarea', {
|
164 | source: this,
|
165 | location: this._location
|
166 | });
|
167 | }
|
168 | }, {
|
169 | key: '_setDocumentViewerElement',
|
170 | get: function get() {
|
171 | return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this._shadowViewer);
|
172 | }
|
173 | }]);
|
174 |
|
175 | return PDFSinglePageViewer;
|
176 | }(_base_viewer.BaseViewer);
|
177 |
|
178 | exports.PDFSinglePageViewer = PDFSinglePageViewer; |
\ | No newline at end of file |