From 5e3a635be55f4f1d27d9f6cbf9453961f708e44d Mon Sep 17 00:00:00 2001 From: rgalus Date: Wed, 12 Oct 2016 20:51:17 +0200 Subject: [PATCH] 1.1.3 --- README.md | 2 +- bower.json | 2 +- dist/sticky.compile.js | 4 ++-- dist/sticky.min.js | 2 +- dist/sticky.min.js.gz | Bin 1396 -> 1396 bytes package.json | 2 +- src/sticky.js | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index da055e2..8d859ba 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.82kb, gzipped: ~1.46kb) +- Lightweight (minified: ~4.68kb, gzipped: ~1.40kb) - 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 b45f838..0390518 100644 --- a/bower.json +++ b/bower.json @@ -18,5 +18,5 @@ "test", "tests" ], - "version": "1.1.2" + "version": "1.1.3" } diff --git a/dist/sticky.compile.js b/dist/sticky.compile.js index 184535a..cf5bd89 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.2 + * @version 1.1.3 * @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.2'; + this.version = '1.1.3'; this.vp = this.getViewportSize(); this.scrollTop = this.getScrollTopPosition(); diff --git a/dist/sticky.min.js b/dist/sticky.min.js index 9c10ab8..6a6d0fe 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.2",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=void 0,e=void 0;i=t.sticky.container.offsetHeight,this.addStyle(t,{position:"fixed"}),e=t.sticky.container.offsetHeight,this.removeStyle(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.removeStyle(t,["position","width","top","left"]),this.vp.heightt.sticky.rect.top-t.sticky.marginTop?(this.addStyle(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.addStyle(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.addStyle(t,{top:t.sticky.marginTop+"px"}))):(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.removeStyle(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.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.removeStyle(t,["position","width","top","left"]);var i=0,e=0,s=0,o=0;s=t.offsetWidth,o=t.offsetHeight;do i+=t.offsetTop||0,e+=t.offsetLeft||0,t=t.offsetParent;while(t);return{top:i,left:e,width:s,height:o}},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.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=void 0,e=void 0;i=t.sticky.container.offsetHeight,this.addStyle(t,{position:"fixed"}),e=t.sticky.container.offsetHeight,this.removeStyle(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.removeStyle(t,["position","width","top","left"]),this.vp.heightt.sticky.rect.top-t.sticky.marginTop?(this.addStyle(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.addStyle(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.addStyle(t,{top:t.sticky.marginTop+"px"}))):(t.sticky.stickyClass&&t.classList.remove(t.sticky.stickyClass),this.removeStyle(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.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.removeStyle(t,["position","width","top","left"]);var i=0,e=0,s=0,o=0;s=t.offsetWidth,o=t.offsetHeight;do i+=t.offsetTop||0,e+=t.offsetLeft||0,t=t.offsetParent;while(t);return{top:i,left:e,width:s,height:o}},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;eOjcXF0@(&U}Yru$>qv%pdmzGlAp z4GKsh)>1{nt#N62qnDZ6*nlcfi-=5uN$?XXH}lB;E~TfjULABdhkQNv0k(dLh;|%Wt^g*&+qnr)+Rv;$c1!tAzN;$i=%NdKEK||?9%I;SwZf@7I1@>(0%3V_4$BcRhVzJcaRY~%!cjk6~pO+P3O6KAf5`Ti?z-=fBR&oOs&;tk-(N_2~Ye(&uJ3 zKY#R{Jnf_0M;(|Of@M-SR$ceHbB=FD##P6=hI+;Ey;!^Gcn8;Td>g;#_=~cBPq*)y z?y8jukg4U@xxwh1kEclT^acSoW7 zHV_JT*Ke^8^lEwZtq9XIVvR`tN_?Yl=YP~}*~4R3sL?qyjQVojU&v3R#^_3|exRMi zvhCI6lI_7J=t^&%C1m}MftOByK%hH%gArJ1FgCqGd=&0K$zI#Hy6mRgt{dxnlY@0K zZ=ENtcHbP2LwiFtrndTGYh)Ge3~8r_V7@r-z#irKa^EN$b_i~X-=EN0^#f(6Wq*+k z2O?PV;?j&*u@g2Nia~T?h^OSMOm>8YOyF>Z(=1YakO_oUZSF}|tM}t|Ep(cg5e#36 z@Lxvb(2Tw=;=dRk+|#WL2ovdvQN3BdXu)acJ%XDpUGIFdYK7aSu+^>9&4#mZH3!Pd zRQN7~rt;WRyg3;3yV%|V{L1wbQ-9-?*5*xgAqCyH|hzL<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jc`9_1eAn?cORyH}2p`X6E>WuSRDZ;H# zu-HsXo;2c1^n^Rn(%O_rKoEUyE}>IL~+i*7n5=O+A`xB5o11N zRI%*5ugh-(A-pL<7>$^q`UPg)alR}^m!Ld>G0SXXeB5TAl*~ct9R*g7J7vg!hZlV$drRf5&!@~j>tm* diff --git a/package.json b/package.json index 116f6bd..f2945e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sticky-js", - "version": "1.1.2", + "version": "1.1.3", "description": "Sticky elements", "main": "index.js", "scripts": { diff --git a/src/sticky.js b/src/sticky.js index 3fae5f7..35035d7 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.2 + * @version 1.1.3 * @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.2'; + this.version = '1.1.3'; this.vp = this.getViewportSize(); this.scrollTop = this.getScrollTopPosition();