Merge pull request #12352 from Snuffleupagus/sidebar-resizer-CSS-vars
Remove CSS variables feature-testing from `PDFSidebarResizer`
This commit is contained in:
commit
e8822e1912
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { clamp, NullL10n } from "./ui_utils.js";
|
import { NullL10n } from "./ui_utils.js";
|
||||||
|
|
||||||
const SIDEBAR_WIDTH_VAR = "--sidebar-width";
|
const SIDEBAR_WIDTH_VAR = "--sidebar-width";
|
||||||
const SIDEBAR_MIN_WIDTH = 200; // pixels
|
const SIDEBAR_MIN_WIDTH = 200; // pixels
|
||||||
@ -34,7 +34,6 @@ class PDFSidebarResizer {
|
|||||||
* @param {IL10n} l10n - Localization service.
|
* @param {IL10n} l10n - Localization service.
|
||||||
*/
|
*/
|
||||||
constructor(options, eventBus, l10n = NullL10n) {
|
constructor(options, eventBus, l10n = NullL10n) {
|
||||||
this.enabled = false;
|
|
||||||
this.isRTL = false;
|
this.isRTL = false;
|
||||||
this.sidebarOpen = false;
|
this.sidebarOpen = false;
|
||||||
this.doc = document.documentElement;
|
this.doc = document.documentElement;
|
||||||
@ -45,24 +44,8 @@ class PDFSidebarResizer {
|
|||||||
this.outerContainer = options.outerContainer;
|
this.outerContainer = options.outerContainer;
|
||||||
this.resizer = options.resizer;
|
this.resizer = options.resizer;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.l10n = l10n;
|
|
||||||
|
|
||||||
if (
|
l10n.getDirection().then(dir => {
|
||||||
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
|
||||||
(typeof CSS === "undefined" ||
|
|
||||||
typeof CSS.supports !== "function" ||
|
|
||||||
!CSS.supports(SIDEBAR_WIDTH_VAR, `calc(-1 * ${SIDEBAR_MIN_WIDTH}px)`))
|
|
||||||
) {
|
|
||||||
console.warn(
|
|
||||||
"PDFSidebarResizer: " +
|
|
||||||
"The browser does not support resizing of the sidebar."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.enabled = true;
|
|
||||||
this.resizer.classList.remove("hidden"); // Show the resizer DOM element.
|
|
||||||
|
|
||||||
this.l10n.getDirection().then(dir => {
|
|
||||||
this.isRTL = dir === "rtl";
|
this.isRTL = dir === "rtl";
|
||||||
});
|
});
|
||||||
this._addEventListeners();
|
this._addEventListeners();
|
||||||
@ -83,22 +66,21 @@ class PDFSidebarResizer {
|
|||||||
* returns {boolean} Indicating if the sidebar width was updated.
|
* returns {boolean} Indicating if the sidebar width was updated.
|
||||||
*/
|
*/
|
||||||
_updateWidth(width = 0) {
|
_updateWidth(width = 0) {
|
||||||
if (!this.enabled) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Prevent the sidebar from becoming too narrow, or from occupying more
|
// Prevent the sidebar from becoming too narrow, or from occupying more
|
||||||
// than half of the available viewer width.
|
// than half of the available viewer width.
|
||||||
const newWidth = clamp(
|
const maxWidth = Math.floor(this.outerContainerWidth / 2);
|
||||||
width,
|
if (width > maxWidth) {
|
||||||
SIDEBAR_MIN_WIDTH,
|
width = maxWidth;
|
||||||
Math.floor(this.outerContainerWidth / 2)
|
}
|
||||||
);
|
if (width < SIDEBAR_MIN_WIDTH) {
|
||||||
|
width = SIDEBAR_MIN_WIDTH;
|
||||||
|
}
|
||||||
// Only update the UI when the sidebar width did in fact change.
|
// Only update the UI when the sidebar width did in fact change.
|
||||||
if (newWidth === this._width) {
|
if (width === this._width) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._width = newWidth;
|
this._width = width;
|
||||||
this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${newWidth}px`);
|
this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,9 +114,6 @@ class PDFSidebarResizer {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_addEventListeners() {
|
_addEventListeners() {
|
||||||
if (!this.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const _boundEvents = this._boundEvents;
|
const _boundEvents = this._boundEvents;
|
||||||
_boundEvents.mouseMove = this._mouseMove.bind(this);
|
_boundEvents.mouseMove = this._mouseMove.bind(this);
|
||||||
_boundEvents.mouseUp = this._mouseUp.bind(this);
|
_boundEvents.mouseUp = this._mouseUp.bind(this);
|
||||||
|
@ -1006,7 +1006,6 @@ export {
|
|||||||
SpreadMode,
|
SpreadMode,
|
||||||
NullL10n,
|
NullL10n,
|
||||||
EventBus,
|
EventBus,
|
||||||
clamp,
|
|
||||||
ProgressBar,
|
ProgressBar,
|
||||||
getPDFFileNameFromURL,
|
getPDFFileNameFromURL,
|
||||||
noContextMenuHandler,
|
noContextMenuHandler,
|
||||||
|
@ -101,7 +101,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<div id="layersView" class="hidden">
|
<div id="layersView" class="hidden">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="sidebarResizer" class="hidden"></div>
|
<div id="sidebarResizer"></div>
|
||||||
</div> <!-- sidebarContainer -->
|
</div> <!-- sidebarContainer -->
|
||||||
|
|
||||||
<div id="mainContainer">
|
<div id="mainContainer">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user