Merge pull request #14637 from timvandermeij/web-private
Use proper private methods in `web/{pdf_cursor_tools,pdf_find_bar,secondary_toolbar}.js`
This commit is contained in:
commit
c1f73b140f
@ -46,7 +46,7 @@ class PDFCursorTools {
|
|||||||
element: this.container,
|
element: this.container,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._addEventListeners();
|
this.#addEventListeners();
|
||||||
|
|
||||||
// Defer the initial `switchTool` call, to give other viewer components
|
// Defer the initial `switchTool` call, to give other viewer components
|
||||||
// time to initialize *and* register 'cursortoolchanged' event listeners.
|
// time to initialize *and* register 'cursortoolchanged' event listeners.
|
||||||
@ -106,23 +106,17 @@ class PDFCursorTools {
|
|||||||
// in order to prevent setting it to an invalid state.
|
// in order to prevent setting it to an invalid state.
|
||||||
this.active = tool;
|
this.active = tool;
|
||||||
|
|
||||||
this._dispatchEvent();
|
this.#dispatchEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#dispatchEvent() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_dispatchEvent() {
|
|
||||||
this.eventBus.dispatch("cursortoolchanged", {
|
this.eventBus.dispatch("cursortoolchanged", {
|
||||||
source: this,
|
source: this,
|
||||||
tool: this.active,
|
tool: this.active,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#addEventListeners() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_addEventListeners() {
|
|
||||||
this.eventBus._on("switchcursortool", evt => {
|
this.eventBus._on("switchcursortool", evt => {
|
||||||
this.switchTool(evt.tool);
|
this.switchTool(evt.tool);
|
||||||
});
|
});
|
||||||
|
@ -87,7 +87,7 @@ class PDFFindBar {
|
|||||||
this.dispatchEvent("diacriticmatchingchange");
|
this.dispatchEvent("diacriticmatchingchange");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventBus._on("resize", this._adjustWidth.bind(this));
|
this.eventBus._on("resize", this.#adjustWidth.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
@ -130,7 +130,7 @@ class PDFFindBar {
|
|||||||
|
|
||||||
findMsg.then(msg => {
|
findMsg.then(msg => {
|
||||||
this.findMsg.textContent = msg;
|
this.findMsg.textContent = msg;
|
||||||
this._adjustWidth();
|
this.#adjustWidth();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateResultsCount(matchesCount);
|
this.updateResultsCount(matchesCount);
|
||||||
@ -165,7 +165,7 @@ class PDFFindBar {
|
|||||||
this.findResultsCount.textContent = msg;
|
this.findResultsCount.textContent = msg;
|
||||||
// Since `updateResultsCount` may be called from `PDFFindController`,
|
// Since `updateResultsCount` may be called from `PDFFindController`,
|
||||||
// ensure that the width of the findbar is always updated correctly.
|
// ensure that the width of the findbar is always updated correctly.
|
||||||
this._adjustWidth();
|
this.#adjustWidth();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ class PDFFindBar {
|
|||||||
this.findField.select();
|
this.findField.select();
|
||||||
this.findField.focus();
|
this.findField.focus();
|
||||||
|
|
||||||
this._adjustWidth();
|
this.#adjustWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
@ -202,10 +202,7 @@ class PDFFindBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#adjustWidth() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_adjustWidth() {
|
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -159,13 +159,13 @@ class SecondaryToolbar {
|
|||||||
|
|
||||||
// Bind the event listeners for click, cursor tool, and scroll/spread mode
|
// Bind the event listeners for click, cursor tool, and scroll/spread mode
|
||||||
// actions.
|
// actions.
|
||||||
this._bindClickListeners();
|
this.#bindClickListeners();
|
||||||
this._bindCursorToolsListener(options);
|
this.#bindCursorToolsListener(options);
|
||||||
this._bindScrollModeListener(options);
|
this.#bindScrollModeListener(options);
|
||||||
this._bindSpreadModeListener(options);
|
this.#bindSpreadModeListener(options);
|
||||||
|
|
||||||
// Bind the event listener for adjusting the 'max-height' of the toolbar.
|
// Bind the event listener for adjusting the 'max-height' of the toolbar.
|
||||||
this.eventBus._on("resize", this._setMaxHeight.bind(this));
|
this.eventBus._on("resize", this.#setMaxHeight.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,31 +177,31 @@ class SecondaryToolbar {
|
|||||||
|
|
||||||
setPageNumber(pageNumber) {
|
setPageNumber(pageNumber) {
|
||||||
this.pageNumber = pageNumber;
|
this.pageNumber = pageNumber;
|
||||||
this._updateUIState();
|
this.#updateUIState();
|
||||||
}
|
}
|
||||||
|
|
||||||
setPagesCount(pagesCount) {
|
setPagesCount(pagesCount) {
|
||||||
this.pagesCount = pagesCount;
|
this.pagesCount = pagesCount;
|
||||||
this._updateUIState();
|
this.#updateUIState();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.pageNumber = 0;
|
this.pageNumber = 0;
|
||||||
this.pagesCount = 0;
|
this.pagesCount = 0;
|
||||||
this._updateUIState();
|
this.#updateUIState();
|
||||||
|
|
||||||
// Reset the Scroll/Spread buttons too, since they're document specific.
|
// Reset the Scroll/Spread buttons too, since they're document specific.
|
||||||
this.eventBus.dispatch("secondarytoolbarreset", { source: this });
|
this.eventBus.dispatch("secondarytoolbarreset", { source: this });
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateUIState() {
|
#updateUIState() {
|
||||||
this.items.firstPage.disabled = this.pageNumber <= 1;
|
this.items.firstPage.disabled = this.pageNumber <= 1;
|
||||||
this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
|
this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
|
||||||
this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
||||||
this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_bindClickListeners() {
|
#bindClickListeners() {
|
||||||
// Button to toggle the visibility of the secondary toolbar.
|
// Button to toggle the visibility of the secondary toolbar.
|
||||||
this.toggleButton.addEventListener("click", this.toggle.bind(this));
|
this.toggleButton.addEventListener("click", this.toggle.bind(this));
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ class SecondaryToolbar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_bindCursorToolsListener(buttons) {
|
#bindCursorToolsListener(buttons) {
|
||||||
this.eventBus._on("cursortoolchanged", function ({ tool }) {
|
this.eventBus._on("cursortoolchanged", function ({ tool }) {
|
||||||
buttons.cursorSelectToolButton.classList.toggle(
|
buttons.cursorSelectToolButton.classList.toggle(
|
||||||
"toggled",
|
"toggled",
|
||||||
@ -235,7 +235,7 @@ class SecondaryToolbar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_bindScrollModeListener(buttons) {
|
#bindScrollModeListener(buttons) {
|
||||||
const scrollModeChanged = ({ mode }) => {
|
const scrollModeChanged = ({ mode }) => {
|
||||||
buttons.scrollPageButton.classList.toggle(
|
buttons.scrollPageButton.classList.toggle(
|
||||||
"toggled",
|
"toggled",
|
||||||
@ -279,7 +279,7 @@ class SecondaryToolbar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_bindSpreadModeListener(buttons) {
|
#bindSpreadModeListener(buttons) {
|
||||||
function spreadModeChanged({ mode }) {
|
function spreadModeChanged({ mode }) {
|
||||||
buttons.spreadNoneButton.classList.toggle(
|
buttons.spreadNoneButton.classList.toggle(
|
||||||
"toggled",
|
"toggled",
|
||||||
@ -308,7 +308,7 @@ class SecondaryToolbar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.opened = true;
|
this.opened = true;
|
||||||
this._setMaxHeight();
|
this.#setMaxHeight();
|
||||||
|
|
||||||
this.toggleButton.classList.add("toggled");
|
this.toggleButton.classList.add("toggled");
|
||||||
this.toggleButton.setAttribute("aria-expanded", "true");
|
this.toggleButton.setAttribute("aria-expanded", "true");
|
||||||
@ -333,10 +333,7 @@ class SecondaryToolbar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
#setMaxHeight() {
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_setMaxHeight() {
|
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
return; // Only adjust the 'max-height' if the toolbar is visible.
|
return; // Only adjust the 'max-height' if the toolbar is visible.
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user