Comparing version 2.2.3 to 2.2.4
@@ -1,11 +0,11 @@ | ||
/*! | ||
/* | ||
* HC-Sticky | ||
* ========= | ||
* Version: 2.2.3 | ||
* Version: 2.2.4 | ||
* Author: Some Web Media | ||
* Author URL: http://somewebmedia.com | ||
* Author URL: https://github.com/somewebmedia | ||
* Plugin URL: https://github.com/somewebmedia/hc-sticky | ||
* Description: Cross-browser plugin that makes any element on your page visible while you scroll | ||
* Description: JavaScript library that makes any element on your page visible while you scroll | ||
* License: MIT | ||
*/ | ||
!function(t,e){"use strict";if("object"==typeof module&&"object"==typeof module.exports){if(!t.document)throw new Error("HC-Sticky requires a browser to run.");module.exports=e(t)}else"function"==typeof define&&define.amd?define("hcSticky",[],e(t)):e(t)}("undefined"!=typeof window?window:this,function(U){"use strict";var Y={top:0,bottom:0,bottomEnd:0,innerTop:0,innerSticker:null,stickyClass:"sticky",stickTo:null,followScroll:!0,responsive:null,mobileFirst:!1,onStart:null,onStop:null,onBeforeResize:null,onResize:null,resizeDebounce:100,disable:!1,queries:null,queryFlow:"down"},$=function(t,e,o){console.log("%c! HC Sticky:%c "+t+"%c "+o+" is now deprecated and will be removed. Use%c "+e+"%c instead.","color: red","color: darkviolet","color: black","color: darkviolet","color: black")},Q=U.document,X=function(n,f){var o=this;if("string"==typeof n&&(n=Q.querySelector(n)),!n)return!1;f.queries&&$("queries","responsive","option"),f.queryFlow&&$("queryFlow","mobileFirst","option");var p={},d=X.Helpers,s=n.parentNode;"static"===d.getStyle(s,"position")&&(s.style.position="relative");var u=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};d.isEmptyObject(t)&&!d.isEmptyObject(p)||(p=Object.assign({},Y,p,t))},t=function(){return p.disable},e=function(){var t,e=p.responsive||p.queries;if(e){var o=U.innerWidth;if(t=f,(p=Object.assign({},Y,t||{})).mobileFirst)for(var i in e)i<=o&&!d.isEmptyObject(e[i])&&u(e[i]);else{var n=[];for(var s in e){var r={};r[s]=e[s],n.push(r)}for(var l=n.length-1;0<=l;l--){var a=n[l],c=Object.keys(a)[0];o<=c&&!d.isEmptyObject(a[c])&&u(a[c])}}}},r={css:{},position:null,stick:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};d.hasClass(n,p.stickyClass)||(!1===l.isAttached&&l.attach(),r.position="fixed",n.style.position="fixed",n.style.left=l.offsetLeft+"px",n.style.width=l.width,void 0===t.bottom?n.style.bottom="auto":n.style.bottom=t.bottom+"px",void 0===t.top?n.style.top="auto":n.style.top=t.top+"px",n.classList?n.classList.add(p.stickyClass):n.className+=" "+p.stickyClass,p.onStart&&p.onStart.call(n,Object.assign({},p)))},release:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(t.stop=t.stop||!1,!0===t.stop||"fixed"===r.position||null===r.position||!(void 0===t.top&&void 0===t.bottom||void 0!==t.top&&(parseInt(d.getStyle(n,"top"))||0)===t.top||void 0!==t.bottom&&(parseInt(d.getStyle(n,"bottom"))||0)===t.bottom)){!0===t.stop?!0===l.isAttached&&l.detach():!1===l.isAttached&&l.attach();var e=t.position||r.css.position;r.position=e,n.style.position=e,n.style.left=!0===t.stop?r.css.left:l.positionLeft+"px",n.style.width="absolute"!==e?r.css.width:l.width,void 0===t.bottom?n.style.bottom=!0===t.stop?"":"auto":n.style.bottom=t.bottom+"px",void 0===t.top?n.style.top=!0===t.stop?"":"auto":n.style.top=t.top+"px",n.classList?n.classList.remove(p.stickyClass):n.className=n.className.replace(new RegExp("(^|\\b)"+p.stickyClass.split(" ").join("|")+"(\\b|$)","gi")," "),p.onStop&&p.onStop.call(n,Object.assign({},p))}}},l={el:Q.createElement("div"),offsetLeft:null,positionLeft:null,width:null,isAttached:!1,init:function(){for(var t in l.el.className="sticky-spacer",r.css)l.el.style[t]=r.css[t];l.el.style["z-index"]="-1";var e=d.getStyle(n);l.offsetLeft=d.offset(n).left-(parseInt(e.marginLeft)||0),l.positionLeft=d.position(n).left,l.width=d.getStyle(n,"width")},attach:function(){s.insertBefore(l.el,n),l.isAttached=!0},detach:function(){l.el=s.removeChild(l.el),l.isAttached=!1}},a=void 0,c=void 0,g=void 0,m=void 0,h=void 0,v=void 0,y=void 0,b=void 0,S=void 0,w=void 0,k=void 0,E=void 0,x=void 0,L=void 0,T=void 0,j=void 0,O=void 0,C=void 0,i=function(){var t,e,o,i;r.css=(t=n,e=d.getCascadedStyle(t),o=d.getStyle(t),i={height:t.offsetHeight+"px",left:e.left,right:e.right,top:e.top,bottom:e.bottom,position:o.position,display:o.display,verticalAlign:o.verticalAlign,boxSizing:o.boxSizing,marginLeft:e.marginLeft,marginRight:e.marginRight,marginTop:e.marginTop,marginBottom:e.marginBottom,paddingLeft:e.paddingLeft,paddingRight:e.paddingRight},e.float&&(i.float=e.float||"none"),e.cssFloat&&(i.cssFloat=e.cssFloat||"none"),o.MozBoxSizing&&(i.MozBoxSizing=o.MozBoxSizing),i.width="auto"!==e.width?e.width:"border-box"===i.boxSizing||"border-box"===i.MozBoxSizing?t.offsetWidth+"px":o.width,i),l.init(),a=!(!p.stickTo||!("document"===p.stickTo||p.stickTo.nodeType&&9===p.stickTo.nodeType||"object"==typeof p.stickTo&&p.stickTo instanceof("undefined"!=typeof HTMLDocument?HTMLDocument:Document))),c=p.stickTo?a?Q:"string"==typeof p.stickTo?Q.querySelector(p.stickTo):p.stickTo:s,T=(C=function(){var t=n.offsetHeight+(parseInt(r.css.marginTop)||0)+(parseInt(r.css.marginBottom)||0),e=(T||0)-t;return-1<=e&&e<=1?T:t})(),m=(O=function(){return a?Math.max(Q.documentElement.clientHeight,Q.body.scrollHeight,Q.documentElement.scrollHeight,Q.body.offsetHeight,Q.documentElement.offsetHeight):c.offsetHeight})(),h=a?0:d.offset(c).top,v=p.stickTo?a?0:d.offset(s).top:h,y=U.innerHeight,j=n.offsetTop-(parseInt(r.css.marginTop)||0),g=p.innerSticker?"string"==typeof p.innerSticker?Q.querySelector(p.innerSticker):p.innerSticker:null,b=isNaN(p.top)&&-1<p.top.indexOf("%")?parseFloat(p.top)/100*y:p.top,S=isNaN(p.bottom)&&-1<p.bottom.indexOf("%")?parseFloat(p.bottom)/100*y:p.bottom,w=g?g.offsetTop:p.innerTop?p.innerTop:0,k=isNaN(p.bottomEnd)&&-1<p.bottomEnd.indexOf("%")?parseFloat(p.bottomEnd)/100*y:p.bottomEnd,E=h-b+w+j},z=U.pageYOffset||Q.documentElement.scrollTop,N=0,H=void 0,R=function(){T=C(),m=O(),x=h+m-b-k,L=y<T;var t=U.pageYOffset||Q.documentElement.scrollTop,e=d.offset(n).top,o=e-t,i=void 0;H=t<z?"up":"down",N=t-z,E<(z=t)?x+b+(L?S:0)-(p.followScroll&&L?0:b)<=t+T-w-(y-(E-w)<T-w&&p.followScroll&&0<(i=T-y-w)?i:0)?r.release({position:"absolute",bottom:v+s.offsetHeight-x-b}):L&&p.followScroll?"down"===H?o+T+S<=y+.9?r.stick({bottom:S}):"fixed"===r.position&&r.release({position:"absolute",top:e-b-E-N+w}):Math.ceil(o+w)<0&&"fixed"===r.position?r.release({position:"absolute",top:e-b-E+w-N}):t+b-w<=e&&r.stick({top:b-w}):r.stick({top:b-w}):r.release({stop:!0})},A=!1,B=!1,I=function(){A&&(d.event.unbind(U,"scroll",R),A=!1)},q=function(){null!==n.offsetParent&&"none"!==d.getStyle(n,"display")?(i(),m<=T?I():(R(),A||(d.event.bind(U,"scroll",R),A=!0))):I()},F=function(){n.style.position="",n.style.left="",n.style.top="",n.style.bottom="",n.style.width="",n.classList?n.classList.remove(p.stickyClass):n.className=n.className.replace(new RegExp("(^|\\b)"+p.stickyClass.split(" ").join("|")+"(\\b|$)","gi")," "),r.css={},!(r.position=null)===l.isAttached&&l.detach()},M=function(){F(),e(),t()?I():q()},D=function(){p.onBeforeResize&&p.onBeforeResize.call(n,Object.assign({},p)),M(),p.onResize&&p.onResize.call(n,Object.assign({},p))},P=p.resizeDebounce?d.debounce(D,p.resizeDebounce):D,W=function(){B&&(d.event.unbind(U,"resize",P),B=!1),I()},V=function(){B||(d.event.bind(U,"resize",P),B=!0),e(),t()?I():q()};this.options=function(t){return t?p[t]:Object.assign({},p)},this.refresh=M,this.update=function(t){u(t),f=Object.assign({},f,t||{}),M()},this.attach=V,this.detach=W,this.destroy=function(){W(),F()},this.triggerMethod=function(t,e){"function"==typeof o[t]&&o[t](e)},this.reinit=function(){$("reinit","refresh","method"),M()},u(f),V(),d.event.bind(U,"load",M)};if(void 0!==U.jQuery){var i=U.jQuery,n="hcSticky";i.fn.extend({hcSticky:function(e,o){return this.length?"options"===e?i.data(this.get(0),n).options():this.each(function(){var t=i.data(this,n);t?t.triggerMethod(e,o):(t=new X(this,e),i.data(this,n,t))}):this}})}return U.hcSticky=U.hcSticky||X,X}),function(c){"use strict";var t=c.hcSticky,f=c.document;"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(t,e){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var o=Object(t),i=1;i<arguments.length;i++){var n=arguments[i];if(null!=n)for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(o[s]=n[s])}return o},writable:!0,configurable:!0}),Array.prototype.forEach||(Array.prototype.forEach=function(t){var e,o;if(null==this)throw new TypeError("this is null or not defined");var i=Object(this),n=i.length>>>0;if("function"!=typeof t)throw new TypeError(t+" is not a function");for(1<arguments.length&&(e=arguments[1]),o=0;o<n;){var s;o in i&&(s=i[o],t.call(e,s,o,i)),o++}});var e=function(){var t=f.documentElement,e=function(){};function i(t){var e=c.event;return e.target=e.target||e.srcElement||t,e}t.addEventListener?e=function(t,e,o){t.addEventListener(e,o,!1)}:t.attachEvent&&(e=function(e,t,o){e[t+o]=o.handleEvent?function(){var t=i(e);o.handleEvent.call(o,t)}:function(){var t=i(e);o.call(e,t)},e.attachEvent("on"+t,e[t+o])});var o=function(){};return t.removeEventListener?o=function(t,e,o){t.removeEventListener(e,o,!1)}:t.detachEvent&&(o=function(e,o,i){e.detachEvent("on"+o,e[o+i]);try{delete e[o+i]}catch(t){e[o+i]=void 0}}),{bind:e,unbind:o}}(),r=function(t,e){return c.getComputedStyle?e?f.defaultView.getComputedStyle(t,null).getPropertyValue(e):f.defaultView.getComputedStyle(t,null):t.currentStyle?e?t.currentStyle[e.replace(/-\w/g,function(t){return t.toUpperCase().replace("-","")})]:t.currentStyle:void 0},l=function(t){var e=t.getBoundingClientRect(),o=c.pageYOffset||f.documentElement.scrollTop,i=c.pageXOffset||f.documentElement.scrollLeft;return{top:e.top+o,left:e.left+i}};t.Helpers={isEmptyObject:function(t){for(var e in t)return!1;return!0},debounce:function(i,n,s){var r=void 0;return function(){var t=this,e=arguments,o=s&&!r;clearTimeout(r),r=setTimeout(function(){r=null,s||i.apply(t,e)},n),o&&i.apply(t,e)}},hasClass:function(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)},offset:l,position:function(t){var e=t.offsetParent,o=l(e),i=l(t),n=r(e),s=r(t);return o.top+=parseInt(n.borderTopWidth)||0,o.left+=parseInt(n.borderLeftWidth)||0,{top:i.top-o.top-(parseInt(s.marginTop)||0),left:i.left-o.left-(parseInt(s.marginLeft)||0)}},getStyle:r,getCascadedStyle:function(t){var e=t.cloneNode(!0);e.style.display="none",Array.prototype.slice.call(e.querySelectorAll('input[type="radio"]')).forEach(function(t){t.removeAttribute("name")}),t.parentNode.insertBefore(e,t.nextSibling);var o=void 0;e.currentStyle?o=e.currentStyle:c.getComputedStyle&&(o=f.defaultView.getComputedStyle(e,null));var i={};for(var n in o)!isNaN(n)||"string"!=typeof o[n]&&"number"!=typeof o[n]||(i[n]=o[n]);if(Object.keys(i).length<3)for(var s in i={},o)isNaN(s)||(i[o[s].replace(/-\w/g,function(t){return t.toUpperCase().replace("-","")})]=o.getPropertyValue(o[s]));if(i.margin||"auto"!==i.marginLeft?i.margin||i.marginLeft!==i.marginRight||i.marginLeft!==i.marginTop||i.marginLeft!==i.marginBottom||(i.margin=i.marginLeft):i.margin="auto",!i.margin&&"0px"===i.marginLeft&&"0px"===i.marginRight){var r=t.offsetLeft-t.parentNode.offsetLeft,l=r-(parseInt(i.left)||0)-(parseInt(i.right)||0),a=t.parentNode.offsetWidth-t.offsetWidth-r-(parseInt(i.right)||0)+(parseInt(i.left)||0)-l;0!==a&&1!==a||(i.margin="auto")}return e.parentNode.removeChild(e),e=null,i},event:e}}(window); | ||
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}!function(t,e){if("object"===("undefined"==typeof module?"undefined":_typeof(module))&&"object"===_typeof(module.exports)){if(!t.document)throw new Error("HC-Sticky requires a browser to run.");module.exports=e(t)}else"function"==typeof define&&define.amd?define("hcSticky",[],e(t)):e(t)}("undefined"!=typeof window?window:this,function(_){var U=_.document,Y=!1;try{var t=Object.defineProperty({},"passive",{get:function(){Y={passive:!1}}});_.addEventListener("testPassive",null,t),_.removeEventListener("testPassive",null,t)}catch(t){}var $={top:0,bottom:0,bottomEnd:0,innerTop:0,innerSticker:null,stickyClass:"sticky",stickTo:null,followScroll:!0,responsive:null,mobileFirst:!1,onStart:null,onStop:null,onBeforeResize:null,onResize:null,resizeDebounce:100,disable:!1},Q=function(t,e,o){console.warn("%cHC Sticky:%c "+o+"%c '"+t+"'%c is now deprecated and will be removed. Use%c '"+e+"'%c instead.","color: #fa253b","color: default","color: #5595c6","color: default","color: #5595c6","color: default")},X=function(n,f){var o=this;if(f=f||{},"string"==typeof n&&(n=U.querySelector(n)),!n)return!1;f.queries&&Q("queries","responsive","option"),f.queryFlow&&Q("queryFlow","mobileFirst","option");var p={},u=X.Helpers,s=n.parentNode;"static"===u.getStyle(s,"position")&&(s.style.position="relative");function d(t){t=t||{},u.isEmptyObject(t)&&!u.isEmptyObject(p)||(p=Object.assign({},$,p,t))}function t(){return p.disable}function e(){var t,e=p.responsive||p.queries;if(e){var o=_.innerWidth;if(t=f,(p=Object.assign({},$,t||{})).mobileFirst)for(var i in e)i<=o&&!u.isEmptyObject(e[i])&&d(e[i]);else{var n=[];for(var s in e){var r={};r[s]=e[s],n.push(r)}for(var l=n.length-1;0<=l;l--){var a=n[l],c=Object.keys(a)[0];o<=c&&!u.isEmptyObject(a[c])&&d(a[c])}}}}function i(){var t,e,o,i;F.css=(t=n,e=u.getCascadedStyle(t),o=u.getStyle(t),i={height:t.offsetHeight+"px",left:e.left,right:e.right,top:e.top,bottom:e.bottom,position:o.position,display:o.display,verticalAlign:o.verticalAlign,boxSizing:o.boxSizing,marginLeft:e.marginLeft,marginRight:e.marginRight,marginTop:e.marginTop,marginBottom:e.marginBottom,paddingLeft:e.paddingLeft,paddingRight:e.paddingRight},e.float&&(i.float=e.float||"none"),e.cssFloat&&(i.cssFloat=e.cssFloat||"none"),o.MozBoxSizing&&(i.MozBoxSizing=o.MozBoxSizing),i.width="auto"!==e.width?e.width:"border-box"===i.boxSizing||"border-box"===i.MozBoxSizing?t.offsetWidth+"px":o.width,i),q.init(),b=!(!p.stickTo||!("document"===p.stickTo||p.stickTo.nodeType&&9===p.stickTo.nodeType||"object"===_typeof(p.stickTo)&&p.stickTo instanceof("undefined"!=typeof HTMLDocument?HTMLDocument:Document))),v=p.stickTo?b?U:"string"==typeof p.stickTo?U.querySelector(p.stickTo):p.stickTo:s,H=(B=function(){var t=n.offsetHeight+(parseInt(F.css.marginTop)||0)+(parseInt(F.css.marginBottom)||0),e=(H||0)-t;return-1<=e&&e<=1?H:t})(),w=(A=function(){return b?Math.max(U.documentElement.clientHeight,U.body.scrollHeight,U.documentElement.scrollHeight,U.body.offsetHeight,U.documentElement.offsetHeight):v.offsetHeight})(),k=b?0:u.offset(v).top,L=p.stickTo?b?0:u.offset(s).top:k,x=_.innerHeight,R=n.offsetTop-(parseInt(F.css.marginTop)||0),S=p.innerSticker?"string"==typeof p.innerSticker?U.querySelector(p.innerSticker):p.innerSticker:null,T=isNaN(p.top)&&-1<p.top.indexOf("%")?parseFloat(p.top)/100*x:p.top,E=isNaN(p.bottom)&&-1<p.bottom.indexOf("%")?parseFloat(p.bottom)/100*x:p.bottom,j=S?S.offsetTop:p.innerTop?p.innerTop:0,O=isNaN(p.bottomEnd)&&-1<p.bottomEnd.indexOf("%")?parseFloat(p.bottomEnd)/100*x:p.bottomEnd,C=k-T+j+R}function r(){H=B(),w=A(),z=k+w-T-O,N=x<H;var t,e=_.pageYOffset||U.documentElement.scrollTop,o=u.offset(n).top,i=o-e;I=e<M?"up":"down",P=e-M,C<(M=e)?z+T+(N?E:0)-(p.followScroll&&N?0:T)<=e+H-j-(x-(C-j)<H-j&&p.followScroll&&0<(t=H-x-j)?t:0)?F.release({position:"absolute",bottom:L+s.offsetHeight-z-T}):N&&p.followScroll?"down"==I?i+H+E<=x+.9?F.stick({bottom:E}):"fixed"===F.position&&F.release({position:"absolute",top:o-T-C-P+j}):Math.ceil(i+j)<0&&"fixed"===F.position?F.release({position:"absolute",top:o-T-C+j-P}):e+T-j<=o&&F.stick({top:T-j}):F.stick({top:T-j}):F.release({stop:!0})}function l(){D&&(_.removeEventListener("scroll",r,Y),D=!1)}function a(){null!==n.offsetParent&&"none"!==u.getStyle(n,"display")?(i(),w<H?l():(r(),D||(_.addEventListener("scroll",r,Y),D=!0))):l()}function c(){n.style.position="",n.style.left="",n.style.top="",n.style.bottom="",n.style.width="",n.classList?n.classList.remove(p.stickyClass):n.className=n.className.replace(new RegExp("(^|\\b)"+p.stickyClass.split(" ").join("|")+"(\\b|$)","gi")," "),F.css={},!(F.position=null)===q.isAttached&&q.detach()}function y(){c(),e(),(t()?l:a)()}function m(){p.onBeforeResize&&p.onBeforeResize.call(n,Object.assign({},p)),y(),p.onResize&&p.onResize.call(n,Object.assign({},p))}function g(){W&&(_.removeEventListener("resize",V,Y),W=!1),l()}function h(){W||(_.addEventListener("resize",V,Y),W=!0),e(),(t()?l:a)()}var b,v,S,w,k,L,x,T,E,j,O,C,z,N,H,R,A,B,I,F={css:{},position:null,stick:function(t){t=t||{},u.hasClass(n,p.stickyClass)||(!1===q.isAttached&&q.attach(),F.position="fixed",n.style.position="fixed",n.style.left=q.offsetLeft+"px",n.style.width=q.width,void 0===t.bottom?n.style.bottom="auto":n.style.bottom=t.bottom+"px",void 0===t.top?n.style.top="auto":n.style.top=t.top+"px",n.classList?n.classList.add(p.stickyClass):n.className+=" "+p.stickyClass,p.onStart&&p.onStart.call(n,Object.assign({},p)))},release:function(t){if((t=t||{}).stop=t.stop||!1,!0===t.stop||"fixed"===F.position||null===F.position||!(void 0===t.top&&void 0===t.bottom||void 0!==t.top&&(parseInt(u.getStyle(n,"top"))||0)===t.top||void 0!==t.bottom&&(parseInt(u.getStyle(n,"bottom"))||0)===t.bottom)){!0===t.stop?!0===q.isAttached&&q.detach():!1===q.isAttached&&q.attach();var e=t.position||F.css.position;F.position=e,n.style.position=e,n.style.left=!0===t.stop?F.css.left:q.positionLeft+"px",n.style.width="absolute"!==e?F.css.width:q.width,void 0===t.bottom?n.style.bottom=!0===t.stop?"":"auto":n.style.bottom=t.bottom+"px",void 0===t.top?n.style.top=!0===t.stop?"":"auto":n.style.top=t.top+"px",n.classList?n.classList.remove(p.stickyClass):n.className=n.className.replace(new RegExp("(^|\\b)"+p.stickyClass.split(" ").join("|")+"(\\b|$)","gi")," "),p.onStop&&p.onStop.call(n,Object.assign({},p))}}},q={el:U.createElement("div"),offsetLeft:null,positionLeft:null,width:null,isAttached:!1,init:function(){for(var t in q.el.className="sticky-spacer",F.css)q.el.style[t]=F.css[t];q.el.style["z-index"]="-1";var e=u.getStyle(n);q.offsetLeft=u.offset(n).left-(parseInt(e.marginLeft)||0),q.positionLeft=u.position(n).left,q.width=u.getStyle(n,"width")},attach:function(){s.insertBefore(q.el,n),q.isAttached=!0},detach:function(){q.el=s.removeChild(q.el),q.isAttached=!1}},M=_.pageYOffset||U.documentElement.scrollTop,P=0,D=!1,W=!1,V=p.resizeDebounce?u.debounce(m,p.resizeDebounce):m;this.options=function(t){return t?p[t]:Object.assign({},p)},this.refresh=y,this.update=function(t){d(t),f=Object.assign({},f,t||{}),y()},this.attach=h,this.detach=g,this.destroy=function(){g(),c()},this.triggerMethod=function(t,e){"function"==typeof o[t]&&o[t](e)},this.reinit=function(){Q("reinit","refresh","method"),y()},d(f),h(),_.addEventListener("load",y)};if(void 0!==_.jQuery){var i=_.jQuery,n="hcSticky";i.fn.extend({hcSticky:function(e,o){return this.length?"options"===e?i.data(this.get(0),n).options():this.each(function(){var t=i.data(this,n);t?t.triggerMethod(e,o):(t=new X(this,e),i.data(this,n,t))}):this}})}return _.hcSticky=_.hcSticky||X,X}),function(c){var t=c.hcSticky,f=c.document;"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(t,e){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var o=Object(t),i=1;i<arguments.length;i++){var n=arguments[i];if(null!=n)for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(o[s]=n[s])}return o},writable:!0,configurable:!0}),Array.prototype.forEach||(Array.prototype.forEach=function(t){var e,o;if(null==this)throw new TypeError("this is null or not defined");var i=Object(this),n=i.length>>>0;if("function"!=typeof t)throw new TypeError(t+" is not a function");for(1<arguments.length&&(e=arguments[1]),o=0;o<n;){var s;o in i&&(s=i[o],t.call(e,s,o,i)),o++}});function r(t,e){return c.getComputedStyle?e?f.defaultView.getComputedStyle(t,null).getPropertyValue(e):f.defaultView.getComputedStyle(t,null):t.currentStyle?e?t.currentStyle[e.replace(/-\w/g,function(t){return t.toUpperCase().replace("-","")})]:t.currentStyle:void 0}function l(t){var e=t.getBoundingClientRect(),o=c.pageYOffset||f.documentElement.scrollTop,i=c.pageXOffset||f.documentElement.scrollLeft;return{top:e.top+o,left:e.left+i}}t.Helpers={isEmptyObject:function(t){for(var e in t)return!1;return!0},debounce:function(i,n,s){var r;return function(){var t=this,e=arguments,o=s&&!r;clearTimeout(r),r=setTimeout(function(){r=null,s||i.apply(t,e)},n),o&&i.apply(t,e)}},hasClass:function(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)},offset:l,position:function(t){var e=t.offsetParent,o=l(e),i=l(t),n=r(e),s=r(t);return o.top+=parseInt(n.borderTopWidth)||0,o.left+=parseInt(n.borderLeftWidth)||0,{top:i.top-o.top-(parseInt(s.marginTop)||0),left:i.left-o.left-(parseInt(s.marginLeft)||0)}},getStyle:r,getCascadedStyle:function(t){var e,o=t.cloneNode(!0);o.style.display="none",Array.prototype.slice.call(o.querySelectorAll('input[type="radio"]')).forEach(function(t){t.removeAttribute("name")}),t.parentNode.insertBefore(o,t.nextSibling),o.currentStyle?e=o.currentStyle:c.getComputedStyle&&(e=f.defaultView.getComputedStyle(o,null));var i={};for(var n in e)!isNaN(n)||"string"!=typeof e[n]&&"number"!=typeof e[n]||(i[n]=e[n]);if(Object.keys(i).length<3)for(var s in i={},e)isNaN(s)||(i[e[s].replace(/-\w/g,function(t){return t.toUpperCase().replace("-","")})]=e.getPropertyValue(e[s]));if(i.margin||"auto"!==i.marginLeft?i.margin||i.marginLeft!==i.marginRight||i.marginLeft!==i.marginTop||i.marginLeft!==i.marginBottom||(i.margin=i.marginLeft):i.margin="auto",!i.margin&&"0px"===i.marginLeft&&"0px"===i.marginRight){var r=t.offsetLeft-t.parentNode.offsetLeft,l=r-(parseInt(i.left)||0)-(parseInt(i.right)||0),a=t.parentNode.offsetWidth-t.offsetWidth-r-(parseInt(i.right)||0)+(parseInt(i.left)||0)-l;0!=a&&1!=a||(i.margin="auto")}return o.parentNode.removeChild(o),o=null,i}}}(window); |
184
gulpfile.js
@@ -1,7 +0,5 @@ | ||
const gulp = require('gulp'); | ||
const { src, dest, parallel, series, watch } = require('gulp'); | ||
const glob = require('glob'); | ||
const sass = require('gulp-sass'); | ||
const autoprefixer = require('gulp-autoprefixer'); | ||
const template = require('gulp-template'); | ||
const glob = require('glob'); | ||
const cheerio = require('cheerio'); | ||
const concat = require('gulp-concat'); | ||
@@ -11,26 +9,27 @@ const babel = require('gulp-babel'); | ||
const saveLicense = require('uglify-save-license'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const through = require('through2'); | ||
const open = require('gulp-open'); | ||
const browserify = require('gulp-browserify'); | ||
const rename = require('gulp-rename'); | ||
const bump = require('gulp-bump'); | ||
const replace = require('gulp-replace'); | ||
const argv = require('yargs').argv; | ||
/* Main JS */ | ||
gulp.task('js', () => { | ||
return gulp.src([ | ||
const compileJs = () => { | ||
return src([ | ||
'./src/hc-sticky.js', | ||
'./src/hc-sticky.helpers.js' | ||
]) | ||
.pipe(babel({ | ||
plugins: [ | ||
'check-es2015-constants', | ||
'transform-es2015-arrow-functions', | ||
'transform-es2015-block-scoped-functions', | ||
'transform-es2015-block-scoping', | ||
'transform-es2015-parameters', | ||
'transform-es2015-shorthand-properties' | ||
] | ||
})) | ||
.pipe(babel( | ||
{ | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false | ||
} | ||
] | ||
] | ||
} | ||
)) | ||
.pipe(concat('hc-sticky.js')) | ||
@@ -42,11 +41,8 @@ .pipe(argv.dev ? through.obj() : uglify({ | ||
})) | ||
.pipe(gulp.dest('./dist')); | ||
}); | ||
.pipe(dest('./docs/')) // demo | ||
.pipe(dest('./dist')); | ||
}; | ||
/* Demo */ | ||
const demo_dest = './demo/build'; | ||
gulp.task('demo-sass', () => { | ||
return gulp.src(['./demo/src/*.scss']) | ||
const compileDemo = () => { | ||
return src(['./docs/*.scss']) | ||
.pipe(sass({ | ||
@@ -56,105 +52,55 @@ 'outputStyle': argv.dev ? 'development' : 'compressed' | ||
.pipe(autoprefixer()) | ||
.pipe(gulp.dest(demo_dest)); | ||
}); | ||
.pipe(dest('./docs/')); | ||
}; | ||
gulp.task('demo-html', () => { | ||
const demos = glob.sync('./demo/src/*.html') || []; | ||
demos.forEach((item, i) => { | ||
if (path.basename(item) === 'index.html') { | ||
delete demos[i]; | ||
} | ||
}); | ||
return gulp.src(demos) | ||
.pipe(gulp.dest(demo_dest)); | ||
}); | ||
gulp.task('demo-browserify', () => { | ||
return gulp.src(['./demo/src/browserify.js']) | ||
const compileDemoBrowserify = () => { | ||
return src(['./docs/browserify.src.js']) | ||
.pipe(browserify({ | ||
insertGlobals: true | ||
})) | ||
.pipe(babel({ | ||
plugins: [ | ||
'check-es2015-constants', | ||
'transform-es2015-arrow-functions', | ||
'transform-es2015-block-scoped-functions', | ||
'transform-es2015-block-scoping' | ||
] | ||
})) | ||
.pipe(babel( | ||
{ | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false | ||
} | ||
] | ||
] | ||
} | ||
)) | ||
.pipe(argv.dev ? through.obj() : uglify()) | ||
.pipe(gulp.dest(demo_dest)); | ||
}); | ||
.pipe(rename('browserify.dist.js')) | ||
.pipe(dest('./docs/')); | ||
}; | ||
gulp.task('demo-js', ['demo-browserify'], () => { | ||
return gulp.src(['./dist/hc-sticky.js']) | ||
.pipe(gulp.dest(demo_dest)); | ||
}); | ||
const bumpPackage = () => { | ||
return src('./*.json') | ||
.pipe(bump(argv.ver && argv.ver.indexOf('.') > -1 ? {version: argv.ver} : {type: argv.ver || 'patch'})) | ||
.pipe(dest('./')); | ||
}; | ||
const compileHtml = (openHtml) => { | ||
openHtml = openHtml || false; | ||
const bumpJs = () => { | ||
const package = require('./package.json'); | ||
const demos = glob.sync('./demo/src/*.html') || []; | ||
let demos_content = ''; | ||
return src(['./src/*.js']) | ||
.pipe(replace(/ \* Version: ([\d\.]+)/g, () => { | ||
return ` * Version: ${package.version}`; | ||
})) | ||
.pipe(dest('./src/')) | ||
}; | ||
demos.forEach((item) => { | ||
const filepath = item; | ||
const filename = path.basename(item); | ||
const defaultTask = parallel(compileJs, compileDemo, compileDemoBrowserify); | ||
if (filename === 'index.html') { | ||
return; | ||
} | ||
const watchFiles = () => { | ||
const watch_js = glob.sync('./src/*.js'); | ||
const watch_demo = glob.sync('./docs/*.scss'); | ||
const $ = cheerio.load(fs.readFileSync(filepath)); | ||
const title = $('title').text(); | ||
const desc = $('meta[name="description"]').attr('content').replace(/\*(.*?)\*/g, str => { | ||
return `<strong>${str.substring(1, str.length - 1)}</strong>`; | ||
}).replace(/`(.*?)`/g, str => { | ||
return `<code>${str.substring(1, str.length - 1)}</code>`; | ||
}); | ||
demos_content += `<li> | ||
<input type="checkbox" checked> | ||
<i></i> | ||
<h2>${title}</h2> | ||
<p>${desc}</p> | ||
<p><a href="./${filename}" target="_blank">Launch Demo</a></p> | ||
</li>`; | ||
}); | ||
const template_options = { | ||
demos: `<ul>${demos_content}</ul>` | ||
}; | ||
if (openHtml) { | ||
return gulp.src('./demo/src/index.html') | ||
.pipe(template(template_options)) | ||
.pipe(gulp.dest(demo_dest)) | ||
.pipe(open()); | ||
} | ||
else { | ||
return gulp.src('./demo/src/index.html') | ||
.pipe(template(template_options)) | ||
.pipe(gulp.dest(demo_dest)); | ||
} | ||
watch(watch_js, parallel(compileJs, compileDemoBrowserify)); | ||
watch(watch_demo, compileDemo); | ||
}; | ||
gulp.task('open-html', () => { | ||
compileHtml(true); | ||
}); | ||
gulp.task('main-html', () => { | ||
compileHtml(false); | ||
}); | ||
/* Gulp Tasks */ | ||
gulp.task('default', ['js', 'demo-sass', 'demo-html', 'demo-js', 'open-html']); | ||
gulp.task('watch', ['js', 'demo-sass', 'demo-html', 'demo-js', 'open-html'], () => { | ||
gulp.watch(['./src/*.js'], ['js', 'demo-js']); | ||
gulp.watch(['./demo/src/*.js'], ['demo-js']); | ||
gulp.watch(['./demo/src/*.scss'], ['demo-sass']); | ||
gulp.watch(['./demo/src/*.html'], ['demo-html', 'main-html']); | ||
}); | ||
module.exports.default = defaultTask; | ||
module.exports.watch = series(defaultTask, watchFiles); | ||
module.exports.bump = series(bumpPackage, bumpJs, compileJs); |
{ | ||
"name": "hc-sticky", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "Dependency free javascript library that makes elements on your page visible while you scroll", | ||
@@ -18,22 +18,17 @@ "homepage": "http://somewebmedia.com/hc-sticky", | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-check-es2015-constants": "^6.22.0", | ||
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0", | ||
"babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0", | ||
"babel-plugin-transform-es2015-block-scoping": "^6.26.0", | ||
"babel-plugin-transform-es2015-parameters": "^6.24.1", | ||
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1", | ||
"cheerio": "^0.22.0", | ||
"glob": "^7.1.3", | ||
"gulp": "^3.9.1", | ||
"gulp-autoprefixer": "^5.0.0", | ||
"gulp-babel": "^7.0.0", | ||
"@babel/cli": "^7.10.5", | ||
"@babel/core": "^7.11.1", | ||
"@babel/preset-env": "^7.11.0", | ||
"gulp": "^4.0.2", | ||
"gulp-autoprefixer": "^6.1.0", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-bump": "^3.2.0", | ||
"gulp-browserify": "^0.5.1", | ||
"gulp-concat": "^2.6.1", | ||
"gulp-open": "^2.0.0", | ||
"gulp-sass": "^4.0.1", | ||
"gulp-template": "^4.0.0", | ||
"gulp-uglify": "^3.0.1", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-replace": "^1.0.0", | ||
"gulp-sass": "^4.1.0", | ||
"gulp-uglify": "^3.0.2", | ||
"uglify-save-license": "^0.4.1", | ||
"yargs": "^11.1.0" | ||
"yargs": "^15.4.1" | ||
}, | ||
@@ -40,0 +35,0 @@ "keywords": [ |
HC-Sticky | ||
========= | ||
Dependency free javascript library that makes any element on your page visible while you scroll. | ||
Check out the [demos](http://somewebmedia.com/hc-sticky). | ||
JavaScript library that makes any element on your page visible while you scroll. Dependency free, but lso works as a jQuery plugin. | ||
Check out the [demos](https://somewebmedia.github.io/hc-sticky). | ||
@@ -15,3 +15,2 @@ | ||
- [npm](https://www.npmjs.com/package/hc-sticky): `npm install --save hc-sticky` | ||
- [bower](http://bower.io/search/?q=hc-sticky): `bower install --save hc-sticky` | ||
@@ -21,19 +20,3 @@ Or download the [latest release](https://github.com/somewebmedia/hc-sticky/releases). | ||
### Load | ||
#### Static HTML | ||
```html | ||
<script src="/path_to/hc-sticky.js"></script> | ||
``` | ||
#### Browserify | ||
In the script, including HC-Sticky will usually look like this: | ||
```js | ||
const hcSticky = require('hc-sticky'); | ||
``` | ||
### Usage | ||
@@ -62,2 +45,11 @@ | ||
#### Browserify | ||
In the script, including HC-Sticky will usually look like this: | ||
```js | ||
const hcSticky = require('hc-sticky'); | ||
``` | ||
## Options | ||
@@ -133,3 +125,3 @@ | ||
* `default` compiles the JS into `/dist` and builds the Demos into `demo/build`. | ||
* `default` compiles the JS into `/dist` and builds the Demos into `/docs`. | ||
* `watch` watches source JS and Demo files and builds them automatically whenever you save. | ||
@@ -136,0 +128,0 @@ |
@@ -75,60 +75,2 @@ ((window) => { | ||
/* | ||
* https://github.com/desandro/eventie | ||
*/ | ||
const event = (() => { | ||
var docElem = document.documentElement; | ||
var bind = function() {}; | ||
function getIEEvent( obj ) { | ||
var event = window.event; | ||
// add event.target | ||
event.target = event.target || event.srcElement || obj; | ||
return event; | ||
} | ||
if ( docElem.addEventListener ) { | ||
bind = function( obj, type, fn ) { | ||
obj.addEventListener( type, fn, false ); | ||
}; | ||
} else if ( docElem.attachEvent ) { | ||
bind = function( obj, type, fn ) { | ||
obj[ type + fn ] = fn.handleEvent ? | ||
function() { | ||
var event = getIEEvent( obj ); | ||
fn.handleEvent.call( fn, event ); | ||
} : | ||
function() { | ||
var event = getIEEvent( obj ); | ||
fn.call( obj, event ); | ||
}; | ||
obj.attachEvent( "on" + type, obj[ type + fn ] ); | ||
}; | ||
} | ||
var unbind = function() {}; | ||
if ( docElem.removeEventListener ) { | ||
unbind = function( obj, type, fn ) { | ||
obj.removeEventListener( type, fn, false ); | ||
}; | ||
} else if ( docElem.detachEvent ) { | ||
unbind = function( obj, type, fn ) { | ||
obj.detachEvent( "on" + type, obj[ type + fn ] ); | ||
try { | ||
delete obj[ type + fn ]; | ||
} catch ( err ) { | ||
// can't delete window object properties | ||
obj[ type + fn ] = undefined; | ||
} | ||
}; | ||
} | ||
return { | ||
bind: bind, | ||
unbind: unbind | ||
}; | ||
})(); | ||
// debounce taken from underscore | ||
@@ -298,6 +240,5 @@ const debounce = (func, wait, immediate) => { | ||
getStyle, | ||
getCascadedStyle, | ||
event | ||
getCascadedStyle | ||
}; | ||
})(window); |
@@ -1,15 +0,15 @@ | ||
/*! | ||
/* | ||
* HC-Sticky | ||
* ========= | ||
* Version: 2.2.3 | ||
* Version: 2.2.4 | ||
* Author: Some Web Media | ||
* Author URL: http://somewebmedia.com | ||
* Author URL: https://github.com/somewebmedia | ||
* Plugin URL: https://github.com/somewebmedia/hc-sticky | ||
* Description: Cross-browser plugin that makes any element on your page visible while you scroll | ||
* Description: JavaScript library that makes any element on your page visible while you scroll | ||
* License: MIT | ||
*/ | ||
'use strict'; | ||
(function(global, factory) { | ||
'use strict'; | ||
if (typeof module === 'object' && typeof module.exports === 'object') { | ||
@@ -30,4 +30,15 @@ if (global.document) { | ||
})(typeof window !== 'undefined' ? window : this, (window) => { | ||
'use strict'; | ||
const document = window.document; | ||
let supportsPassive = false; | ||
try { | ||
const opts = Object.defineProperty({}, 'passive', { | ||
get: function() { | ||
supportsPassive = {passive: false}; | ||
} | ||
}); | ||
window.addEventListener('testPassive', null, opts); | ||
window.removeEventListener('testPassive', null, opts); | ||
} catch (e) {} | ||
const DEFAULT_OPTIONS = { | ||
@@ -49,16 +60,28 @@ top: 0, | ||
resizeDebounce: 100, | ||
disable: false, | ||
// deprecated | ||
queries: null, | ||
queryFlow: 'down' | ||
disable: false | ||
}; | ||
const deprecated = (what, instead, type) => { | ||
console.log('%c! HC Sticky:' + '%c '+what + '%c '+type+' is now deprecated and will be removed. Use' + '%c '+instead + '%c instead.', 'color: red', 'color: darkviolet', 'color: black', 'color: darkviolet', 'color: black'); | ||
}; | ||
const deprecated = (() => { | ||
const pluginName = 'HC Sticky'; | ||
const document = window.document; | ||
return (what, instead, type) => { | ||
console.warn( | ||
'%c' + pluginName + ':' | ||
+ '%c ' + type | ||
+ "%c '"+ what + "'" | ||
+ '%c is now deprecated and will be removed. Use' | ||
+ "%c '" + instead + "'" | ||
+ '%c instead.', | ||
'color: #fa253b', | ||
'color: default', | ||
'color: #5595c6', | ||
'color: default', | ||
'color: #5595c6', | ||
'color: default'); | ||
}; | ||
})(); | ||
const hcSticky = function(elem, userSettings) { | ||
userSettings = userSettings || {}; | ||
// use querySeletor if string is passed | ||
@@ -70,5 +93,3 @@ if (typeof elem === 'string') { | ||
// check if element exist | ||
if (!elem) { | ||
return false; | ||
} | ||
if (!elem) return false; | ||
@@ -92,3 +113,5 @@ if (userSettings.queries) { | ||
const setOptions = (options = {}) => { | ||
const setOptions = (options) => { | ||
options = options || {}; | ||
if (Helpers.isEmptyObject(options) && !Helpers.isEmptyObject(STICKY_OPTIONS)) { | ||
@@ -198,3 +221,5 @@ // nothing to set | ||
position: null, // so we don't need to check css all the time | ||
stick: (args = {}) => { | ||
stick: (args) => { | ||
args = args || {}; | ||
// check if element is already sticky | ||
@@ -243,3 +268,4 @@ if (Helpers.hasClass(elem, STICKY_OPTIONS.stickyClass)) { | ||
}, | ||
release: (args = {}) => { | ||
release: (args) => { | ||
args = args || {}; | ||
args.stop = args.stop || false; | ||
@@ -542,3 +568,3 @@ | ||
// detach sticky from scroll | ||
Helpers.event.unbind(window, 'scroll', runSticky); | ||
window.removeEventListener('scroll', runSticky, supportsPassive); | ||
@@ -561,3 +587,3 @@ // sticky is not attached to scroll anymore | ||
// check if sticky is bigger than reffering container | ||
if (sticky_height >= container_height) { | ||
if (sticky_height > container_height) { | ||
disableSticky(); | ||
@@ -572,3 +598,3 @@ return; | ||
// attach sticky to scroll | ||
Helpers.event.bind(window, 'scroll', runSticky); | ||
window.addEventListener('scroll', runSticky, supportsPassive); | ||
@@ -649,3 +675,3 @@ // sticky is attached to scroll | ||
if (resizeAttached) { | ||
Helpers.event.unbind(window, 'resize', resize_cb); | ||
window.removeEventListener('resize', resize_cb, supportsPassive); | ||
resizeAttached = false; | ||
@@ -665,3 +691,3 @@ } | ||
if (!resizeAttached) { | ||
Helpers.event.bind(window, 'resize', resize_cb); | ||
window.addEventListener('resize', resize_cb, supportsPassive); | ||
resizeAttached = true; | ||
@@ -706,3 +732,3 @@ } | ||
// reinit on complete page load | ||
Helpers.event.bind(window, 'load', reinitSticky); | ||
window.addEventListener('load', reinitSticky); | ||
}; | ||
@@ -709,0 +735,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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
15
2
128655
21
982
130