From 357125185f067c2517105c5a21f09683d208f47c Mon Sep 17 00:00:00 2001 From: rgalus Date: Wed, 12 Oct 2016 23:58:20 +0200 Subject: [PATCH] 1.1.4 --- README.md | 2 +- bower.json | 2 +- dist/sticky.compile.js | 4 ++-- dist/sticky.min.js | 2 +- dist/sticky.min.js.gz | Bin 1411 -> 1412 bytes package.json | 2 +- src/sticky.js | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8d859ba..550372a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Sticky-js is a library for sticky elements written in vanilla javascript. With t ## Features - Written in vanilla javascript, no dependencies needed -- Lightweight (minified: ~4.68kb, gzipped: ~1.40kb) +- Lightweight (minified: ~4.75kb, gzipped: ~1.41kb) - It can be sticky to the entire page or to selected parent container - No additional CSS needed diff --git a/bower.json b/bower.json index 0390518..5b855db 100644 --- a/bower.json +++ b/bower.json @@ -18,5 +18,5 @@ "test", "tests" ], - "version": "1.1.3" + "version": "1.1.4" } diff --git a/dist/sticky.compile.js b/dist/sticky.compile.js index bc08813..57adb19 100644 --- a/dist/sticky.compile.js +++ b/dist/sticky.compile.js @@ -4,7 +4,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * Sticky.js * Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive. * - * @version 1.1.3 + * @version 1.1.4 * @author Rafal Galus * @website https://rgalus.github.io/sticky-js/ * @repo https://github.com/rgalus/sticky-js @@ -27,7 +27,7 @@ var Sticky = function () { this.selector = selector; this.elements = []; - this.version = '1.1.3'; + this.version = '1.1.4'; this.vp = this.getViewportSize(); this.scrollTop = this.getScrollTopPosition(); diff --git a/dist/sticky.min.js b/dist/sticky.min.js index fbd6977..3ff13a6 100644 --- a/dist/sticky.min.js +++ b/dist/sticky.min.js @@ -1 +1 @@ -function _classCallCheck(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}var Sticky=function(){function t(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,t),this.selector=i,this.elements=[],this.version="1.1.3",this.vp=this.getViewportSize(),this.scrollTop=this.getScrollTopPosition(),this.options={marginTop:e.marginTop||0,stickyFor:e.stickFor||0,stickyClass:e.stickyClass||null},this.run()}return t.prototype.run=function(){var t=this,i=setInterval(function(){if("complete"===document.readyState){clearInterval(i);var e=document.querySelectorAll(t.selector);t.forEach(e,function(i){return t.renderElement(i)})}},10)},t.prototype.renderElement=function(t){var i=this;t.sticky={},t.sticky.active=!1,t.sticky.marginTop=parseInt(t.getAttribute("data-margin-top"))||this.options.marginTop,t.sticky.stickyFor=parseInt(t.getAttribute("data-sticky-for"))||this.options.stickyFor,t.sticky.stickyClass=t.getAttribute("data-sticky-class")||this.options.stickyClass,t.sticky.container=this.getStickyContainer(t),t.sticky.container.rect=this.getRectangle(t.sticky.container),t.sticky.rect=this.getRectangle(t),"img"===t.tagName.toLowerCase&&(t.onload=function(){return t.sticky.rect=i.getRectangle(t)}),this.activate(t)},t.prototype.activate=function(t){var i=t.sticky.container.offsetHeight;this.css(t,{position:"fixed"});var e=t.sticky.container.offsetHeight;this.css(t,{position:""}),e>=i&&t.sticky.stickyFor=this.vp.width&&t.sticky.active&&(t.sticky.active=!1),this.setPosition(t)},t.prototype.initScrollEvents=function(t){var i=this;t.sticky.scrollListener=function(){return i.onScrollEvents(t)},window.addEventListener("scroll",t.sticky.scrollListener)},t.prototype.onScrollEvents=function(t){this.scrollTop=this.getScrollTopPosition(),t.sticky.active&&this.setPosition(t)},t.prototype.setPosition=function(t){this.css(t,{position:"",width:"",top:"",left:""}),this.vp.heightt.sticky.rect.top-t.sticky.marginTop?(this.css(t,{position:"fixed",width:t.sticky.rect.width+"px",left:t.sticky.rect.left+"px"}),this.scrollTop+t.sticky.rect.height+t.sticky.marginTop>t.sticky.container.rect.top+t.sticky.container.offsetHeight?(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.css(t,{top:t.sticky.container.rect.top+t.sticky.container.offsetHeight-(this.scrollTop+t.sticky.rect.height)+"px"})):(t.sticky.stickyClass&&t.classList.add(t.sticky.stickyClass),this.css(t,{top:t.sticky.marginTop+"px"}))):(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.css(t,{position:"",width:"",top:"",left:""})))},t.prototype.update=function(){var t=this;this.forEach(this.elements,function(i){i.sticky.rect=t.getRectangle(i),i.sticky.container.rect=t.getRectangle(i.sticky.container),t.activate(i),t.setPosition(i)})},t.prototype.getStickyContainer=function(t){for(var i=t;!i.hasAttribute("data-sticky-container")&&i!==document.querySelector("body");)i=i.parentNode;return i},t.prototype.getRectangle=function(t){this.css(t,{position:"",width:"",top:"",left:""});var i=Math.max(t.offsetWidth,t.clientWidth,t.scrollWidth),e=Math.max(t.offsetHeight,t.clientHeight,t.scrollHeight),s=0,o=0;do s+=t.offsetTop||0,o+=t.offsetLeft||0,t=t.offsetParent;while(t);return{top:s,left:o,width:i,height:e}},t.prototype.getViewportSize=function(){return{width:Math.max(document.documentElement.clientWidth,window.innerWidth||0),height:Math.max(document.documentElement.clientHeight,window.innerHeight||0)}},t.prototype.getScrollTopPosition=function(){return(window.pageYOffset||document.scrollTop)-(document.clientTop||0)||0},t.prototype.forEach=function(t,i){for(var e=0,s=t.length;e0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,t),this.selector=i,this.elements=[],this.version="1.1.4",this.vp=this.getViewportSize(),this.scrollTop=this.getScrollTopPosition(),this.options={marginTop:e.marginTop||0,stickyFor:e.stickFor||0,stickyClass:e.stickyClass||null},this.run()}return t.prototype.run=function(){var t=this,i=setInterval(function(){if("complete"===document.readyState){clearInterval(i);var e=document.querySelectorAll(t.selector);t.forEach(e,function(i){return t.renderElement(i)})}},10)},t.prototype.renderElement=function(t){var i=this;t.sticky={},t.sticky.active=!1,t.sticky.marginTop=parseInt(t.getAttribute("data-margin-top"))||this.options.marginTop,t.sticky.stickyFor=parseInt(t.getAttribute("data-sticky-for"))||this.options.stickyFor,t.sticky.stickyClass=t.getAttribute("data-sticky-class")||this.options.stickyClass,t.sticky.container=this.getStickyContainer(t),t.sticky.container.rect=this.getRectangle(t.sticky.container),t.sticky.rect=this.getRectangle(t),"img"===t.tagName.toLowerCase&&(t.onload=function(){return t.sticky.rect=i.getRectangle(t)}),this.activate(t)},t.prototype.activate=function(t){var i=t.sticky.container.offsetHeight;this.css(t,{position:"fixed"});var e=t.sticky.container.offsetHeight;this.css(t,{position:""}),e>=i&&t.sticky.stickyFor=this.vp.width&&t.sticky.active&&(t.sticky.active=!1),this.setPosition(t)},t.prototype.initScrollEvents=function(t){var i=this;t.sticky.scrollListener=function(){return i.onScrollEvents(t)},window.addEventListener("scroll",t.sticky.scrollListener)},t.prototype.onScrollEvents=function(t){this.scrollTop=this.getScrollTopPosition(),t.sticky.active&&this.setPosition(t)},t.prototype.setPosition=function(t){this.css(t,{position:"",width:"",top:"",left:""}),this.vp.heightt.sticky.rect.top-t.sticky.marginTop?(this.css(t,{position:"fixed",width:t.sticky.rect.width+"px",left:t.sticky.rect.left+"px"}),this.scrollTop+t.sticky.rect.height+t.sticky.marginTop>t.sticky.container.rect.top+t.sticky.container.offsetHeight?(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.css(t,{top:t.sticky.container.rect.top+t.sticky.container.offsetHeight-(this.scrollTop+t.sticky.rect.height)+"px"})):(t.sticky.stickyClass&&t.classList.add(t.sticky.stickyClass),this.css(t,{top:t.sticky.marginTop+"px"}))):(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.css(t,{position:"",width:"",top:"",left:""})))},t.prototype.update=function(){var t=this;this.forEach(this.elements,function(i){i.sticky.rect=t.getRectangle(i),i.sticky.container.rect=t.getRectangle(i.sticky.container),t.activate(i),t.setPosition(i)})},t.prototype.getStickyContainer=function(t){for(var i=t;!i.hasAttribute("data-sticky-container")&&i!==document.querySelector("body");)i=i.parentNode;return i},t.prototype.getRectangle=function(t){this.css(t,{position:"",width:"",top:"",left:""});var i=Math.max(t.offsetWidth,t.clientWidth,t.scrollWidth),e=Math.max(t.offsetHeight,t.clientHeight,t.scrollHeight),s=0,o=0;do s+=t.offsetTop||0,o+=t.offsetLeft||0,t=t.offsetParent;while(t);return{top:s,left:o,width:i,height:e}},t.prototype.getViewportSize=function(){return{width:Math.max(document.documentElement.clientWidth,window.innerWidth||0),height:Math.max(document.documentElement.clientHeight,window.innerHeight||0)}},t.prototype.getScrollTopPosition=function(){return(window.pageYOffset||document.scrollTop)-(document.clientTop||0)||0},t.prototype.forEach=function(t,i){for(var e=0,s=t.length;emoN$7=!avWtNjqN3}R$Z;_b8P+h&c5i~j-94p zuy%Il*?HfQ7Mm=VjAzc@aY~Egfu`xh3gWMx^cgv@g*Wn~!?HrsEC#-C7$I^c_|C~- z=X~1d@F)Zqp8G(vj7uj*d51b0%c1yl7WM#_lv^sCC&}Wk`+umSdgM?&IuaL(g+){> zH*3gb5u}hU;bml8cC$H7>Pm^!#E7TMz|W5xKKq7X0E`Vjk)LCCEP+>~b#T6Z-~U1sV&Urk{Aj z^;A(l@`4!$8Glxut5p#l)~GhikYf%({d_!5{X%>8S1xcvKjULVe^9nnJ7#q}W}7rE z4ZhgmQKbO65g3Ue7hH0Q;Z+;$XsG~6t*+0a0_1O*1hJ*5*W$sfabv#DQ;^_BQIzml zJ30_Rll_yV638J=fr?t1kx(H+!~4$$#Qw>8{Y{#BvVV>N31zV0;*rKH5B&OI%-33f z0a*g#(F6&1N>Y~oY)a7Dwry>$#!6Y`p)wQCGCqqAO4vLH6gjsLjb;t04n~wyQ2?5T zDq~3BNGaHtjRen4sH8WB??&?6CFFQ)N4LRfVC%46fHizK=$9dEjnRkIc@TXMPuGNd z8c<6&kbg1HBxMKx1#QPj~n7O|j~PT|j{i@NtW~$D?ksD9_N(HMuy)Z;q~Q(4BGs^wf~M zKrMa+)Q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dh+aP|(AZn-)7`y%Q>;2+7f@gWeB9#h@u*uY$}{wHO)k#yo1<$Rbf+8uJvHPm zP>WvybtBhT;ZiTKYQ1BH1eNf^Tw<7JJ)=s0hpytgfF_A1R^py(;M~616+=(kE^}E(YGD(S^YGlJGl$H*ju0 zP0t4Ytgb&YPxM`P(Mzqp;i1EZ#hrg`rQmK@O$rj?bup(LVu%)o4;CPySs{{H_N_0lT#j;3{|>2QRdK>Pg?*s)Y3Au5t~r)_e;m8Li6J8!Dndq05bTh5f|(ip;Oj9Bb-F)vmo- zopaSeSG(w{N+7)w+vG`Sa%fN5=3=iV-p&QvnSNQf9J;l@h|f;PZNPc5uh&x#(|;YL z)h+aN-7#i3`gPg{TH@K>8je`7qQ$x4vl4g7c+5u8nYRPa{lb&IOG3hMYQr%ZIo|UG z!m1??w5yH%xpo#BD}JYPg-P|QW=oyxpOt{Gl82!x)ygEjUg1PGlrj}ki`7dbXO_e- zqN&fLX_#=Qm_(JVeFx+XRrrywg}<22y|gGAXiHx{!b;lHP4 J=)H^*004;^#Z&+Q diff --git a/package.json b/package.json index f2945e7..472641b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sticky-js", - "version": "1.1.3", + "version": "1.1.4", "description": "Sticky elements", "main": "index.js", "scripts": { diff --git a/src/sticky.js b/src/sticky.js index e398784..41053e8 100644 --- a/src/sticky.js +++ b/src/sticky.js @@ -3,7 +3,7 @@ * Sticky.js * Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive. * - * @version 1.1.3 + * @version 1.1.4 * @author Rafal Galus * @website https://rgalus.github.io/sticky-js/ * @repo https://github.com/rgalus/sticky-js @@ -21,7 +21,7 @@ class Sticky { this.selector = selector; this.elements = []; - this.version = '1.1.3'; + this.version = '1.1.4'; this.vp = this.getViewportSize(); this.scrollTop = this.getScrollTopPosition();