/** * sticky-sidebar-v2 - A JavaScript plugin for making smart and high performance sticky sidebars. * @version v1.1.0 * @link https://github.com/blixhavn/sticky-sidebar-v2 * @author Øystein Blixhavn * @license The MIT License (MIT) **/ !function(t,e){"function"==typeof define&&define.amd?define(["exports"],e):"undefined"!=typeof exports?e(exports):(e(e={}),t.stickySidebar=e)}(this,function(t){"use strict";function n(t,e){for(var i=0;i=this.dimensions.lastBottomSpacing+this.dimensions.lastTopSpacing+this.dimensions.sidebarHeight}},{key:"observeScrollDir",value:function(){var t,e=this.dimensions;e.lastViewportTop!==e.viewportTop&&(t="down"===this.direction?Math.min:Math.max,e.viewportTop===t(e.viewportTop,e.lastViewportTop)&&(this.direction="down"===this.direction?"up":"down"))}},{key:"getAffixType",value:function(){this._calcDimensionsWithScroll();var t=this.dimensions,e=t.viewportTop+t.topSpacing,i=this.affixedType,i=e<=t.containerTop||t.containerHeight<=t.sidebarHeight?(t.translateY=0,"STATIC"):"up"===this.direction?this._getAffixTypeScrollingUp():this._getAffixTypeScrollingDown();return t.translateY=Math.max(0,t.translateY),t.translateY=Math.min(t.containerHeight,t.translateY),t.translateY=Math.round(t.translateY),t.lastViewportTop=t.viewportTop,i}},{key:"_getAffixTypeScrollingDown",value:function(){var t=this.dimensions,e=t.sidebarHeight+t.containerTop,i=t.viewportTop+t.topSpacing,n=t.viewportBottom-t.bottomSpacing,s=this.affixedType;return this.isSidebarFitsViewport()?t.sidebarHeight+i>=t.containerBottom?(t.translateY=t.containerBottom-e,s="CONTAINER-BOTTOM"):i>=t.containerTop&&(t.translateY=i-t.containerTop,s="VIEWPORT-TOP"):t.containerBottom<=n?(t.translateY=t.containerBottom-e,s="CONTAINER-BOTTOM"):e+t.translateY<=n?(t.translateY=n-e,s="VIEWPORT-BOTTOM"):t.containerTop+t.translateY<=i&&0!==t.translateY&&t.maxTranslateY!==t.translateY&&(s="VIEWPORT-UNBOTTOM"),s}},{key:"_getAffixTypeScrollingUp",value:function(){var t=this.dimensions,e=t.sidebarHeight+t.containerTop,i=t.viewportTop+t.topSpacing,n=t.viewportBottom-t.bottomSpacing,s=this.affixedType;return i<=t.translateY+t.containerTop?(t.translateY=i-t.containerTop,s="VIEWPORT-TOP"):t.containerBottom<=n?(t.translateY=t.containerBottom-e,s="CONTAINER-BOTTOM"):this.isSidebarFitsViewport()||t.containerTop<=i&&0!==t.translateY&&t.maxTranslateY!==t.translateY&&(s="VIEWPORT-UNBOTTOM"),s}},{key:"_getStyle",value:function(t){if(void 0!==t){var e={inner:{},outer:{}},i=this.dimensions;switch(t){case"VIEWPORT-TOP":e.inner={position:"fixed",top:i.topSpacing,left:i.sidebarLeft-i.viewportLeft,width:i.sidebarWidth};break;case"VIEWPORT-BOTTOM":e.inner={position:"fixed",top:"auto",left:i.sidebarLeft,bottom:i.bottomSpacing,width:i.sidebarWidth};break;case"CONTAINER-BOTTOM":case"VIEWPORT-UNBOTTOM":var n=this._getTranslate(0,i.translateY+"px");e.inner=n?{transform:n}:{position:"absolute",top:i.translateY,width:i.sidebarWidth}}switch(t){case"VIEWPORT-TOP":case"VIEWPORT-BOTTOM":case"VIEWPORT-UNBOTTOM":case"CONTAINER-BOTTOM":e.outer={height:i.sidebarHeight,position:"relative"}}return e.outer=p.extend({height:"",position:""},e.outer),e.inner=p.extend({position:"relative",top:"",left:"",bottom:"",width:"",transform:""},e.inner),e}}},{key:"stickyPosition",value:function(t){if(!this._breakpoint){t=this._reStyle||t||!1;this.options.topSpacing,this.options.bottomSpacing;var e=this.getAffixType(),i=this._getStyle(e);if((this.affixedType!=e||t)&&e){var n,s,t="affix."+e.toLowerCase().replace("viewport-","")+a;for(n in p.eventTrigger(this.sidebar,t),"STATIC"===e?p.removeClass(this.sidebar,this.options.stickyClass):p.addClass(this.sidebar,this.options.stickyClass),i.outer){var o="number"==typeof i.outer[n]?"px":"";this.sidebar.style[n]=i.outer[n]+o}for(s in i.inner){var r="number"==typeof i.inner[s]?"px":"";this.sidebarInner.style[s]=i.inner[s]+r}t="affixed."+e.toLowerCase().replace("viewport-","")+a;p.eventTrigger(this.sidebar,t)}else this._initialized&&(this.sidebarInner.style.left=i.inner.left);this.affixedType=e}}},{key:"_widthBreakpoint",value:function(){window.innerWidth<=this.options.minWidth?(this._breakpoint=!0,this.affixedType="STATIC",this.sidebar.removeAttribute("style"),p.removeClass(this.sidebar,this.options.stickyClass),this.sidebarInner.removeAttribute("style")):this._breakpoint=!1}},{key:"updateSticky",value:function(){var t,e=this,i=0