2013-09-05 06:48:31 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
Modify a number of the viewer preferences, whose current default value is `0`, such that they behave as expected with the view history
The intention with preferences such as `sidebarViewOnLoad`/`scrollModeOnLoad`/`spreadModeOnLoad` were always that they should be able to *unconditionally* override their view history counterparts.
Due to the way that these preferences were initially implemented[1], trying to e.g. force the sidebar to remain hidden on load cannot be guaranteed[2]. The reason for this is the use of "enumeration values" containing zero, which in hindsight was an unfortunate choice on my part.
At this point it's also not as simple as just re-numbering the affected structures, since that would wreak havoc on existing (modified) preferences. The only reasonable solution that I was able to come up with was to change the *default* values of the preferences themselves, but not their actual values or the meaning thereof.
As part of the refactoring, the `disablePageMode` preference was combined with the *adjusted* `sidebarViewOnLoad` one, to hopefully reduce confusion by not tracking related state separately.
Additionally, the `showPreviousViewOnLoad` and `disableOpenActionDestination` preferences were combined into a *new* `viewOnLoad` enumeration preference, to further avoid tracking related state separately.
2019-01-27 20:07:38 +09:00
|
|
|
import { SCROLLBAR_PADDING, ScrollMode, SpreadMode } from './ui_utils';
|
2016-09-07 20:30:26 +09:00
|
|
|
import { CursorTool } from './pdf_cursor_tools';
|
2018-07-08 17:56:01 +09:00
|
|
|
import { PDFSinglePageViewer } from './pdf_single_page_viewer';
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2016-05-11 08:31:03 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} SecondaryToolbarOptions
|
|
|
|
* @property {HTMLDivElement} toolbar - Container for the secondary toolbar.
|
|
|
|
* @property {HTMLButtonElement} toggleButton - Button to toggle the visibility
|
|
|
|
* of the secondary toolbar.
|
2016-09-08 19:35:49 +09:00
|
|
|
* @property {HTMLDivElement} toolbarButtonContainer - Container where all the
|
|
|
|
* toolbar buttons are placed. The maximum height of the toolbar is controlled
|
|
|
|
* dynamically by adjusting the 'max-height' CSS property of this DOM element.
|
2016-05-11 08:31:03 +09:00
|
|
|
* @property {HTMLButtonElement} presentationModeButton - Button for entering
|
|
|
|
* presentation mode.
|
|
|
|
* @property {HTMLButtonElement} openFileButton - Button to open a file.
|
|
|
|
* @property {HTMLButtonElement} printButton - Button to print the document.
|
|
|
|
* @property {HTMLButtonElement} downloadButton - Button to download the
|
|
|
|
* document.
|
|
|
|
* @property {HTMLLinkElement} viewBookmarkButton - Button to obtain a bookmark
|
|
|
|
* link to the current location in the document.
|
|
|
|
* @property {HTMLButtonElement} firstPageButton - Button to go to the first
|
|
|
|
* page in the document.
|
|
|
|
* @property {HTMLButtonElement} lastPageButton - Button to go to the last page
|
|
|
|
* in the document.
|
|
|
|
* @property {HTMLButtonElement} pageRotateCwButton - Button to rotate the pages
|
|
|
|
* clockwise.
|
|
|
|
* @property {HTMLButtonElement} pageRotateCcwButton - Button to rotate the
|
|
|
|
* pages counterclockwise.
|
2016-09-07 20:30:26 +09:00
|
|
|
* @property {HTMLButtonElement} cursorSelectToolButton - Button to enable the
|
|
|
|
* select tool.
|
|
|
|
* @property {HTMLButtonElement} cursorHandToolButton - Button to enable the
|
2016-05-11 08:31:03 +09:00
|
|
|
* hand tool.
|
|
|
|
* @property {HTMLButtonElement} documentPropertiesButton - Button for opening
|
|
|
|
* the document properties dialog.
|
|
|
|
*/
|
2013-09-05 06:48:31 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
class SecondaryToolbar {
|
2016-05-11 08:31:03 +09:00
|
|
|
/**
|
|
|
|
* @param {SecondaryToolbarOptions} options
|
2016-09-08 19:35:49 +09:00
|
|
|
* @param {HTMLDivElement} mainContainer
|
2016-05-11 08:31:03 +09:00
|
|
|
* @param {EventBus} eventBus
|
|
|
|
*/
|
2017-05-08 04:43:50 +09:00
|
|
|
constructor(options, mainContainer, eventBus) {
|
2013-09-05 06:48:31 +09:00
|
|
|
this.toolbar = options.toolbar;
|
2013-10-18 06:49:30 +09:00
|
|
|
this.toggleButton = options.toggleButton;
|
2016-09-08 19:35:49 +09:00
|
|
|
this.toolbarButtonContainer = options.toolbarButtonContainer;
|
2016-05-11 08:31:03 +09:00
|
|
|
this.buttons = [
|
|
|
|
{ element: options.presentationModeButton, eventName: 'presentationmode',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: true, },
|
|
|
|
{ element: options.openFileButton, eventName: 'openfile', close: true, },
|
|
|
|
{ element: options.printButton, eventName: 'print', close: true, },
|
|
|
|
{ element: options.downloadButton, eventName: 'download', close: true, },
|
|
|
|
{ element: options.viewBookmarkButton, eventName: null, close: true, },
|
|
|
|
{ element: options.firstPageButton, eventName: 'firstpage',
|
|
|
|
close: true, },
|
|
|
|
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
|
2016-05-11 08:31:03 +09:00
|
|
|
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: false, },
|
2016-05-11 08:31:03 +09:00
|
|
|
{ element: options.pageRotateCcwButton, eventName: 'rotateccw',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
close: false, },
|
2016-09-07 20:30:26 +09:00
|
|
|
{ element: options.cursorSelectToolButton, eventName: 'switchcursortool',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventDetails: { tool: CursorTool.SELECT, }, close: true, },
|
2016-09-07 20:30:26 +09:00
|
|
|
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventDetails: { tool: CursorTool.HAND, }, close: true, },
|
2018-05-15 12:10:32 +09:00
|
|
|
{ element: options.scrollVerticalButton, eventName: 'switchscrollmode',
|
|
|
|
eventDetails: { mode: ScrollMode.VERTICAL, }, close: true, },
|
|
|
|
{ element: options.scrollHorizontalButton, eventName: 'switchscrollmode',
|
|
|
|
eventDetails: { mode: ScrollMode.HORIZONTAL, }, close: true, },
|
|
|
|
{ element: options.scrollWrappedButton, eventName: 'switchscrollmode',
|
|
|
|
eventDetails: { mode: ScrollMode.WRAPPED, }, close: true, },
|
2018-05-15 12:10:32 +09:00
|
|
|
{ element: options.spreadNoneButton, eventName: 'switchspreadmode',
|
|
|
|
eventDetails: { mode: SpreadMode.NONE, }, close: true, },
|
|
|
|
{ element: options.spreadOddButton, eventName: 'switchspreadmode',
|
|
|
|
eventDetails: { mode: SpreadMode.ODD, }, close: true, },
|
|
|
|
{ element: options.spreadEvenButton, eventName: 'switchspreadmode',
|
|
|
|
eventDetails: { mode: SpreadMode.EVEN, }, close: true, },
|
2016-05-11 08:31:03 +09:00
|
|
|
{ element: options.documentPropertiesButton,
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
eventName: 'documentproperties', close: true, },
|
2013-10-18 06:49:30 +09:00
|
|
|
];
|
2016-11-19 03:50:29 +09:00
|
|
|
this.items = {
|
|
|
|
firstPage: options.firstPageButton,
|
|
|
|
lastPage: options.lastPageButton,
|
|
|
|
pageRotateCw: options.pageRotateCwButton,
|
|
|
|
pageRotateCcw: options.pageRotateCcwButton,
|
|
|
|
};
|
2013-10-18 06:49:30 +09:00
|
|
|
|
2016-09-08 19:35:49 +09:00
|
|
|
this.mainContainer = mainContainer;
|
2016-05-11 08:31:03 +09:00
|
|
|
this.eventBus = eventBus;
|
|
|
|
|
|
|
|
this.opened = false;
|
2016-09-08 19:35:49 +09:00
|
|
|
this.containerHeight = null;
|
2016-05-11 08:31:03 +09:00
|
|
|
this.previousContainerHeight = null;
|
|
|
|
|
2016-11-19 03:50:29 +09:00
|
|
|
this.reset();
|
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
// Bind the event listeners for click, cursor tool, and scroll/spread mode
|
|
|
|
// actions.
|
2016-05-11 08:31:03 +09:00
|
|
|
this._bindClickListeners();
|
2016-09-07 20:30:26 +09:00
|
|
|
this._bindCursorToolsListener(options);
|
2018-05-15 12:10:32 +09:00
|
|
|
this._bindScrollModeListener(options);
|
2018-05-15 12:10:32 +09:00
|
|
|
this._bindSpreadModeListener(options);
|
2016-09-08 19:35:49 +09:00
|
|
|
|
|
|
|
// Bind the event listener for adjusting the 'max-height' of the toolbar.
|
|
|
|
this.eventBus.on('resize', this._setMaxHeight.bind(this));
|
2018-07-08 17:56:01 +09:00
|
|
|
|
|
|
|
// Hide the Scroll/Spread mode buttons, when they're not applicable to the
|
|
|
|
// current `BaseViewer` instance (in particular `PDFSinglePageViewer`).
|
|
|
|
this.eventBus.on('baseviewerinit', (evt) => {
|
|
|
|
if (evt.source instanceof PDFSinglePageViewer) {
|
2018-10-12 22:29:45 +09:00
|
|
|
this.toolbarButtonContainer.classList.add('hiddenScrollModeButtons',
|
|
|
|
'hiddenSpreadModeButtons');
|
2018-07-08 17:56:01 +09:00
|
|
|
} else {
|
2018-10-12 22:29:45 +09:00
|
|
|
this.toolbarButtonContainer.classList.remove('hiddenScrollModeButtons',
|
|
|
|
'hiddenSpreadModeButtons');
|
2018-07-08 17:56:01 +09:00
|
|
|
}
|
|
|
|
});
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
/**
|
2019-10-13 00:02:54 +09:00
|
|
|
* @type {boolean}
|
2017-05-08 04:43:50 +09:00
|
|
|
*/
|
|
|
|
get isOpen() {
|
|
|
|
return this.opened;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPageNumber(pageNumber) {
|
|
|
|
this.pageNumber = pageNumber;
|
|
|
|
this._updateUIState();
|
|
|
|
}
|
|
|
|
|
|
|
|
setPagesCount(pagesCount) {
|
|
|
|
this.pagesCount = pagesCount;
|
|
|
|
this._updateUIState();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.pageNumber = 0;
|
|
|
|
this.pagesCount = 0;
|
|
|
|
this._updateUIState();
|
2018-06-30 21:54:33 +09:00
|
|
|
|
|
|
|
// Reset the Scroll/Spread buttons too, since they're document specific.
|
2018-07-08 17:55:56 +09:00
|
|
|
this.eventBus.dispatch('secondarytoolbarreset', { source: this, });
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
_updateUIState() {
|
|
|
|
this.items.firstPage.disabled = (this.pageNumber <= 1);
|
|
|
|
this.items.lastPage.disabled = (this.pageNumber >= this.pagesCount);
|
|
|
|
this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
|
|
|
this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_bindClickListeners() {
|
|
|
|
// Button to toggle the visibility of the secondary toolbar.
|
|
|
|
this.toggleButton.addEventListener('click', this.toggle.bind(this));
|
|
|
|
|
|
|
|
// All items within the secondary toolbar.
|
|
|
|
for (let button in this.buttons) {
|
2016-09-07 20:30:26 +09:00
|
|
|
let { element, eventName, close, eventDetails, } = this.buttons[button];
|
2017-05-08 04:43:50 +09:00
|
|
|
|
|
|
|
element.addEventListener('click', (evt) => {
|
|
|
|
if (eventName !== null) {
|
2016-09-07 20:30:26 +09:00
|
|
|
let details = { source: this, };
|
|
|
|
for (let property in eventDetails) {
|
|
|
|
details[property] = eventDetails[property];
|
|
|
|
}
|
|
|
|
this.eventBus.dispatch(eventName, details);
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
2017-05-08 04:43:50 +09:00
|
|
|
if (close) {
|
|
|
|
this.close();
|
2016-05-11 08:31:03 +09:00
|
|
|
}
|
2016-12-10 21:58:06 +09:00
|
|
|
});
|
2017-05-08 04:43:50 +09:00
|
|
|
}
|
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2016-09-07 20:30:26 +09:00
|
|
|
_bindCursorToolsListener(buttons) {
|
2019-02-07 01:18:45 +09:00
|
|
|
this.eventBus.on('cursortoolchanged', function({ tool, }) {
|
|
|
|
buttons.cursorSelectToolButton.classList.toggle('toggled',
|
|
|
|
tool === CursorTool.SELECT);
|
|
|
|
buttons.cursorHandToolButton.classList.toggle('toggled',
|
|
|
|
tool === CursorTool.HAND);
|
2017-05-08 04:43:50 +09:00
|
|
|
});
|
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
_bindScrollModeListener(buttons) {
|
2019-02-07 01:18:45 +09:00
|
|
|
function scrollModeChanged({ mode, }) {
|
|
|
|
buttons.scrollVerticalButton.classList.toggle('toggled',
|
|
|
|
mode === ScrollMode.VERTICAL);
|
|
|
|
buttons.scrollHorizontalButton.classList.toggle('toggled',
|
|
|
|
mode === ScrollMode.HORIZONTAL);
|
|
|
|
buttons.scrollWrappedButton.classList.toggle('toggled',
|
|
|
|
mode === ScrollMode.WRAPPED);
|
2018-07-08 17:56:06 +09:00
|
|
|
|
|
|
|
// Temporarily *disable* the Spread buttons when horizontal scrolling is
|
|
|
|
// enabled, since the non-default Spread modes doesn't affect the layout.
|
2019-02-07 01:18:45 +09:00
|
|
|
const isScrollModeHorizontal = (mode === ScrollMode.HORIZONTAL);
|
2018-07-08 17:56:06 +09:00
|
|
|
buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
|
|
|
|
buttons.spreadOddButton.disabled = isScrollModeHorizontal;
|
|
|
|
buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
|
2018-06-30 21:54:33 +09:00
|
|
|
}
|
|
|
|
this.eventBus.on('scrollmodechanged', scrollModeChanged);
|
|
|
|
|
2018-07-08 17:55:56 +09:00
|
|
|
this.eventBus.on('secondarytoolbarreset', (evt) => {
|
2018-06-30 21:54:33 +09:00
|
|
|
if (evt.source === this) {
|
|
|
|
scrollModeChanged({ mode: ScrollMode.VERTICAL, });
|
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:10:32 +09:00
|
|
|
_bindSpreadModeListener(buttons) {
|
2019-02-07 01:18:45 +09:00
|
|
|
function spreadModeChanged({ mode, }) {
|
|
|
|
buttons.spreadNoneButton.classList.toggle('toggled',
|
|
|
|
mode === SpreadMode.NONE);
|
|
|
|
buttons.spreadOddButton.classList.toggle('toggled',
|
|
|
|
mode === SpreadMode.ODD);
|
|
|
|
buttons.spreadEvenButton.classList.toggle('toggled',
|
|
|
|
mode === SpreadMode.EVEN);
|
2018-06-30 21:54:33 +09:00
|
|
|
}
|
|
|
|
this.eventBus.on('spreadmodechanged', spreadModeChanged);
|
|
|
|
|
2018-07-08 17:55:56 +09:00
|
|
|
this.eventBus.on('secondarytoolbarreset', (evt) => {
|
2018-06-30 21:54:33 +09:00
|
|
|
if (evt.source === this) {
|
|
|
|
spreadModeChanged({ mode: SpreadMode.NONE, });
|
|
|
|
}
|
2018-05-15 12:10:32 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
open() {
|
|
|
|
if (this.opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.opened = true;
|
|
|
|
this._setMaxHeight();
|
|
|
|
|
|
|
|
this.toggleButton.classList.add('toggled');
|
|
|
|
this.toolbar.classList.remove('hidden');
|
|
|
|
}
|
2016-09-08 19:35:49 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
close() {
|
|
|
|
if (!this.opened) {
|
|
|
|
return;
|
2013-09-05 06:48:31 +09:00
|
|
|
}
|
2017-05-08 04:43:50 +09:00
|
|
|
this.opened = false;
|
|
|
|
this.toolbar.classList.add('hidden');
|
|
|
|
this.toggleButton.classList.remove('toggled');
|
|
|
|
}
|
2016-05-11 08:31:03 +09:00
|
|
|
|
2017-05-08 04:43:50 +09:00
|
|
|
toggle() {
|
|
|
|
if (this.opened) {
|
|
|
|
this.close();
|
|
|
|
} else {
|
|
|
|
this.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_setMaxHeight() {
|
|
|
|
if (!this.opened) {
|
|
|
|
return; // Only adjust the 'max-height' if the toolbar is visible.
|
|
|
|
}
|
|
|
|
this.containerHeight = this.mainContainer.clientHeight;
|
|
|
|
|
|
|
|
if (this.containerHeight === this.previousContainerHeight) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.toolbarButtonContainer.setAttribute('style',
|
|
|
|
'max-height: ' + (this.containerHeight - SCROLLBAR_PADDING) + 'px;');
|
|
|
|
|
|
|
|
this.previousContainerHeight = this.containerHeight;
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
SecondaryToolbar,
|
|
|
|
};
|