File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 20
20
// only use if you want to override default behavior
21
21
scrollTarget : null ,
22
22
23
+ // automatically focus the target element after scrolling to it
24
+ autoFocus : false ,
25
+
23
26
// fn(opts) function to be called before scrolling occurs.
24
27
// `this` is the element(s) being scrolled
25
28
beforeScroll : function ( ) { } ,
106
109
} ;
107
110
108
111
var rRelative = / ^ ( [ \- \+ ] = ) ( \d + ) / ;
112
+
109
113
$ . fn . extend ( {
110
114
scrollable : function ( dir ) {
111
115
var scrl = getScrollable . call ( this , { dir : dir } ) ;
218
222
return explicit ;
219
223
} ;
220
224
225
+ var onAfterScroll = function ( opts ) {
226
+ var $tgt = $ ( opts . scrollTarget ) ;
227
+
228
+ if ( opts . autoFocus && $tgt . length ) {
229
+ $tgt [ 0 ] . focus ( ) ;
230
+
231
+ if ( ! $tgt . is ( document . activeElement ) ) {
232
+ $tgt . prop ( { tabIndex : - 1 } ) ;
233
+ $tgt [ 0 ] . focus ( ) ;
234
+ }
235
+ }
236
+
237
+ opts . afterScroll . call ( opts . link , opts ) ;
238
+ } ;
239
+
221
240
$ . smoothScroll = function ( options , px ) {
222
241
if ( options === 'options' && typeof px === 'object' ) {
223
242
return $ . extend ( optionOverrides , px ) ;
288
307
duration : speed ,
289
308
easing : opts . easing ,
290
309
complete : function ( ) {
291
- opts . afterScroll . call ( opts . link , opts ) ;
310
+ onAfterScroll ( opts ) ;
292
311
}
293
312
} ;
294
313
299
318
if ( $scroller . length ) {
300
319
$scroller . stop ( ) . animate ( aniProps , aniOpts ) ;
301
320
} else {
302
- opts . afterScroll . call ( opts . link , opts ) ;
321
+ onAfterScroll ( opts ) ;
303
322
}
304
323
} ;
305
324
You can’t perform that action at this time.
0 commit comments