@@ -17,6 +17,22 @@ define([
17
17
stickyClass : '_sticky'
18
18
} ,
19
19
20
+ _optionToNumber ( option ) {
21
+ var value = this . options [ option ] || 0 ;
22
+ if ( typeof value === 'function' ) {
23
+ value = this . options [ option ] ( ) ;
24
+ }
25
+
26
+ var converted = Number ( value ) ;
27
+ if ( isNaN ( converted ) ) {
28
+ throw Error (
29
+ 'sticky: Could not convert supplied option "' +
30
+ option + '" to Number from "' + value + '"'
31
+ ) ;
32
+ }
33
+ return converted ;
34
+ } ,
35
+
20
36
/**
21
37
* Bind handlers to scroll event
22
38
* @private
@@ -43,25 +59,15 @@ define([
43
59
isStatic = this . element . css ( 'position' ) === 'static' ;
44
60
45
61
if ( ! isStatic && this . element . is ( ':visible' ) ) {
46
- offset = $ ( document ) . scrollTop ( ) - this . parentOffset ;
47
-
48
- if ( typeof this . options . spacingTop === 'function' ) {
49
- offset += this . options . spacingTop ( ) ;
50
- } else {
51
- offset += this . options . spacingTop ;
52
- }
62
+ offset = $ ( document ) . scrollTop ( )
63
+ - this . parentOffset
64
+ + this . _optionToNumber ( 'spacingTop' ) ;
53
65
54
66
offset = Math . max ( 0 , Math . min ( offset , this . maxOffset ) ) ;
55
67
56
68
var stuck = this . element . hasClass ( this . options . stickyClass ) ;
57
69
if ( offset && this . options . offsetTop && ! stuck ) {
58
- var offsetTop = 0 ;
59
- if ( typeof this . options . offsetTop === 'function' ) {
60
- offsetTop = this . options . offsetTop ( ) ;
61
- } else {
62
- offsetTop = this . options . offsetTop ;
63
- }
64
-
70
+ var offsetTop = this . _optionToNumber ( 'offsetTop' ) ;
65
71
if ( offset < offsetTop ) {
66
72
offset = 0 ;
67
73
}
0 commit comments