Skip to content

Commit e8822e1

Browse files
Merge pull request #12352 from Snuffleupagus/sidebar-resizer-CSS-vars
Remove CSS variables feature-testing from `PDFSidebarResizer`
2 parents 82dede0 + 01c1d87 commit e8822e1

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

web/pdf_sidebar_resizer.js

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { clamp, NullL10n } from "./ui_utils.js";
16+
import { NullL10n } from "./ui_utils.js";
1717

1818
const SIDEBAR_WIDTH_VAR = "--sidebar-width";
1919
const SIDEBAR_MIN_WIDTH = 200; // pixels
@@ -34,7 +34,6 @@ class PDFSidebarResizer {
3434
* @param {IL10n} l10n - Localization service.
3535
*/
3636
constructor(options, eventBus, l10n = NullL10n) {
37-
this.enabled = false;
3837
this.isRTL = false;
3938
this.sidebarOpen = false;
4039
this.doc = document.documentElement;
@@ -45,24 +44,8 @@ class PDFSidebarResizer {
4544
this.outerContainer = options.outerContainer;
4645
this.resizer = options.resizer;
4746
this.eventBus = eventBus;
48-
this.l10n = l10n;
49-
50-
if (
51-
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
52-
(typeof CSS === "undefined" ||
53-
typeof CSS.supports !== "function" ||
54-
!CSS.supports(SIDEBAR_WIDTH_VAR, `calc(-1 * ${SIDEBAR_MIN_WIDTH}px)`))
55-
) {
56-
console.warn(
57-
"PDFSidebarResizer: " +
58-
"The browser does not support resizing of the sidebar."
59-
);
60-
return;
61-
}
62-
this.enabled = true;
63-
this.resizer.classList.remove("hidden"); // Show the resizer DOM element.
6447

65-
this.l10n.getDirection().then(dir => {
48+
l10n.getDirection().then(dir => {
6649
this.isRTL = dir === "rtl";
6750
});
6851
this._addEventListeners();
@@ -83,22 +66,21 @@ class PDFSidebarResizer {
8366
* returns {boolean} Indicating if the sidebar width was updated.
8467
*/
8568
_updateWidth(width = 0) {
86-
if (!this.enabled) {
87-
return false;
88-
}
8969
// Prevent the sidebar from becoming too narrow, or from occupying more
9070
// than half of the available viewer width.
91-
const newWidth = clamp(
92-
width,
93-
SIDEBAR_MIN_WIDTH,
94-
Math.floor(this.outerContainerWidth / 2)
95-
);
71+
const maxWidth = Math.floor(this.outerContainerWidth / 2);
72+
if (width > maxWidth) {
73+
width = maxWidth;
74+
}
75+
if (width < SIDEBAR_MIN_WIDTH) {
76+
width = SIDEBAR_MIN_WIDTH;
77+
}
9678
// Only update the UI when the sidebar width did in fact change.
97-
if (newWidth === this._width) {
79+
if (width === this._width) {
9880
return false;
9981
}
100-
this._width = newWidth;
101-
this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${newWidth}px`);
82+
this._width = width;
83+
this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
10284
return true;
10385
}
10486

@@ -132,9 +114,6 @@ class PDFSidebarResizer {
132114
* @private
133115
*/
134116
_addEventListeners() {
135-
if (!this.enabled) {
136-
return;
137-
}
138117
const _boundEvents = this._boundEvents;
139118
_boundEvents.mouseMove = this._mouseMove.bind(this);
140119
_boundEvents.mouseUp = this._mouseUp.bind(this);

web/ui_utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ export {
10061006
SpreadMode,
10071007
NullL10n,
10081008
EventBus,
1009-
clamp,
10101009
ProgressBar,
10111010
getPDFFileNameFromURL,
10121011
noContextMenuHandler,

web/viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<div id="layersView" class="hidden">
102102
</div>
103103
</div>
104-
<div id="sidebarResizer" class="hidden"></div>
104+
<div id="sidebarResizer"></div>
105105
</div> <!-- sidebarContainer -->
106106

107107
<div id="mainContainer">

0 commit comments

Comments
 (0)