@@ -62,9 +62,11 @@ class NavCard {
62
62
useBackdrop : false ,
63
63
backdrop : null ,
64
64
dest : null ,
65
+ scrollableContainer : null ,
65
66
maxStartArea : 25 ,
66
67
threshold : 1 / 2 ,
67
- unit : 'px'
68
+ unit : 'px' ,
69
+ CustomDrawer : null
68
70
}
69
71
70
72
static SERVICES = {
@@ -134,13 +136,15 @@ class NavCard {
134
136
MAX_WIDTH : maxWidth ,
135
137
DIRECTION : opts . direction ,
136
138
maxStartArea : opts . maxStartArea ,
137
- threshold : opts . threshold
139
+ threshold : opts . threshold ,
140
+ scrollableContainer : opts . scrollableContainer ,
141
+ CustomDrawer : opts . CustomDrawer
138
142
}
139
143
const hashOptions = {
140
144
INIT_ELEM : defaultOptions . INIT_ELEM
141
145
}
142
146
143
- return new NavMountWorker ( {
147
+ return new NavMountWorker ( this , {
144
148
defaultOptions,
145
149
drawerOptions,
146
150
hashOptions
@@ -174,7 +178,10 @@ class NavCard {
174
178
}
175
179
176
180
_drawerAPI ( options ) {
177
- this . Drawer = new NavDrawer ( options , this . State )
181
+ const {
182
+ CustomDrawer : Drawer
183
+ } = options
184
+ this . Drawer = Drawer && typeof Drawer === 'object' ? new Drawer ( options , this . State ) : new NavDrawer ( options , this . State )
178
185
return {
179
186
activate : ( ) => this . Drawer . activate ( ) ,
180
187
deactivate : ( ) => this . Drawer . deactivate ( )
@@ -198,29 +205,29 @@ class NavCard {
198
205
}
199
206
}
200
207
201
- class NavMountWorker extends NavCard {
202
- constructor ( options ) {
203
- super ( )
208
+ class NavMountWorker {
209
+ constructor ( borrowedContext , options ) {
210
+ this . $this = borrowedContext
204
211
this . options = options
205
212
}
206
213
207
214
mount ( ) {
208
- const DEFAULT_ACTIVE = ! this . _defaultAPI ( this . options . defaultOptions ) . activate ( )
209
- const DRAWER_ACTIVE = ! this . _drawerAPI ( this . options . drawerOptions ) . activate ( )
210
- const HASH_ACTIVE = ! this . _hashAPI ( this . options . hashOptions ) . activate ( )
215
+ const DEFAULT_ACTIVE = ! this . $this . _defaultAPI ( this . options . defaultOptions ) . activate ( )
216
+ const DRAWER_ACTIVE = ! this . $this . _drawerAPI ( this . options . drawerOptions ) . activate ( )
217
+ const HASH_ACTIVE = ! this . $this . _hashAPI ( this . options . hashOptions ) . activate ( )
211
218
return new Promise ( ( resolve , reject ) => {
212
219
if ( ! ( DEFAULT_ACTIVE && DRAWER_ACTIVE && HASH_ACTIVE ) ) {
213
220
reject ( new Error ( 'one or more services could not activate' ) )
214
221
return
215
222
}
216
- resolve ( new NavStateEvent ( this . State ) )
223
+ resolve ( new NavStateEvent ( this . $this , this . $this . State ) )
217
224
} )
218
225
}
219
226
220
227
unmount ( ) {
221
- this . SheetService . forceDeactivate ( )
222
- this . Drawer . deactivate ( )
223
- this . PopService . deactivate ( )
228
+ this . $this . SheetService . forceDeactivate ( )
229
+ this . $this . Drawer . deactivate ( )
230
+ this . $this . PopService . deactivate ( )
224
231
}
225
232
226
233
toString ( ) {
@@ -230,14 +237,15 @@ class NavMountWorker extends NavCard {
230
237
231
238
class NavStateEvent {
232
239
events = [ NAVSTATE_EVENTS . show , NAVSTATE_EVENTS . hide ]
233
- constructor ( state ) {
240
+ constructor ( $this , state ) {
241
+ this . $this = $this
234
242
this . _State = state
235
243
}
236
- on ( event , handle ) {
244
+ on ( event , handle = ( ) => false ) {
237
245
if ( ! ( this . events . indexOf ( event ) + 1 ) ) {
238
246
throw new Error ( `unknown event '${ event } '` )
239
247
}
240
- this . _State [ `on${ event } ` ] = handle
248
+ this . _State [ `on${ event } ` ] = handle . bind ( this . $this )
241
249
}
242
250
off ( event ) {
243
251
if ( ! ( this . events . indexOf ( event ) + 1 ) ) {
0 commit comments