@@ -17,17 +17,17 @@ const STATUS_ORIGINAL = 0; // The default status, locating at the original posit
1717const STATUS_RELEASED = 1 ; // The released status, locating at somewhere on document but not default one.
1818const STATUS_FIXED = 2 ; // The sticky status, locating fixed to the top or the bottom of screen.
1919
20- var TRANSFORM_PROP = 'transform' ;
20+ let TRANSFORM_PROP = 'transform' ;
2121
2222// global variable for all instances
23- var doc ;
24- var docBody ;
25- var docEl ;
26- var canEnableTransforms = true ; // Use transform by default, so no Sticky on lower-end browser when no Modernizr
27- var M ;
28- var scrollDelta = 0 ;
29- var win ;
30- var winHeight = - 1 ;
23+ let doc ;
24+ let docBody ;
25+ let docEl ;
26+ let canEnableTransforms = true ; // Use transform by default, so no Sticky on lower-end browser when no Modernizr
27+ let M ;
28+ let scrollDelta = 0 ;
29+ let win ;
30+ let winHeight = - 1 ;
3131
3232class Sticky extends Component {
3333 constructor ( props , context ) {
@@ -81,13 +81,13 @@ class Sticky extends Component {
8181 if ( ! target ) {
8282 return - 1 ;
8383 }
84- var rect = target . getBoundingClientRect ( ) ;
84+ const rect = target . getBoundingClientRect ( ) ;
8585 return this . scrollTop + rect . bottom ;
8686 }
8787
8888 getBottomBoundary ( bottomBoundary ) {
8989 // a bottomBoundary can be provided to avoid reading from the props
90- var boundary = bottomBoundary || this . props . bottomBoundary ;
90+ let boundary = bottomBoundary || this . props . bottomBoundary ;
9191
9292 // TODO, bottomBoundary was an object, depricate it later.
9393 if ( typeof boundary === 'object' ) {
@@ -135,18 +135,18 @@ class Sticky extends Component {
135135 return ;
136136 }
137137
138- var outerRect = this . outerElement . getBoundingClientRect ( ) ;
139- var innerRect = this . innerElement . getBoundingClientRect ( ) ;
138+ const outerRect = this . outerElement . getBoundingClientRect ( ) ;
139+ const innerRect = this . innerElement . getBoundingClientRect ( ) ;
140140
141- var width = outerRect . width || outerRect . right - outerRect . left ;
142- var height = innerRect . height || innerRect . bottom - innerRect . top ;
143- var outerY = outerRect . top + this . scrollTop ;
141+ const width = outerRect . width || outerRect . right - outerRect . left ;
142+ const height = innerRect . height || innerRect . bottom - innerRect . top ;
143+ const outerY = outerRect . top + this . scrollTop ;
144144
145145 this . setState ( {
146146 top : this . getTopPosition ( options . top ) ,
147147 bottom : Math . min ( this . state . top + height , winHeight ) ,
148- width : width ,
149- height : height ,
148+ width,
149+ height,
150150 x : outerRect . left ,
151151 y : outerY ,
152152 bottomBoundary : this . getBottomBoundary ( options . bottomBoundary ) ,
@@ -276,7 +276,8 @@ class Sticky extends Component {
276276 // This case only happens when Sticky's bottom sticks to the screen bottom and
277277 // its height gets changed. Sticky should be in RELEASE status and update its
278278 // sticky bottom by calculating how much height it changed.
279- var deltaHeight = pos + height - this . state . bottom ;
279+ const deltaHeight =
280+ pos + height - this . state . bottom ;
280281 this . stickyBottom = bottom - delta + deltaHeight ;
281282 this . stickyTop = this . stickyBottom - height ;
282283 } else {
@@ -338,7 +339,7 @@ class Sticky extends Component {
338339 }
339340
340341 componentWillUnmount ( ) {
341- var subscribers = this . subscribers || [ ] ;
342+ const subscribers = this . subscribers || [ ] ;
342343 for ( var i = subscribers . length - 1 ; i >= 0 ; i -- ) {
343344 this . subscribers [ i ] . unsubscribe ( ) ;
344345 }
@@ -385,7 +386,7 @@ class Sticky extends Component {
385386 }
386387
387388 translate ( style , pos ) {
388- var enableTransforms =
389+ const enableTransforms =
389390 canEnableTransforms && this . props . enableTransforms ;
390391 if ( enableTransforms && this . state . activated ) {
391392 style [ TRANSFORM_PROP ] =
@@ -407,12 +408,12 @@ class Sticky extends Component {
407408
408409 render ( ) {
409410 // TODO, "overflow: auto" prevents collapse, need a good way to get children height
410- var innerStyle = {
411+ const innerStyle = {
411412 position : this . state . status === STATUS_FIXED ? 'fixed' : 'relative' ,
412413 top : this . state . status === STATUS_FIXED ? '0px' : '' ,
413414 zIndex : this . props . innerZ ,
414415 } ;
415- var outerStyle = { } ;
416+ const outerStyle = { } ;
416417
417418 // always use translate3d to enhance the performance
418419 this . translate ( innerStyle , this . state . pos ) ;
@@ -421,7 +422,7 @@ class Sticky extends Component {
421422 outerStyle . height = this . state . height + 'px' ;
422423 }
423424
424- var outerClasses = classNames (
425+ const outerClasses = classNames (
425426 'sticky-outer-wrapper' ,
426427 this . props . className ,
427428 {
@@ -431,7 +432,7 @@ class Sticky extends Component {
431432 }
432433 ) ;
433434
434- var innerClasses = classNames (
435+ const innerClasses = classNames (
435436 'sticky-inner-wrapper' ,
436437 this . props . innerClass ,
437438 {
@@ -440,7 +441,7 @@ class Sticky extends Component {
440441 }
441442 ) ;
442443
443- var children = this . props . children ;
444+ const children = this . props . children ;
444445
445446 return (
446447 < div
@@ -513,4 +514,4 @@ Sticky.STATUS_ORIGINAL = STATUS_ORIGINAL;
513514Sticky . STATUS_RELEASED = STATUS_RELEASED ;
514515Sticky . STATUS_FIXED = STATUS_FIXED ;
515516
516- module . exports = Sticky ;
517+ export default Sticky ;
0 commit comments