11( function ( $ ) {
22var version = '1.4.12' ,
3+ optionOverrides = { } ,
34 defaults = {
45 exclude : [ ] ,
56 excludeWithin :[ ] ,
@@ -86,8 +87,21 @@ $.fn.extend({
8687 return this . pushStack ( scrl ) ;
8788 } ,
8889
89- smoothScroll : function ( options ) {
90+ smoothScroll : function ( options , extra ) {
9091 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+
91105 var opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options ) ,
92106 locationPath = $ . smoothScroll . filterPath ( location . pathname ) ;
93107
@@ -96,16 +110,17 @@ $.fn.extend({
96110 . bind ( 'click.smoothscroll' , function ( event ) {
97111 var link = this ,
98112 $link = $ ( this ) ,
113+ thisOpts = $ . extend ( { } , opts , $link . data ( 'ssOpts' ) || { } ) ,
99114 exclude = opts . exclude ,
100- excludeWithin = opts . excludeWithin ,
115+ excludeWithin = thisOpts . excludeWithin ,
101116 elCounter = 0 , ewlCounter = 0 ,
102117 include = true ,
103118 clickOpts = { } ,
104119 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 ,
106121 thisHash = escapeSelector ( link . hash ) ;
107122
108- if ( ! opts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
123+ if ( ! thisOpts . scrollTarget && ( ! hostMatch || ! pathMatch || ! thisHash ) ) {
109124 include = false ;
110125 } else {
111126 while ( include && elCounter < exclude . length ) {
@@ -122,15 +137,14 @@ $.fn.extend({
122137
123138 if ( include ) {
124139
125- if ( opts . preventDefault ) {
140+ if ( thisOpts . preventDefault ) {
126141 event . preventDefault ( ) ;
127142 }
128143
129- $ . extend ( clickOpts , opts , {
130- scrollTarget : opts . scrollTarget || thisHash ,
144+ $ . extend ( clickOpts , thisOpts , {
145+ scrollTarget : thisOpts . scrollTarget || thisHash ,
131146 link : link
132147 } ) ;
133-
134148 $ . smoothScroll ( clickOpts ) ;
135149 }
136150 } ) ;
@@ -140,6 +154,9 @@ $.fn.extend({
140154} ) ;
141155
142156$ . smoothScroll = function ( options , px ) {
157+ if ( options === 'options' && typeof px === 'object' ) {
158+ return $ . extend ( optionOverrides , px ) ;
159+ }
143160 var opts , $scroller , scrollTargetOffset , speed ,
144161 scrollerOffset = 0 ,
145162 offPos = 'offset' ,
@@ -148,12 +165,11 @@ $.smoothScroll = function(options, px) {
148165 aniOpts = { } ,
149166 scrollprops = [ ] ;
150167
151-
152168 if ( typeof options === 'number' ) {
153- opts = $ . fn . smoothScroll . defaults ;
169+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , optionOverrides ) ;
154170 scrollTargetOffset = options ;
155171 } else {
156- opts = $ . extend ( { } , $ . fn . smoothScroll . defaults , options || { } ) ;
172+ opts = $ . extend ( { link : null } , $ . fn . smoothScroll . defaults , options || { } , optionOverrides ) ;
157173 if ( opts . scrollElement ) {
158174 offPos = 'position' ;
159175 if ( opts . scrollElement . css ( 'position' ) == 'static' ) {
@@ -162,7 +178,6 @@ $.smoothScroll = function(options, px) {
162178 }
163179 }
164180
165- opts = $ . extend ( { link : null } , opts ) ;
166181 scrollDir = opts . direction == 'left' ? 'scrollLeft' : scrollDir ;
167182
168183 if ( opts . scrollElement ) {
0 commit comments