1
1
( function ( $ ) {
2
2
var version = '1.4.12' ,
3
+ optionOverrides = { } ,
3
4
defaults = {
4
5
exclude : [ ] ,
5
6
excludeWithin :[ ] ,
@@ -86,8 +87,21 @@ $.fn.extend({
86
87
return this . pushStack ( scrl ) ;
87
88
} ,
88
89
89
- smoothScroll : function ( options ) {
90
+ smoothScroll : function ( options , extra ) {
90
91
options = options || { } ;
92
+
93
+ if ( options === 'options' ) {
94
+ if ( ! extra ) {
95
+ return this . first ( ) . data ( 'ssOpts' ) ;
96
+ }
97
+ return this . each ( function ( ) {
98
+ var $this = $ ( this ) ,
99
+ opts = $ . extend ( $this . data ( 'ssOpts' ) || { } , extra ) ;
100
+
101
+ $ ( this ) . data ( 'ssOpts' , opts ) ;
102
+ } ) ;
103
+ }
104
+
91
105
var opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options ) ,
92
106
locationPath = $ . smoothScroll . filterPath ( location . pathname ) ;
93
107
@@ -96,16 +110,17 @@ $.fn.extend({
96
110
. bind ( 'click.smoothscroll' , function ( event ) {
97
111
var link = this ,
98
112
$link = $ ( this ) ,
113
+ thisOpts = $ . extend ( { } , opts , $link . data ( 'ssOpts' ) || { } ) ,
99
114
exclude = opts . exclude ,
100
- excludeWithin = opts . excludeWithin ,
115
+ excludeWithin = thisOpts . excludeWithin ,
101
116
elCounter = 0 , ewlCounter = 0 ,
102
117
include = true ,
103
118
clickOpts = { } ,
104
119
hostMatch = ( ( location . hostname === link . hostname ) || ! link . hostname ) ,
105
- pathMatch = opts . scrollTarget || ( $ . smoothScroll . filterPath ( link . pathname ) || locationPath ) === locationPath ,
120
+ pathMatch = thisOpts . scrollTarget || ( $ . smoothScroll . filterPath ( link . pathname ) || locationPath ) === locationPath ,
106
121
thisHash = escapeSelector ( link . hash ) ;
107
122
108
- if ( ! opts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
123
+ if ( ! thisOpts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
109
124
include = false ;
110
125
} else {
111
126
while ( include && elCounter < exclude . length ) {
@@ -122,15 +137,14 @@ $.fn.extend({
122
137
123
138
if ( include ) {
124
139
125
- if ( opts . preventDefault ) {
140
+ if ( thisOpts . preventDefault ) {
126
141
event . preventDefault ( ) ;
127
142
}
128
143
129
- $ . extend ( clickOpts , opts , {
130
- scrollTarget : opts . scrollTarget || thisHash ,
144
+ $ . extend ( clickOpts , thisOpts , {
145
+ scrollTarget : thisOpts . scrollTarget || thisHash ,
131
146
link : link
132
147
} ) ;
133
-
134
148
$ . smoothScroll ( clickOpts ) ;
135
149
}
136
150
} ) ;
@@ -140,6 +154,9 @@ $.fn.extend({
140
154
} ) ;
141
155
142
156
$ . smoothScroll = function ( options , px ) {
157
+ if ( options === 'options' && typeof px === 'object' ) {
158
+ return $ . extend ( optionOverrides , px ) ;
159
+ }
143
160
var opts , $scroller , scrollTargetOffset , speed ,
144
161
scrollerOffset = 0 ,
145
162
offPos = 'offset' ,
@@ -148,12 +165,11 @@ $.smoothScroll = function(options, px) {
148
165
aniOpts = { } ,
149
166
scrollprops = [ ] ;
150
167
151
-
152
168
if ( typeof options === 'number' ) {
153
- opts = $ . fn . smoothScroll . defaults ;
169
+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , optionOverrides ) ;
154
170
scrollTargetOffset = options ;
155
171
} else {
156
- opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options || { } ) ;
172
+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , options || { } , optionOverrides ) ;
157
173
if ( opts . scrollElement ) {
158
174
offPos = 'position' ;
159
175
if ( opts . scrollElement . css ( 'position' ) == 'static' ) {
@@ -162,7 +178,6 @@ $.smoothScroll = function(options, px) {
162
178
}
163
179
}
164
180
165
- opts = $ . extend ( { link : null } , opts ) ;
166
181
scrollDir = opts . direction == 'left' ? 'scrollLeft' : scrollDir ;
167
182
168
183
if ( opts . scrollElement ) {
0 commit comments