@@ -25,13 +25,13 @@ var version = '1.4.2',
25
25
scrollElement : null , // jQuery set of elements you wish to scroll (for $.smoothScroll).
26
26
// if null (default), $('html, body').firstScrollable() is used.
27
27
scrollTarget : null , // only use if you want to override default behavior
28
- beforeScroll : null , // fn(opts) function to be called before scrolling occurs. "this" is the element(s) being scrolled
29
- afterScroll : null , // fn(opts) function to be called after scrolling occurs. "this" is the triggering element
28
+ beforeScroll : function ( ) { } , // fn(opts) function to be called before scrolling occurs. "this" is the element(s) being scrolled
29
+ afterScroll : function ( ) { } , // fn(opts) function to be called after scrolling occurs. "this" is the triggering element
30
30
easing : 'swing' ,
31
31
speed : 400
32
32
} ,
33
33
34
- locationPath = filterPath ( location . pathname ) ,
34
+ locationPath = $ . smoothScroll . filterPath ( location . pathname ) ,
35
35
getScrollable = function ( opts ) {
36
36
var scrollable = [ ] ,
37
37
scrolled = false ,
@@ -81,7 +81,7 @@ $.fn.extend({
81
81
82
82
var clickOpts = { } , link = this , $link = $ ( this ) ,
83
83
hostMatch = ( ( location . hostname === link . hostname ) || ! link . hostname ) ,
84
- pathMatch = opts . scrollTarget || ( filterPath ( link . pathname ) || locationPath ) === locationPath ,
84
+ pathMatch = opts . scrollTarget || ( $ . smoothScroll . filterPath ( link . pathname ) || locationPath ) === locationPath ,
85
85
thisHash = escapeSelector ( link . hash ) ,
86
86
include = true ;
87
87
@@ -159,41 +159,36 @@ $.smoothScroll = function(options, px) {
159
159
160
160
aniprops [ scrollDir ] = scrollTargetOffset + scrollerOffset + opts . offset ;
161
161
162
- if ( $ . isFunction ( opts . beforeScroll ) ) {
163
- opts . beforeScroll . call ( $scroller , opts ) ;
164
- }
162
+ opts . beforeScroll . call ( $scroller , opts ) ;
165
163
166
164
if ( useScrollTo ) {
167
165
scrollprops = ( opts . direction == 'left' ) ? [ aniprops [ scrollDir ] , 0 ] : [ 0 , aniprops [ scrollDir ] ] ;
168
166
window . scrollTo . apply ( window , scrollprops ) ;
167
+ opts . afterScroll . call ( opts . link , opts ) ;
168
+
169
169
} else {
170
170
$scroller . animate ( aniprops ,
171
171
{
172
172
duration : opts . speed ,
173
173
easing : opts . easing ,
174
174
complete : function ( ) {
175
- if ( opts . afterScroll && $ . isFunction ( opts . afterScroll ) ) {
176
- opts . afterScroll . call ( opts . link , opts ) ;
177
- }
175
+ opts . afterScroll . call ( opts . link , opts ) ;
178
176
}
179
177
} ) ;
180
178
}
181
179
182
180
} ;
183
181
184
182
$ . smoothScroll . version = version ;
185
-
186
- // default options
187
- $ . fn . smoothScroll . defaults = defaults ;
188
-
189
-
190
- // private function
191
- function filterPath ( string ) {
183
+ $ . smoothScroll . filterPath = function ( string ) {
192
184
return string
193
185
. replace ( / ^ \/ / , '' )
194
186
. replace ( / ( i n d e x | d e f a u l t ) .[ a - z A - Z ] { 3 , 4 } $ / , '' )
195
187
. replace ( / \/ $ / , '' ) ;
196
- }
188
+ } ;
189
+
190
+ // default options
191
+ $ . fn . smoothScroll . defaults = defaults ;
197
192
198
193
function escapeSelector ( str ) {
199
194
return str . replace ( / ( : | \. ) / g, '\\$1' ) ;
0 commit comments