function _classcallcheck(t,i){if(!(t instanceof i))throw new typeerror("cannot call a class as a function")}function _defineproperties(t,i){for(var e=0;e",margintop:e.margintop||0,marginbottom:e.marginbottom||0,stickyfor:e.stickyfor||0,stickyclass:e.stickyclass||null,stickycontainer:e.stickycontainer||"body"},this.updatescrolltopposition=this.updatescrolltopposition.bind(this),this.updatescrolltopposition(),window.addeventlistener("load",this.updatescrolltopposition),window.addeventlistener("scroll",this.updatescrolltopposition),this.run()}return _createclass(t,[{key:"run",value: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)}},{key:"renderelement",value: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.marginbottom=parseint(t.getattribute("data-margin-bottom"))||this.options.marginbottom,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.wrap=!!t.hasattribute("data-sticky-wrap")||this.options.wrap,t.sticky.stickycontainer=this.options.stickycontainer,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)}),t.sticky.wrap&&this.wrapelement(t),this.activate(t)}},{key:"wrapelement",value:function(t){t.insertadjacenthtml("beforebegin",t.getattribute("data-sticky-wrapwith")||this.options.wrapwith),t.previoussibling.appendchild(t)}},{key:"activate",value:function(t){t.sticky.rect.top+t.sticky.rect.height=t.sticky.container.rect.top+t.sticky.container.rect.height||t.sticky.stickyfor>=this.vp.width&&t.sticky.active)&&(t.sticky.active=!1),this.setposition(t)}},{key:"initscrollevents",value:function(t){var i=this;t.sticky.scrolllistener=function(){return i.onscrollevents(t)},window.addeventlistener("scroll",t.sticky.scrolllistener)}},{key:"destroyscrollevents",value:function(t){window.removeeventlistener("scroll",t.sticky.scrolllistener)}},{key:"onscrollevents",value:function(t){t.sticky&&t.sticky.active&&this.setposition(t)}},{key:"setposition",value: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.marginbottom?(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+t.sticky.marginbottom)+"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.sticky.wrap&&this.css(t.parentnode,{display:"",width:"",height:""})))}},{key:"update",value: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)})}},{key:"destroy",value:function(){var t=this;window.removeeventlistener("load",this.updatescrolltopposition),window.removeeventlistener("scroll",this.updatescrolltopposition),this.foreach(this.elements,function(i){t.destroyresizeevents(i),t.destroyscrollevents(i),delete i.sticky})}},{key:"getstickycontainer",value:function(t){for(var i=t.parentnode;!i.hasattribute("data-sticky-container")&&!i.parentnode.queryselector(t.sticky.stickycontainer)&&i!==this.body;)i=i.parentnode;return i}},{key:"getrectangle",value:function(t){this.css(t,{position:"",width:"",top:"",left:""});for(var i=math.max(t.offsetwidth,t.clientwidth,t.scrollwidth),e=math.max(t.offsetheight,t.clientheight,t.scrollheight),s=0,n=0;s+=t.offsettop||0,n+=t.offsetleft||0,t=t.offsetparent;);return{top:s,left:n,width:i,height:e}}},{key:"getviewportsize",value:function(){return{width:math.max(document.documentelement.clientwidth,window.innerwidth||0),height:math.max(document.documentelement.clientheight,window.innerheight||0)}}},{key:"updatescrolltopposition",value:function(){this.scrolltop=(window.pageyoffset||document.scrolltop)-(document.clienttop||0)||0}},{key:"foreach",value:function(t,i){for(var e=0,s=t.length;e1&&(this.progress=1),this.progress},this.getpara=function(){var i=t.elements[0],e=t.getstickycontainer(i);this.starttop=i.sticky.rect.top-i.sticky.margintop,this.distance=e.offsetheight-i.sticky.rect.height},this.init()}var i=this;return new t(i)}}]),t}();!function(t,i){"undefined"!=typeof exports?module.exports=i:"function"==typeof define&&define.amd?define([],function(){return i}):t.sticky=i}(this,sticky);