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.PDFSidebarResizer = void 0;
|
28 |
|
29 | var _ui_utils = require("./ui_utils");
|
30 |
|
31 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
32 |
|
33 | 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); } }
|
34 |
|
35 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
36 |
|
37 | var SIDEBAR_WIDTH_VAR = '--sidebar-width';
|
38 | var SIDEBAR_MIN_WIDTH = 200;
|
39 | var SIDEBAR_RESIZING_CLASS = 'sidebarResizing';
|
40 |
|
41 | var PDFSidebarResizer =
|
42 |
|
43 | function () {
|
44 | function PDFSidebarResizer(options, eventBus) {
|
45 | var _this = this;
|
46 |
|
47 | var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
|
48 |
|
49 | _classCallCheck(this, PDFSidebarResizer);
|
50 |
|
51 | this.enabled = false;
|
52 | this.isRTL = false;
|
53 | this.sidebarOpen = false;
|
54 | this.doc = document.documentElement;
|
55 | this._width = null;
|
56 | this._outerContainerWidth = null;
|
57 | this._boundEvents = Object.create(null);
|
58 | this.outerContainer = options.outerContainer;
|
59 | this.resizer = options.resizer;
|
60 | this.eventBus = eventBus;
|
61 | this.l10n = l10n;
|
62 |
|
63 | if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || !CSS.supports(SIDEBAR_WIDTH_VAR, "calc(-1 * ".concat(SIDEBAR_MIN_WIDTH, "px)"))) {
|
64 | console.warn('PDFSidebarResizer: ' + 'The browser does not support resizing of the sidebar.');
|
65 | return;
|
66 | }
|
67 |
|
68 | this.enabled = true;
|
69 | this.resizer.classList.remove('hidden');
|
70 | this.l10n.getDirection().then(function (dir) {
|
71 | _this.isRTL = dir === 'rtl';
|
72 | });
|
73 |
|
74 | this._addEventListeners();
|
75 | }
|
76 |
|
77 | _createClass(PDFSidebarResizer, [{
|
78 | key: "_updateWidth",
|
79 | value: function _updateWidth() {
|
80 | var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
81 |
|
82 | if (!this.enabled) {
|
83 | return false;
|
84 | }
|
85 |
|
86 | var maxWidth = Math.floor(this.outerContainerWidth / 2);
|
87 |
|
88 | if (width > maxWidth) {
|
89 | width = maxWidth;
|
90 | }
|
91 |
|
92 | if (width < SIDEBAR_MIN_WIDTH) {
|
93 | width = SIDEBAR_MIN_WIDTH;
|
94 | }
|
95 |
|
96 | if (width === this._width) {
|
97 | return false;
|
98 | }
|
99 |
|
100 | this._width = width;
|
101 | this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, "".concat(width, "px"));
|
102 | return true;
|
103 | }
|
104 | }, {
|
105 | key: "_mouseMove",
|
106 | value: function _mouseMove(evt) {
|
107 | var width = evt.clientX;
|
108 |
|
109 | if (this.isRTL) {
|
110 | width = this.outerContainerWidth - width;
|
111 | }
|
112 |
|
113 | this._updateWidth(width);
|
114 | }
|
115 | }, {
|
116 | key: "_mouseUp",
|
117 | value: function _mouseUp(evt) {
|
118 | this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
|
119 | this.eventBus.dispatch('resize', {
|
120 | source: this
|
121 | });
|
122 | var _boundEvents = this._boundEvents;
|
123 | window.removeEventListener('mousemove', _boundEvents.mouseMove);
|
124 | window.removeEventListener('mouseup', _boundEvents.mouseUp);
|
125 | }
|
126 | }, {
|
127 | key: "_addEventListeners",
|
128 | value: function _addEventListeners() {
|
129 | var _this2 = this;
|
130 |
|
131 | if (!this.enabled) {
|
132 | return;
|
133 | }
|
134 |
|
135 | var _boundEvents = this._boundEvents;
|
136 | _boundEvents.mouseMove = this._mouseMove.bind(this);
|
137 | _boundEvents.mouseUp = this._mouseUp.bind(this);
|
138 | this.resizer.addEventListener('mousedown', function (evt) {
|
139 | if (evt.button !== 0) {
|
140 | return;
|
141 | }
|
142 |
|
143 | _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
144 |
|
145 | window.addEventListener('mousemove', _boundEvents.mouseMove);
|
146 | window.addEventListener('mouseup', _boundEvents.mouseUp);
|
147 | });
|
148 | this.eventBus.on('sidebarviewchanged', function (evt) {
|
149 | _this2.sidebarOpen = !!(evt && evt.view);
|
150 | });
|
151 | this.eventBus.on('resize', function (evt) {
|
152 | if (evt && evt.source === window) {
|
153 | _this2._outerContainerWidth = null;
|
154 |
|
155 | if (_this2._width) {
|
156 | if (_this2.sidebarOpen) {
|
157 | _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
158 |
|
159 | var updated = _this2._updateWidth(_this2._width);
|
160 |
|
161 | Promise.resolve().then(function () {
|
162 | _this2.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
|
163 |
|
164 | if (updated) {
|
165 | _this2.eventBus.dispatch('resize', {
|
166 | source: _this2
|
167 | });
|
168 | }
|
169 | });
|
170 | } else {
|
171 | _this2._updateWidth(_this2._width);
|
172 | }
|
173 | }
|
174 | }
|
175 | });
|
176 | }
|
177 | }, {
|
178 | key: "outerContainerWidth",
|
179 | get: function get() {
|
180 | if (!this._outerContainerWidth) {
|
181 | this._outerContainerWidth = this.outerContainer.clientWidth;
|
182 | }
|
183 |
|
184 | return this._outerContainerWidth;
|
185 | }
|
186 | }]);
|
187 |
|
188 | return PDFSidebarResizer;
|
189 | }();
|
190 |
|
191 | exports.PDFSidebarResizer = PDFSidebarResizer; |
\ | No newline at end of file |