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.SecondaryToolbar = void 0;
|
28 |
|
29 | var _ui_utils = require("./ui_utils.js");
|
30 |
|
31 | var _pdf_cursor_tools = require("./pdf_cursor_tools.js");
|
32 |
|
33 | var _base_viewer = require("./base_viewer.js");
|
34 |
|
35 | class SecondaryToolbar {
|
36 | constructor(options, eventBus) {
|
37 | this.toolbar = options.toolbar;
|
38 | this.toggleButton = options.toggleButton;
|
39 | this.buttons = [{
|
40 | element: options.presentationModeButton,
|
41 | eventName: "presentationmode",
|
42 | close: true
|
43 | }, {
|
44 | element: options.printButton,
|
45 | eventName: "print",
|
46 | close: true
|
47 | }, {
|
48 | element: options.downloadButton,
|
49 | eventName: "download",
|
50 | close: true
|
51 | }, {
|
52 | element: options.viewBookmarkButton,
|
53 | eventName: null,
|
54 | close: true
|
55 | }, {
|
56 | element: options.firstPageButton,
|
57 | eventName: "firstpage",
|
58 | close: true
|
59 | }, {
|
60 | element: options.lastPageButton,
|
61 | eventName: "lastpage",
|
62 | close: true
|
63 | }, {
|
64 | element: options.pageRotateCwButton,
|
65 | eventName: "rotatecw",
|
66 | close: false
|
67 | }, {
|
68 | element: options.pageRotateCcwButton,
|
69 | eventName: "rotateccw",
|
70 | close: false
|
71 | }, {
|
72 | element: options.cursorSelectToolButton,
|
73 | eventName: "switchcursortool",
|
74 | eventDetails: {
|
75 | tool: _pdf_cursor_tools.CursorTool.SELECT
|
76 | },
|
77 | close: true
|
78 | }, {
|
79 | element: options.cursorHandToolButton,
|
80 | eventName: "switchcursortool",
|
81 | eventDetails: {
|
82 | tool: _pdf_cursor_tools.CursorTool.HAND
|
83 | },
|
84 | close: true
|
85 | }, {
|
86 | element: options.scrollPageButton,
|
87 | eventName: "switchscrollmode",
|
88 | eventDetails: {
|
89 | mode: _ui_utils.ScrollMode.PAGE
|
90 | },
|
91 | close: true
|
92 | }, {
|
93 | element: options.scrollVerticalButton,
|
94 | eventName: "switchscrollmode",
|
95 | eventDetails: {
|
96 | mode: _ui_utils.ScrollMode.VERTICAL
|
97 | },
|
98 | close: true
|
99 | }, {
|
100 | element: options.scrollHorizontalButton,
|
101 | eventName: "switchscrollmode",
|
102 | eventDetails: {
|
103 | mode: _ui_utils.ScrollMode.HORIZONTAL
|
104 | },
|
105 | close: true
|
106 | }, {
|
107 | element: options.scrollWrappedButton,
|
108 | eventName: "switchscrollmode",
|
109 | eventDetails: {
|
110 | mode: _ui_utils.ScrollMode.WRAPPED
|
111 | },
|
112 | close: true
|
113 | }, {
|
114 | element: options.spreadNoneButton,
|
115 | eventName: "switchspreadmode",
|
116 | eventDetails: {
|
117 | mode: _ui_utils.SpreadMode.NONE
|
118 | },
|
119 | close: true
|
120 | }, {
|
121 | element: options.spreadOddButton,
|
122 | eventName: "switchspreadmode",
|
123 | eventDetails: {
|
124 | mode: _ui_utils.SpreadMode.ODD
|
125 | },
|
126 | close: true
|
127 | }, {
|
128 | element: options.spreadEvenButton,
|
129 | eventName: "switchspreadmode",
|
130 | eventDetails: {
|
131 | mode: _ui_utils.SpreadMode.EVEN
|
132 | },
|
133 | close: true
|
134 | }, {
|
135 | element: options.documentPropertiesButton,
|
136 | eventName: "documentproperties",
|
137 | close: true
|
138 | }];
|
139 | this.buttons.push({
|
140 | element: options.openFileButton,
|
141 | eventName: "openfile",
|
142 | close: true
|
143 | });
|
144 | this.items = {
|
145 | firstPage: options.firstPageButton,
|
146 | lastPage: options.lastPageButton,
|
147 | pageRotateCw: options.pageRotateCwButton,
|
148 | pageRotateCcw: options.pageRotateCcwButton
|
149 | };
|
150 | this.eventBus = eventBus;
|
151 | this.opened = false;
|
152 | this.reset();
|
153 | this.#bindClickListeners();
|
154 | this.#bindCursorToolsListener(options);
|
155 | this.#bindScrollModeListener(options);
|
156 | this.#bindSpreadModeListener(options);
|
157 | }
|
158 |
|
159 | get isOpen() {
|
160 | return this.opened;
|
161 | }
|
162 |
|
163 | setPageNumber(pageNumber) {
|
164 | this.pageNumber = pageNumber;
|
165 | this.#updateUIState();
|
166 | }
|
167 |
|
168 | setPagesCount(pagesCount) {
|
169 | this.pagesCount = pagesCount;
|
170 | this.#updateUIState();
|
171 | }
|
172 |
|
173 | reset() {
|
174 | this.pageNumber = 0;
|
175 | this.pagesCount = 0;
|
176 | this.#updateUIState();
|
177 | this.eventBus.dispatch("secondarytoolbarreset", {
|
178 | source: this
|
179 | });
|
180 | }
|
181 |
|
182 | #updateUIState() {
|
183 | this.items.firstPage.disabled = this.pageNumber <= 1;
|
184 | this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
|
185 | this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
186 | this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
187 | }
|
188 |
|
189 | #bindClickListeners() {
|
190 | this.toggleButton.addEventListener("click", this.toggle.bind(this));
|
191 |
|
192 | for (const {
|
193 | element,
|
194 | eventName,
|
195 | close,
|
196 | eventDetails
|
197 | } of this.buttons) {
|
198 | element.addEventListener("click", evt => {
|
199 | if (eventName !== null) {
|
200 | const details = {
|
201 | source: this
|
202 | };
|
203 |
|
204 | for (const property in eventDetails) {
|
205 | details[property] = eventDetails[property];
|
206 | }
|
207 |
|
208 | this.eventBus.dispatch(eventName, details);
|
209 | }
|
210 |
|
211 | if (close) {
|
212 | this.close();
|
213 | }
|
214 | });
|
215 | }
|
216 | }
|
217 |
|
218 | #bindCursorToolsListener({
|
219 | cursorSelectToolButton,
|
220 | cursorHandToolButton
|
221 | }) {
|
222 | this.eventBus._on("cursortoolchanged", function ({
|
223 | tool
|
224 | }) {
|
225 | const isSelect = tool === _pdf_cursor_tools.CursorTool.SELECT,
|
226 | isHand = tool === _pdf_cursor_tools.CursorTool.HAND;
|
227 | cursorSelectToolButton.classList.toggle("toggled", isSelect);
|
228 | cursorHandToolButton.classList.toggle("toggled", isHand);
|
229 | cursorSelectToolButton.setAttribute("aria-checked", isSelect);
|
230 | cursorHandToolButton.setAttribute("aria-checked", isHand);
|
231 | });
|
232 | }
|
233 |
|
234 | #bindScrollModeListener({
|
235 | scrollPageButton,
|
236 | scrollVerticalButton,
|
237 | scrollHorizontalButton,
|
238 | scrollWrappedButton,
|
239 | spreadNoneButton,
|
240 | spreadOddButton,
|
241 | spreadEvenButton
|
242 | }) {
|
243 | const scrollModeChanged = ({
|
244 | mode
|
245 | }) => {
|
246 | const isPage = mode === _ui_utils.ScrollMode.PAGE,
|
247 | isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
|
248 | isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
|
249 | isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
|
250 | scrollPageButton.classList.toggle("toggled", isPage);
|
251 | scrollVerticalButton.classList.toggle("toggled", isVertical);
|
252 | scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
|
253 | scrollWrappedButton.classList.toggle("toggled", isWrapped);
|
254 | scrollPageButton.setAttribute("aria-checked", isPage);
|
255 | scrollVerticalButton.setAttribute("aria-checked", isVertical);
|
256 | scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
|
257 | scrollWrappedButton.setAttribute("aria-checked", isWrapped);
|
258 | const forceScrollModePage = this.pagesCount > _base_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
|
259 | scrollPageButton.disabled = forceScrollModePage;
|
260 | scrollVerticalButton.disabled = forceScrollModePage;
|
261 | scrollHorizontalButton.disabled = forceScrollModePage;
|
262 | scrollWrappedButton.disabled = forceScrollModePage;
|
263 | spreadNoneButton.disabled = isHorizontal;
|
264 | spreadOddButton.disabled = isHorizontal;
|
265 | spreadEvenButton.disabled = isHorizontal;
|
266 | };
|
267 |
|
268 | this.eventBus._on("scrollmodechanged", scrollModeChanged);
|
269 |
|
270 | this.eventBus._on("secondarytoolbarreset", evt => {
|
271 | if (evt.source === this) {
|
272 | scrollModeChanged({
|
273 | mode: _ui_utils.ScrollMode.VERTICAL
|
274 | });
|
275 | }
|
276 | });
|
277 | }
|
278 |
|
279 | #bindSpreadModeListener({
|
280 | spreadNoneButton,
|
281 | spreadOddButton,
|
282 | spreadEvenButton
|
283 | }) {
|
284 | function spreadModeChanged({
|
285 | mode
|
286 | }) {
|
287 | const isNone = mode === _ui_utils.SpreadMode.NONE,
|
288 | isOdd = mode === _ui_utils.SpreadMode.ODD,
|
289 | isEven = mode === _ui_utils.SpreadMode.EVEN;
|
290 | spreadNoneButton.classList.toggle("toggled", isNone);
|
291 | spreadOddButton.classList.toggle("toggled", isOdd);
|
292 | spreadEvenButton.classList.toggle("toggled", isEven);
|
293 | spreadNoneButton.setAttribute("aria-checked", isNone);
|
294 | spreadOddButton.setAttribute("aria-checked", isOdd);
|
295 | spreadEvenButton.setAttribute("aria-checked", isEven);
|
296 | }
|
297 |
|
298 | this.eventBus._on("spreadmodechanged", spreadModeChanged);
|
299 |
|
300 | this.eventBus._on("secondarytoolbarreset", evt => {
|
301 | if (evt.source === this) {
|
302 | spreadModeChanged({
|
303 | mode: _ui_utils.SpreadMode.NONE
|
304 | });
|
305 | }
|
306 | });
|
307 | }
|
308 |
|
309 | open() {
|
310 | if (this.opened) {
|
311 | return;
|
312 | }
|
313 |
|
314 | this.opened = true;
|
315 | this.toggleButton.classList.add("toggled");
|
316 | this.toggleButton.setAttribute("aria-expanded", "true");
|
317 | this.toolbar.classList.remove("hidden");
|
318 | }
|
319 |
|
320 | close() {
|
321 | if (!this.opened) {
|
322 | return;
|
323 | }
|
324 |
|
325 | this.opened = false;
|
326 | this.toolbar.classList.add("hidden");
|
327 | this.toggleButton.classList.remove("toggled");
|
328 | this.toggleButton.setAttribute("aria-expanded", "false");
|
329 | }
|
330 |
|
331 | toggle() {
|
332 | if (this.opened) {
|
333 | this.close();
|
334 | } else {
|
335 | this.open();
|
336 | }
|
337 | }
|
338 |
|
339 | }
|
340 |
|
341 | exports.SecondaryToolbar = SecondaryToolbar; |
\ | No newline at end of file |