stickybits
Advanced tools
Comparing version 3.6.5 to 3.6.6
@@ -0,1 +1,6 @@ | ||
## [3.6.5](https://github.com/dollarshaveclub/stickybits/compare/3.6.4...3.6.5) (2019-03-31) | ||
## [3.6.4](https://github.com/dollarshaveclub/stickybits/compare/3.6.3...3.6.4) (2019-03-03) | ||
@@ -2,0 +7,0 @@ |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -73,3 +73,3 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
var o = typeof obj !== 'undefined' ? obj : {}; | ||
this.version = '3.6.5'; | ||
this.version = '3.6.6'; | ||
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser'; | ||
@@ -90,3 +90,3 @@ this.props = { | ||
/* | ||
define positionVal | ||
define positionVal after the setting of props, because definePosition looks at the props.useFixed | ||
---- | ||
@@ -104,4 +104,3 @@ - uses a computed (`.definePosition()`) | ||
noStyles = _this$props.noStyles, | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset, | ||
useStickyClasses = _this$props.useStickyClasses; | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset; | ||
var verticalPositionStyle = verticalPosition === 'top' && !noStyles ? stickyBitStickyOffset + "px" : ''; | ||
@@ -116,8 +115,5 @@ var positionStyle = positionVal !== 'fixed' ? positionVal : ''; | ||
el.style[verticalPosition] = verticalPositionStyle; | ||
el.style.position = positionStyle; | ||
el.style.position = positionStyle; // instances are an array of objects | ||
if (positionVal === 'fixed' || useStickyClasses) { | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
@@ -190,13 +186,17 @@ } | ||
}; | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
if (props.positionVal === 'fixed' || props.useStickyClasses) { | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
se.addEventListener('scroll', item.stateContainer); | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
se.addEventListener('scroll', item.stateContainer); | ||
} | ||
return item; | ||
@@ -444,3 +444,7 @@ } | ||
var instance = this.instances[i]; | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
if (instance.stateContainer) { | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
} | ||
this.removeInstance(instance); | ||
@@ -447,0 +451,0 @@ } |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -8,2 +8,2 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
**/ | ||
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";var s=function(){function t(t,s){var e=void 0!==s?s:{};this.version="3.6.5",this.userAgent=window.navigator.userAgent||"no `userAgent` provided by the browser",this.props={customStickyChangeNumber:e.customStickyChangeNumber||null,noStyles:e.noStyles||!1,stickyBitStickyOffset:e.stickyBitStickyOffset||0,parentClass:e.parentClass||"js-stickybit-parent",scrollEl:"string"==typeof e.scrollEl?document.querySelector(e.scrollEl):e.scrollEl||window,stickyClass:e.stickyClass||"js-is-sticky",stuckClass:e.stuckClass||"js-is-stuck",stickyChangeClass:e.stickyChangeClass||"js-is-sticky--change",useStickyClasses:e.useStickyClasses||!1,useFixed:e.useFixed||!1,useGetBoundingClientRect:e.useGetBoundingClientRect||!1,verticalPosition:e.verticalPosition||"top"},this.props.positionVal=this.definePosition()||"fixed",this.instances=[];var i=this.props,n=i.positionVal,o=i.verticalPosition,a=i.noStyles,r=i.stickyBitStickyOffset,l=i.useStickyClasses,c="top"!==o||a?"":r+"px",f="fixed"!==n?n:"";this.els="string"==typeof t?document.querySelectorAll(t):t,"length"in this.els||(this.els=[this.els]);for(var u=0;u<this.els.length;u++){var p=this.els[u];p.style[o]=c,p.style.position=f,("fixed"===n||l)&&this.instances.push(this.addInstance(p,this.props))}}var s=t.prototype;return s.definePosition=function(){var t;if(this.props.useFixed)t="fixed";else{for(var s=["","-o-","-webkit-","-moz-","-ms-"],e=document.head.style,i=0;i<s.length;i+=1)e.position=s[i]+"sticky";t=e.position?e.position:"fixed",e.position=""}return t},s.addInstance=function(t,s){var e=this,i={el:t,parent:t.parentNode,props:s};this.isWin=this.props.scrollEl===window;var n=this.isWin?window:this.getClosestParent(i.el,i.props.scrollEl);return this.computeScrollOffsets(i),i.parent.className+=" "+s.parentClass,i.state="default",i.stateContainer=function(){return e.manageState(i)},n.addEventListener("scroll",i.stateContainer),i},s.getClosestParent=function(t,s){var e=s,i=t;if(i.parentElement===e)return e;for(;i.parentElement!==e;)i=i.parentElement;return e},s.getTopPosition=function(t){if(this.props.useGetBoundingClientRect)return t.getBoundingClientRect().top+(this.props.scrollEl.pageYOffset||document.documentElement.scrollTop);for(var s=0;s=t.offsetTop+s,t=t.offsetParent;);return s},s.computeScrollOffsets=function(t){var s=t,e=s.props,i=s.el,n=s.parent,o=!this.isWin&&"fixed"===e.positionVal,a="bottom"!==e.verticalPosition,r=o?this.getTopPosition(e.scrollEl):0,l=o?this.getTopPosition(n)-r:this.getTopPosition(n),c=null!==e.customStickyChangeNumber?e.customStickyChangeNumber:i.offsetHeight,f=l+n.offsetHeight;s.offset=r+e.stickyBitStickyOffset,s.stickyStart=a?l-s.offset:0,s.stickyChange=s.stickyStart+c,s.stickyStop=a?f-(i.offsetHeight+s.offset):f-window.innerHeight},s.toggleClasses=function(t,s,e){var i=t,n=i.className.split(" ");e&&-1===n.indexOf(e)&&n.push(e);var o=n.indexOf(s);-1!==o&&n.splice(o,1),i.className=n.join(" ")},s.manageState=function(t){var s=t,e=s.el,i=s.props,n=s.state,o=s.stickyStart,a=s.stickyChange,r=s.stickyStop,l=e.style,c=i.noStyles,f=i.positionVal,u=i.scrollEl,p=i.stickyClass,h=i.stickyChangeClass,d=i.stuckClass,y=i.verticalPosition,k="bottom"!==y,g=function(t){t()},m=this.isWin&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)||g,v=this.toggleClasses,C=this.isWin?window.scrollY||window.pageYOffset:u.scrollTop,w=k&&C<=o&&("sticky"===n||"stuck"===n),S=r<=C&&"sticky"===n;o<C&&C<r&&("default"===n||"stuck"===n)?(s.state="sticky",m(function(){v(e,d,p),l.position=f,c||(l.bottom="",l[y]=i.stickyBitStickyOffset+"px")})):w?(s.state="default",m(function(){v(e,p),v(e,d),"fixed"===f&&(l.position="")})):S&&(s.state="stuck",m(function(){v(e,p,d),"fixed"!==f||c||(l.top="",l.bottom="0",l.position="absolute")}));var b=a<=C&&C<=r;C<a/2||r<C?m(function(){v(e,h)}):b&&m(function(){v(e,"stub",h)})},s.update=function(t){void 0===t&&(t=null);for(var s=0;s<this.instances.length;s+=1){var e=this.instances[s];if(this.computeScrollOffsets(e),t)for(var i in t)e.props[i]=t[i]}return this},s.removeInstance=function(t){var s=t.el,e=t.props,i=this.toggleClasses;s.style.position="",s.style[e.verticalPosition]="",i(s,e.stickyClass),i(s,e.stuckClass),i(s.parentNode,e.parentClass)},s.cleanup=function(){for(var t=0;t<this.instances.length;t+=1){var s=this.instances[t];s.props.scrollEl.removeEventListener("scroll",s.stateContainer),this.removeInstance(s)}this.manageState=!1,this.instances=[]},t}();if("undefined"!=typeof window){var t=window.$||window.jQuery||window.Zepto;t&&(t.fn.stickybits=function(t){return new s(this,t)})}}); | ||
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";var s=function(){function t(t,s){var e=void 0!==s?s:{};this.version="3.6.6",this.userAgent=window.navigator.userAgent||"no `userAgent` provided by the browser",this.props={customStickyChangeNumber:e.customStickyChangeNumber||null,noStyles:e.noStyles||!1,stickyBitStickyOffset:e.stickyBitStickyOffset||0,parentClass:e.parentClass||"js-stickybit-parent",scrollEl:"string"==typeof e.scrollEl?document.querySelector(e.scrollEl):e.scrollEl||window,stickyClass:e.stickyClass||"js-is-sticky",stuckClass:e.stuckClass||"js-is-stuck",stickyChangeClass:e.stickyChangeClass||"js-is-sticky--change",useStickyClasses:e.useStickyClasses||!1,useFixed:e.useFixed||!1,useGetBoundingClientRect:e.useGetBoundingClientRect||!1,verticalPosition:e.verticalPosition||"top"},this.props.positionVal=this.definePosition()||"fixed",this.instances=[];var i=this.props,n=i.positionVal,o=i.verticalPosition,a=i.noStyles,r=i.stickyBitStickyOffset,l="top"!==o||a?"":r+"px",c="fixed"!==n?n:"";this.els="string"==typeof t?document.querySelectorAll(t):t,"length"in this.els||(this.els=[this.els]);for(var f=0;f<this.els.length;f++){var u=this.els[f];u.style[o]=l,u.style.position=c,this.instances.push(this.addInstance(u,this.props))}}var s=t.prototype;return s.definePosition=function(){var t;if(this.props.useFixed)t="fixed";else{for(var s=["","-o-","-webkit-","-moz-","-ms-"],e=document.head.style,i=0;i<s.length;i+=1)e.position=s[i]+"sticky";t=e.position?e.position:"fixed",e.position=""}return t},s.addInstance=function(t,s){var e=this,i={el:t,parent:t.parentNode,props:s};if("fixed"===s.positionVal||s.useStickyClasses){this.isWin=this.props.scrollEl===window;var n=this.isWin?window:this.getClosestParent(i.el,i.props.scrollEl);this.computeScrollOffsets(i),i.parent.className+=" "+s.parentClass,i.state="default",i.stateContainer=function(){return e.manageState(i)},n.addEventListener("scroll",i.stateContainer)}return i},s.getClosestParent=function(t,s){var e=s,i=t;if(i.parentElement===e)return e;for(;i.parentElement!==e;)i=i.parentElement;return e},s.getTopPosition=function(t){if(this.props.useGetBoundingClientRect)return t.getBoundingClientRect().top+(this.props.scrollEl.pageYOffset||document.documentElement.scrollTop);for(var s=0;s=t.offsetTop+s,t=t.offsetParent;);return s},s.computeScrollOffsets=function(t){var s=t,e=s.props,i=s.el,n=s.parent,o=!this.isWin&&"fixed"===e.positionVal,a="bottom"!==e.verticalPosition,r=o?this.getTopPosition(e.scrollEl):0,l=o?this.getTopPosition(n)-r:this.getTopPosition(n),c=null!==e.customStickyChangeNumber?e.customStickyChangeNumber:i.offsetHeight,f=l+n.offsetHeight;s.offset=r+e.stickyBitStickyOffset,s.stickyStart=a?l-s.offset:0,s.stickyChange=s.stickyStart+c,s.stickyStop=a?f-(i.offsetHeight+s.offset):f-window.innerHeight},s.toggleClasses=function(t,s,e){var i=t,n=i.className.split(" ");e&&-1===n.indexOf(e)&&n.push(e);var o=n.indexOf(s);-1!==o&&n.splice(o,1),i.className=n.join(" ")},s.manageState=function(t){var s=t,e=s.el,i=s.props,n=s.state,o=s.stickyStart,a=s.stickyChange,r=s.stickyStop,l=e.style,c=i.noStyles,f=i.positionVal,u=i.scrollEl,p=i.stickyClass,h=i.stickyChangeClass,d=i.stuckClass,y=i.verticalPosition,k="bottom"!==y,g=function(t){t()},m=this.isWin&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)||g,v=this.toggleClasses,C=this.isWin?window.scrollY||window.pageYOffset:u.scrollTop,w=k&&C<=o&&("sticky"===n||"stuck"===n),S=r<=C&&"sticky"===n;o<C&&C<r&&("default"===n||"stuck"===n)?(s.state="sticky",m(function(){v(e,d,p),l.position=f,c||(l.bottom="",l[y]=i.stickyBitStickyOffset+"px")})):w?(s.state="default",m(function(){v(e,p),v(e,d),"fixed"===f&&(l.position="")})):S&&(s.state="stuck",m(function(){v(e,p,d),"fixed"!==f||c||(l.top="",l.bottom="0",l.position="absolute")}));var b=a<=C&&C<=r;C<a/2||r<C?m(function(){v(e,h)}):b&&m(function(){v(e,"stub",h)})},s.update=function(t){void 0===t&&(t=null);for(var s=0;s<this.instances.length;s+=1){var e=this.instances[s];if(this.computeScrollOffsets(e),t)for(var i in t)e.props[i]=t[i]}return this},s.removeInstance=function(t){var s=t.el,e=t.props,i=this.toggleClasses;s.style.position="",s.style[e.verticalPosition]="",i(s,e.stickyClass),i(s,e.stuckClass),i(s.parentNode,e.parentClass)},s.cleanup=function(){for(var t=0;t<this.instances.length;t+=1){var s=this.instances[t];s.stateContainer&&s.props.scrollEl.removeEventListener("scroll",s.stateContainer),this.removeInstance(s)}this.manageState=!1,this.instances=[]},t}();if("undefined"!=typeof window){var t=window.$||window.jQuery||window.Zepto;t&&(t.fn.stickybits=function(t){return new s(this,t)})}}); |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -68,3 +68,3 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
var o = typeof obj !== 'undefined' ? obj : {}; | ||
this.version = '3.6.5'; | ||
this.version = '3.6.6'; | ||
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser'; | ||
@@ -85,3 +85,3 @@ this.props = { | ||
/* | ||
define positionVal | ||
define positionVal after the setting of props, because definePosition looks at the props.useFixed | ||
---- | ||
@@ -99,4 +99,3 @@ - uses a computed (`.definePosition()`) | ||
noStyles = _this$props.noStyles, | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset, | ||
useStickyClasses = _this$props.useStickyClasses; | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset; | ||
var verticalPositionStyle = verticalPosition === 'top' && !noStyles ? stickyBitStickyOffset + "px" : ''; | ||
@@ -111,8 +110,5 @@ var positionStyle = positionVal !== 'fixed' ? positionVal : ''; | ||
el.style[verticalPosition] = verticalPositionStyle; | ||
el.style.position = positionStyle; | ||
el.style.position = positionStyle; // instances are an array of objects | ||
if (positionVal === 'fixed' || useStickyClasses) { | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
@@ -185,13 +181,17 @@ } | ||
}; | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
if (props.positionVal === 'fixed' || props.useStickyClasses) { | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
se.addEventListener('scroll', item.stateContainer); | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
se.addEventListener('scroll', item.stateContainer); | ||
} | ||
return item; | ||
@@ -439,3 +439,7 @@ } | ||
var instance = this.instances[i]; | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
if (instance.stateContainer) { | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
} | ||
this.removeInstance(instance); | ||
@@ -442,0 +446,0 @@ } |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -74,3 +74,3 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
var o = typeof obj !== 'undefined' ? obj : {}; | ||
this.version = '3.6.5'; | ||
this.version = '3.6.6'; | ||
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser'; | ||
@@ -91,3 +91,3 @@ this.props = { | ||
/* | ||
define positionVal | ||
define positionVal after the setting of props, because definePosition looks at the props.useFixed | ||
---- | ||
@@ -105,4 +105,3 @@ - uses a computed (`.definePosition()`) | ||
noStyles = _this$props.noStyles, | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset, | ||
useStickyClasses = _this$props.useStickyClasses; | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset; | ||
var verticalPositionStyle = verticalPosition === 'top' && !noStyles ? stickyBitStickyOffset + "px" : ''; | ||
@@ -117,8 +116,5 @@ var positionStyle = positionVal !== 'fixed' ? positionVal : ''; | ||
el.style[verticalPosition] = verticalPositionStyle; | ||
el.style.position = positionStyle; | ||
el.style.position = positionStyle; // instances are an array of objects | ||
if (positionVal === 'fixed' || useStickyClasses) { | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
@@ -191,13 +187,17 @@ } | ||
}; | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
if (props.positionVal === 'fixed' || props.useStickyClasses) { | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
se.addEventListener('scroll', item.stateContainer); | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
se.addEventListener('scroll', item.stateContainer); | ||
} | ||
return item; | ||
@@ -445,3 +445,7 @@ } | ||
var instance = this.instances[i]; | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
if (instance.stateContainer) { | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
} | ||
this.removeInstance(instance); | ||
@@ -448,0 +452,0 @@ } |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -8,2 +8,2 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
**/ | ||
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t=t||self).stickybits=s()}(this,function(){"use strict";var e=function(){function t(t,s){var e=void 0!==s?s:{};this.version="3.6.5",this.userAgent=window.navigator.userAgent||"no `userAgent` provided by the browser",this.props={customStickyChangeNumber:e.customStickyChangeNumber||null,noStyles:e.noStyles||!1,stickyBitStickyOffset:e.stickyBitStickyOffset||0,parentClass:e.parentClass||"js-stickybit-parent",scrollEl:"string"==typeof e.scrollEl?document.querySelector(e.scrollEl):e.scrollEl||window,stickyClass:e.stickyClass||"js-is-sticky",stuckClass:e.stuckClass||"js-is-stuck",stickyChangeClass:e.stickyChangeClass||"js-is-sticky--change",useStickyClasses:e.useStickyClasses||!1,useFixed:e.useFixed||!1,useGetBoundingClientRect:e.useGetBoundingClientRect||!1,verticalPosition:e.verticalPosition||"top"},this.props.positionVal=this.definePosition()||"fixed",this.instances=[];var i=this.props,n=i.positionVal,o=i.verticalPosition,r=i.noStyles,a=i.stickyBitStickyOffset,l=i.useStickyClasses,c="top"!==o||r?"":a+"px",u="fixed"!==n?n:"";this.els="string"==typeof t?document.querySelectorAll(t):t,"length"in this.els||(this.els=[this.els]);for(var f=0;f<this.els.length;f++){var p=this.els[f];p.style[o]=c,p.style.position=u,("fixed"===n||l)&&this.instances.push(this.addInstance(p,this.props))}}var s=t.prototype;return s.definePosition=function(){var t;if(this.props.useFixed)t="fixed";else{for(var s=["","-o-","-webkit-","-moz-","-ms-"],e=document.head.style,i=0;i<s.length;i+=1)e.position=s[i]+"sticky";t=e.position?e.position:"fixed",e.position=""}return t},s.addInstance=function(t,s){var e=this,i={el:t,parent:t.parentNode,props:s};this.isWin=this.props.scrollEl===window;var n=this.isWin?window:this.getClosestParent(i.el,i.props.scrollEl);return this.computeScrollOffsets(i),i.parent.className+=" "+s.parentClass,i.state="default",i.stateContainer=function(){return e.manageState(i)},n.addEventListener("scroll",i.stateContainer),i},s.getClosestParent=function(t,s){var e=s,i=t;if(i.parentElement===e)return e;for(;i.parentElement!==e;)i=i.parentElement;return e},s.getTopPosition=function(t){if(this.props.useGetBoundingClientRect)return t.getBoundingClientRect().top+(this.props.scrollEl.pageYOffset||document.documentElement.scrollTop);for(var s=0;s=t.offsetTop+s,t=t.offsetParent;);return s},s.computeScrollOffsets=function(t){var s=t,e=s.props,i=s.el,n=s.parent,o=!this.isWin&&"fixed"===e.positionVal,r="bottom"!==e.verticalPosition,a=o?this.getTopPosition(e.scrollEl):0,l=o?this.getTopPosition(n)-a:this.getTopPosition(n),c=null!==e.customStickyChangeNumber?e.customStickyChangeNumber:i.offsetHeight,u=l+n.offsetHeight;s.offset=a+e.stickyBitStickyOffset,s.stickyStart=r?l-s.offset:0,s.stickyChange=s.stickyStart+c,s.stickyStop=r?u-(i.offsetHeight+s.offset):u-window.innerHeight},s.toggleClasses=function(t,s,e){var i=t,n=i.className.split(" ");e&&-1===n.indexOf(e)&&n.push(e);var o=n.indexOf(s);-1!==o&&n.splice(o,1),i.className=n.join(" ")},s.manageState=function(t){var s=t,e=s.el,i=s.props,n=s.state,o=s.stickyStart,r=s.stickyChange,a=s.stickyStop,l=e.style,c=i.noStyles,u=i.positionVal,f=i.scrollEl,p=i.stickyClass,h=i.stickyChangeClass,d=i.stuckClass,y=i.verticalPosition,k="bottom"!==y,m=function(t){t()},g=this.isWin&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)||m,v=this.toggleClasses,C=this.isWin?window.scrollY||window.pageYOffset:f.scrollTop,S=k&&C<=o&&("sticky"===n||"stuck"===n),w=a<=C&&"sticky"===n;o<C&&C<a&&("default"===n||"stuck"===n)?(s.state="sticky",g(function(){v(e,d,p),l.position=u,c||(l.bottom="",l[y]=i.stickyBitStickyOffset+"px")})):S?(s.state="default",g(function(){v(e,p),v(e,d),"fixed"===u&&(l.position="")})):w&&(s.state="stuck",g(function(){v(e,p,d),"fixed"!==u||c||(l.top="",l.bottom="0",l.position="absolute")}));var b=r<=C&&C<=a;C<r/2||a<C?g(function(){v(e,h)}):b&&g(function(){v(e,"stub",h)})},s.update=function(t){void 0===t&&(t=null);for(var s=0;s<this.instances.length;s+=1){var e=this.instances[s];if(this.computeScrollOffsets(e),t)for(var i in t)e.props[i]=t[i]}return this},s.removeInstance=function(t){var s=t.el,e=t.props,i=this.toggleClasses;s.style.position="",s.style[e.verticalPosition]="",i(s,e.stickyClass),i(s,e.stuckClass),i(s.parentNode,e.parentClass)},s.cleanup=function(){for(var t=0;t<this.instances.length;t+=1){var s=this.instances[t];s.props.scrollEl.removeEventListener("scroll",s.stateContainer),this.removeInstance(s)}this.manageState=!1,this.instances=[]},t}();return function(t,s){return new e(t,s)}}); | ||
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t=t||self).stickybits=s()}(this,function(){"use strict";var e=function(){function t(t,s){var e=void 0!==s?s:{};this.version="3.6.6",this.userAgent=window.navigator.userAgent||"no `userAgent` provided by the browser",this.props={customStickyChangeNumber:e.customStickyChangeNumber||null,noStyles:e.noStyles||!1,stickyBitStickyOffset:e.stickyBitStickyOffset||0,parentClass:e.parentClass||"js-stickybit-parent",scrollEl:"string"==typeof e.scrollEl?document.querySelector(e.scrollEl):e.scrollEl||window,stickyClass:e.stickyClass||"js-is-sticky",stuckClass:e.stuckClass||"js-is-stuck",stickyChangeClass:e.stickyChangeClass||"js-is-sticky--change",useStickyClasses:e.useStickyClasses||!1,useFixed:e.useFixed||!1,useGetBoundingClientRect:e.useGetBoundingClientRect||!1,verticalPosition:e.verticalPosition||"top"},this.props.positionVal=this.definePosition()||"fixed",this.instances=[];var i=this.props,n=i.positionVal,o=i.verticalPosition,r=i.noStyles,a=i.stickyBitStickyOffset,l="top"!==o||r?"":a+"px",c="fixed"!==n?n:"";this.els="string"==typeof t?document.querySelectorAll(t):t,"length"in this.els||(this.els=[this.els]);for(var f=0;f<this.els.length;f++){var u=this.els[f];u.style[o]=l,u.style.position=c,this.instances.push(this.addInstance(u,this.props))}}var s=t.prototype;return s.definePosition=function(){var t;if(this.props.useFixed)t="fixed";else{for(var s=["","-o-","-webkit-","-moz-","-ms-"],e=document.head.style,i=0;i<s.length;i+=1)e.position=s[i]+"sticky";t=e.position?e.position:"fixed",e.position=""}return t},s.addInstance=function(t,s){var e=this,i={el:t,parent:t.parentNode,props:s};if("fixed"===s.positionVal||s.useStickyClasses){this.isWin=this.props.scrollEl===window;var n=this.isWin?window:this.getClosestParent(i.el,i.props.scrollEl);this.computeScrollOffsets(i),i.parent.className+=" "+s.parentClass,i.state="default",i.stateContainer=function(){return e.manageState(i)},n.addEventListener("scroll",i.stateContainer)}return i},s.getClosestParent=function(t,s){var e=s,i=t;if(i.parentElement===e)return e;for(;i.parentElement!==e;)i=i.parentElement;return e},s.getTopPosition=function(t){if(this.props.useGetBoundingClientRect)return t.getBoundingClientRect().top+(this.props.scrollEl.pageYOffset||document.documentElement.scrollTop);for(var s=0;s=t.offsetTop+s,t=t.offsetParent;);return s},s.computeScrollOffsets=function(t){var s=t,e=s.props,i=s.el,n=s.parent,o=!this.isWin&&"fixed"===e.positionVal,r="bottom"!==e.verticalPosition,a=o?this.getTopPosition(e.scrollEl):0,l=o?this.getTopPosition(n)-a:this.getTopPosition(n),c=null!==e.customStickyChangeNumber?e.customStickyChangeNumber:i.offsetHeight,f=l+n.offsetHeight;s.offset=a+e.stickyBitStickyOffset,s.stickyStart=r?l-s.offset:0,s.stickyChange=s.stickyStart+c,s.stickyStop=r?f-(i.offsetHeight+s.offset):f-window.innerHeight},s.toggleClasses=function(t,s,e){var i=t,n=i.className.split(" ");e&&-1===n.indexOf(e)&&n.push(e);var o=n.indexOf(s);-1!==o&&n.splice(o,1),i.className=n.join(" ")},s.manageState=function(t){var s=t,e=s.el,i=s.props,n=s.state,o=s.stickyStart,r=s.stickyChange,a=s.stickyStop,l=e.style,c=i.noStyles,f=i.positionVal,u=i.scrollEl,p=i.stickyClass,h=i.stickyChangeClass,d=i.stuckClass,y=i.verticalPosition,k="bottom"!==y,m=function(t){t()},g=this.isWin&&(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)||m,C=this.toggleClasses,v=this.isWin?window.scrollY||window.pageYOffset:u.scrollTop,S=k&&v<=o&&("sticky"===n||"stuck"===n),w=a<=v&&"sticky"===n;o<v&&v<a&&("default"===n||"stuck"===n)?(s.state="sticky",g(function(){C(e,d,p),l.position=f,c||(l.bottom="",l[y]=i.stickyBitStickyOffset+"px")})):S?(s.state="default",g(function(){C(e,p),C(e,d),"fixed"===f&&(l.position="")})):w&&(s.state="stuck",g(function(){C(e,p,d),"fixed"!==f||c||(l.top="",l.bottom="0",l.position="absolute")}));var b=r<=v&&v<=a;v<r/2||a<v?g(function(){C(e,h)}):b&&g(function(){C(e,"stub",h)})},s.update=function(t){void 0===t&&(t=null);for(var s=0;s<this.instances.length;s+=1){var e=this.instances[s];if(this.computeScrollOffsets(e),t)for(var i in t)e.props[i]=t[i]}return this},s.removeInstance=function(t){var s=t.el,e=t.props,i=this.toggleClasses;s.style.position="",s.style[e.verticalPosition]="",i(s,e.stickyClass),i(s,e.stuckClass),i(s.parentNode,e.parentClass)},s.cleanup=function(){for(var t=0;t<this.instances.length;t+=1){var s=this.instances[t];s.stateContainer&&s.props.scrollEl.removeEventListener("scroll",s.stateContainer),this.removeInstance(s)}this.manageState=!1,this.instances=[]},t}();return function(t,s){return new e(t,s)}}); |
/** | ||
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills | ||
@version v3.6.5 | ||
@version v3.6.6 | ||
@link https://github.com/dollarshaveclub/stickybits#readme | ||
@@ -73,3 +73,3 @@ @author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in) | ||
var o = typeof obj !== 'undefined' ? obj : {}; | ||
this.version = '3.6.5'; | ||
this.version = '3.6.6'; | ||
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser'; | ||
@@ -90,3 +90,3 @@ this.props = { | ||
/* | ||
define positionVal | ||
define positionVal after the setting of props, because definePosition looks at the props.useFixed | ||
---- | ||
@@ -104,4 +104,3 @@ - uses a computed (`.definePosition()`) | ||
noStyles = _this$props.noStyles, | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset, | ||
useStickyClasses = _this$props.useStickyClasses; | ||
stickyBitStickyOffset = _this$props.stickyBitStickyOffset; | ||
var verticalPositionStyle = verticalPosition === 'top' && !noStyles ? stickyBitStickyOffset + "px" : ''; | ||
@@ -116,8 +115,5 @@ var positionStyle = positionVal !== 'fixed' ? positionVal : ''; | ||
el.style[verticalPosition] = verticalPositionStyle; | ||
el.style.position = positionStyle; | ||
el.style.position = positionStyle; // instances are an array of objects | ||
if (positionVal === 'fixed' || useStickyClasses) { | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
this.instances.push(this.addInstance(el, this.props)); | ||
} | ||
@@ -190,13 +186,17 @@ } | ||
}; | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
if (props.positionVal === 'fixed' || props.useStickyClasses) { | ||
this.isWin = this.props.scrollEl === window; | ||
var se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl); | ||
this.computeScrollOffsets(item); | ||
item.parent.className += " " + props.parentClass; | ||
item.state = 'default'; | ||
se.addEventListener('scroll', item.stateContainer); | ||
item.stateContainer = function () { | ||
return _this.manageState(item); | ||
}; | ||
se.addEventListener('scroll', item.stateContainer); | ||
} | ||
return item; | ||
@@ -444,3 +444,7 @@ } | ||
var instance = this.instances[i]; | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
if (instance.stateContainer) { | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer); | ||
} | ||
this.removeInstance(instance); | ||
@@ -447,0 +451,0 @@ } |
{ | ||
"name": "stickybits", | ||
"version": "3.6.5", | ||
"version": "3.6.6", | ||
"description": "Stickybits is a lightweight alternative to `position: sticky` polyfills", | ||
@@ -67,13 +67,13 @@ "main": "dist/stickybits.js", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-node": "^9.0.0", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"husky": "^1.0.0", | ||
"husky": "^2.0.0", | ||
"jest": "^22.0.0", | ||
"jquery": "^3.2.1", | ||
"markdown-spellcheck": "^1.3.1", | ||
"markdownlint-cli": "^0.14.0", | ||
"markdownlint-cli": "^0.16.0", | ||
"node-qunit-phantomjs": "^2.0.0", | ||
"nyc": "^13.2.0", | ||
"nyc": "^14.0.0", | ||
"qunit": "^2.6.1", | ||
"rollup": "1.7.3", | ||
"rollup": "1.12.2", | ||
"rollup-plugin-babel": "^4.1.0", | ||
@@ -80,0 +80,0 @@ "rollup-plugin-replace": "^2.0.0", |
@@ -479,2 +479,3 @@ <p align="center"> | ||
- [Frank Merema](https://github.com/FrankMerema) | ||
- [Daniel Ruf](https://github.com/DanielRuf) | ||
@@ -481,0 +482,0 @@ - [Nestor Vera](https://github.com/hacknug) |
@@ -76,3 +76,3 @@ /* | ||
/* | ||
define positionVal | ||
define positionVal after the setting of props, because definePosition looks at the props.useFixed | ||
---- | ||
@@ -91,3 +91,2 @@ - uses a computed (`.definePosition()`) | ||
stickyBitStickyOffset, | ||
useStickyClasses, | ||
} = this.props | ||
@@ -108,6 +107,4 @@ const verticalPositionStyle = verticalPosition === 'top' && !noStyles ? `${stickyBitStickyOffset}px` : '' | ||
if (positionVal === 'fixed' || useStickyClasses) { | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)) | ||
} | ||
// instances are an array of objects | ||
this.instances.push(this.addInstance(el, this.props)) | ||
} | ||
@@ -170,9 +167,11 @@ } | ||
} | ||
this.isWin = this.props.scrollEl === window | ||
const se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl) | ||
this.computeScrollOffsets(item) | ||
item.parent.className += ` ${props.parentClass}` | ||
item.state = 'default' | ||
item.stateContainer = () => this.manageState(item) | ||
se.addEventListener('scroll', item.stateContainer) | ||
if (props.positionVal === 'fixed' || props.useStickyClasses) { | ||
this.isWin = this.props.scrollEl === window | ||
const se = this.isWin ? window : this.getClosestParent(item.el, item.props.scrollEl) | ||
this.computeScrollOffsets(item) | ||
item.parent.className += ` ${props.parentClass}` | ||
item.state = 'default' | ||
item.stateContainer = () => this.manageState(item) | ||
se.addEventListener('scroll', item.stateContainer) | ||
} | ||
return item | ||
@@ -403,3 +402,5 @@ } | ||
const instance = this.instances[i] | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer) | ||
if (instance.stateContainer) { | ||
instance.props.scrollEl.removeEventListener('scroll', instance.stateContainer) | ||
} | ||
this.removeInstance(instance) | ||
@@ -406,0 +407,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108257
2173
484