13
13
* limitations under the License.
14
14
*/
15
15
16
- import { clamp , NullL10n } from "./ui_utils.js" ;
16
+ import { NullL10n } from "./ui_utils.js" ;
17
17
18
18
const SIDEBAR_WIDTH_VAR = "--sidebar-width" ;
19
19
const SIDEBAR_MIN_WIDTH = 200 ; // pixels
@@ -34,7 +34,6 @@ class PDFSidebarResizer {
34
34
* @param {IL10n } l10n - Localization service.
35
35
*/
36
36
constructor ( options , eventBus , l10n = NullL10n ) {
37
- this . enabled = false ;
38
37
this . isRTL = false ;
39
38
this . sidebarOpen = false ;
40
39
this . doc = document . documentElement ;
@@ -45,24 +44,8 @@ class PDFSidebarResizer {
45
44
this . outerContainer = options . outerContainer ;
46
45
this . resizer = options . resizer ;
47
46
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.
64
47
65
- this . l10n . getDirection ( ) . then ( dir => {
48
+ l10n . getDirection ( ) . then ( dir => {
66
49
this . isRTL = dir === "rtl" ;
67
50
} ) ;
68
51
this . _addEventListeners ( ) ;
@@ -83,22 +66,21 @@ class PDFSidebarResizer {
83
66
* returns {boolean} Indicating if the sidebar width was updated.
84
67
*/
85
68
_updateWidth ( width = 0 ) {
86
- if ( ! this . enabled ) {
87
- return false ;
88
- }
89
69
// Prevent the sidebar from becoming too narrow, or from occupying more
90
70
// 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
+ }
96
78
// Only update the UI when the sidebar width did in fact change.
97
- if ( newWidth === this . _width ) {
79
+ if ( width === this . _width ) {
98
80
return false ;
99
81
}
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` ) ;
102
84
return true ;
103
85
}
104
86
@@ -132,9 +114,6 @@ class PDFSidebarResizer {
132
114
* @private
133
115
*/
134
116
_addEventListeners ( ) {
135
- if ( ! this . enabled ) {
136
- return ;
137
- }
138
117
const _boundEvents = this . _boundEvents ;
139
118
_boundEvents . mouseMove = this . _mouseMove . bind ( this ) ;
140
119
_boundEvents . mouseUp = this . _mouseUp . bind ( this ) ;
0 commit comments