7
7
8
8
import {
9
9
defineJQueryPlugin ,
10
- reflow ,
11
10
typeCheckConfig
12
11
} from './util/index'
12
+ import ScrollBarHelper from './util/scrollbar'
13
13
import EventHandler from './dom/event-handler'
14
- import Manipulator from './dom/manipulator'
15
14
import BaseComponent from './base-component'
15
+ import Manipulator from './dom/manipulator'
16
+ import Backdrop from './util/backdrop'
16
17
17
18
/**
18
19
* ------------------------------------------------------------------------
@@ -30,7 +31,6 @@ const Default = {}
30
31
const DefaultType = { }
31
32
32
33
const CLASS_NAME_BACKDROP = 'sidebar-backdrop'
33
- const CLASS_NAME_FADE = 'fade'
34
34
const CLASS_NAME_HIDE = 'hide'
35
35
const CLASS_NAME_SHOW = 'show'
36
36
const CLASS_NAME_SIDEBAR_NARROW = 'sidebar-narrow'
@@ -66,8 +66,7 @@ class Sidebar extends BaseComponent {
66
66
this . _overlaid = this . _isOverlaid ( )
67
67
this . _narrow = this . _isNarrow ( )
68
68
this . _unfoldable = this . _isUnfoldable ( )
69
- this . _backdrop = null
70
-
69
+ this . _backdrop = this . _initializeBackDrop ( )
71
70
this . _addEventListeners ( )
72
71
}
73
72
@@ -96,7 +95,8 @@ class Sidebar extends BaseComponent {
96
95
97
96
if ( this . _isMobile ( ) ) {
98
97
this . _element . classList . add ( CLASS_NAME_SHOW )
99
- this . _showBackdrop ( )
98
+ this . _backdrop . show ( )
99
+ new ScrollBarHelper ( ) . hide ( )
100
100
}
101
101
102
102
const complete = ( ) => {
@@ -121,7 +121,8 @@ class Sidebar extends BaseComponent {
121
121
}
122
122
123
123
if ( this . _isMobile ( ) ) {
124
- this . _removeBackdrop ( )
124
+ this . _backdrop . hide ( )
125
+ new ScrollBarHelper ( ) . reset ( )
125
126
} else {
126
127
this . _element . classList . add ( CLASS_NAME_HIDE )
127
128
}
@@ -207,6 +208,16 @@ class Sidebar extends BaseComponent {
207
208
return config
208
209
}
209
210
211
+ _initializeBackDrop ( ) {
212
+ return new Backdrop ( {
213
+ className : CLASS_NAME_BACKDROP ,
214
+ isVisible : this . _mobile ,
215
+ isAnimated : true ,
216
+ rootElement : this . _element . parentNode ,
217
+ clickCallback : ( ) => this . hide ( )
218
+ } )
219
+ }
220
+
210
221
_isMobile ( ) {
211
222
return Boolean ( window . getComputedStyle ( this . _element , null ) . getPropertyValue ( '--cui-is-mobile' ) )
212
223
}
@@ -226,32 +237,14 @@ class Sidebar extends BaseComponent {
226
237
_isVisible ( ) {
227
238
const rect = this . _element . getBoundingClientRect ( )
228
239
return (
229
- rect . top >= 0 && rect . left >= 0 && rect . bottom <= ( window . innerHeight || document . documentElement . clientHeight ) && rect . right <= ( window . innerWidth || document . documentElement . clientWidth )
240
+ rect . top >= 0 && rect . left >= 0 && Math . floor ( rect . bottom ) <= ( window . innerHeight || document . documentElement . clientHeight ) && Math . floor ( rect . right ) <= ( window . innerWidth || document . documentElement . clientWidth )
230
241
)
231
242
}
232
243
233
244
_addClassName ( className ) {
234
245
this . _element . classList . add ( className )
235
246
}
236
247
237
- _removeBackdrop ( ) {
238
- if ( this . _backdrop ) {
239
- this . _backdrop . remove ( )
240
- this . _backdrop = null
241
- }
242
- }
243
-
244
- _showBackdrop ( ) {
245
- if ( ! this . _backdrop ) {
246
- this . _backdrop = document . createElement ( 'div' )
247
- this . _backdrop . className = CLASS_NAME_BACKDROP
248
- this . _backdrop . classList . add ( CLASS_NAME_FADE )
249
- document . body . append ( this . _backdrop )
250
- reflow ( this . _backdrop )
251
- this . _backdrop . classList . add ( CLASS_NAME_SHOW )
252
- }
253
- }
254
-
255
248
_clickOutListener ( event , sidebar ) {
256
249
if ( event . target . closest ( SELECTOR_SIDEBAR ) === null ) {
257
250
event . preventDefault ( )
0 commit comments