1
1
/*!
2
- * Smooth Scroll - v1.4.12 - 2013-09-19
2
+ * Smooth Scroll - v1.4.13 - 2013-11-02
3
3
* https://github.com/kswedberg/jquery-smooth-scroll
4
4
* Copyright (c) 2013 Karl Swedberg
5
5
* Licensed MIT (https://github.com/kswedberg/jquery-smooth-scroll/blob/master/LICENSE-MIT)
6
6
*/
7
7
8
8
( function ( $ ) {
9
- var version = '1.4.12' ,
9
+ var version = '1.4.13' ,
10
+ optionOverrides = { } ,
10
11
defaults = {
11
12
exclude : [ ] ,
12
13
excludeWithin :[ ] ,
@@ -43,6 +44,7 @@ var version = '1.4.12',
43
44
var scrollable = [ ] ,
44
45
scrolled = false ,
45
46
dir = opts . dir && opts . dir == 'left' ? 'scrollLeft' : 'scrollTop' ;
47
+
46
48
this . each ( function ( ) {
47
49
48
50
if ( this == document || this == window ) { return ; }
@@ -92,8 +94,21 @@ $.fn.extend({
92
94
return this . pushStack ( scrl ) ;
93
95
} ,
94
96
95
- smoothScroll : function ( options ) {
97
+ smoothScroll : function ( options , extra ) {
96
98
options = options || { } ;
99
+
100
+ if ( options === 'options' ) {
101
+ if ( ! extra ) {
102
+ return this . first ( ) . data ( 'ssOpts' ) ;
103
+ }
104
+ return this . each ( function ( ) {
105
+ var $this = $ ( this ) ,
106
+ opts = $ . extend ( $this . data ( 'ssOpts' ) || { } , extra ) ;
107
+
108
+ $ ( this ) . data ( 'ssOpts' , opts ) ;
109
+ } ) ;
110
+ }
111
+
97
112
var opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options ) ,
98
113
locationPath = $ . smoothScroll . filterPath ( location . pathname ) ;
99
114
@@ -102,16 +117,17 @@ $.fn.extend({
102
117
. bind ( 'click.smoothscroll' , function ( event ) {
103
118
var link = this ,
104
119
$link = $ ( this ) ,
120
+ thisOpts = $ . extend ( { } , opts , $link . data ( 'ssOpts' ) || { } ) ,
105
121
exclude = opts . exclude ,
106
- excludeWithin = opts . excludeWithin ,
122
+ excludeWithin = thisOpts . excludeWithin ,
107
123
elCounter = 0 , ewlCounter = 0 ,
108
124
include = true ,
109
125
clickOpts = { } ,
110
126
hostMatch = ( ( location . hostname === link . hostname ) || ! link . hostname ) ,
111
- pathMatch = opts . scrollTarget || ( $ . smoothScroll . filterPath ( link . pathname ) || locationPath ) === locationPath ,
127
+ pathMatch = thisOpts . scrollTarget || ( $ . smoothScroll . filterPath ( link . pathname ) || locationPath ) === locationPath ,
112
128
thisHash = escapeSelector ( link . hash ) ;
113
129
114
- if ( ! opts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
130
+ if ( ! thisOpts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
115
131
include = false ;
116
132
} else {
117
133
while ( include && elCounter < exclude . length ) {
@@ -128,15 +144,14 @@ $.fn.extend({
128
144
129
145
if ( include ) {
130
146
131
- if ( opts . preventDefault ) {
147
+ if ( thisOpts . preventDefault ) {
132
148
event . preventDefault ( ) ;
133
149
}
134
150
135
- $ . extend ( clickOpts , opts , {
136
- scrollTarget : opts . scrollTarget || thisHash ,
151
+ $ . extend ( clickOpts , thisOpts , {
152
+ scrollTarget : thisOpts . scrollTarget || thisHash ,
137
153
link : link
138
154
} ) ;
139
-
140
155
$ . smoothScroll ( clickOpts ) ;
141
156
}
142
157
} ) ;
@@ -146,6 +161,9 @@ $.fn.extend({
146
161
} ) ;
147
162
148
163
$ . smoothScroll = function ( options , px ) {
164
+ if ( options === 'options' && typeof px === 'object' ) {
165
+ return $ . extend ( optionOverrides , px ) ;
166
+ }
149
167
var opts , $scroller , scrollTargetOffset , speed ,
150
168
scrollerOffset = 0 ,
151
169
offPos = 'offset' ,
@@ -154,12 +172,11 @@ $.smoothScroll = function(options, px) {
154
172
aniOpts = { } ,
155
173
scrollprops = [ ] ;
156
174
157
-
158
175
if ( typeof options === 'number' ) {
159
- opts = $ . fn . smoothScroll . defaults ;
176
+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , optionOverrides ) ;
160
177
scrollTargetOffset = options ;
161
178
} else {
162
- opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options || { } ) ;
179
+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , options || { } , optionOverrides ) ;
163
180
if ( opts . scrollElement ) {
164
181
offPos = 'position' ;
165
182
if ( opts . scrollElement . css ( 'position' ) == 'static' ) {
@@ -168,7 +185,6 @@ $.smoothScroll = function(options, px) {
168
185
}
169
186
}
170
187
171
- opts = $ . extend ( { link : null } , opts ) ;
172
188
scrollDir = opts . direction == 'left' ? 'scrollLeft' : scrollDir ;
173
189
174
190
if ( opts . scrollElement ) {
0 commit comments