This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
cookthebooks-legacy/js/sticky-sidebar.min.js

1 line
12 KiB
JavaScript
Raw Permalink Normal View History

2023-09-08 01:45:46 -07:00
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).StickySidebar={})}(this,function(e){"use strict";var t,i,n=(function(e){!function(e){function s(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}Object.defineProperty(e,"__esModule",{value:true});var t=function(){function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||false;n.configurable=true;if("value"in n)n.writable=true;Object.defineProperty(e,n.key,n)}}return function(e,t,i){if(t)n(e.prototype,t);if(i)n(e,i);return e}}(),i=function(){var d=".stickySidebar";var n={topSpacing:0,bottomSpacing:0,containerSelector:false,scrollContainer:false,innerWrapperSelector:".inner-wrapper-sticky",stickyClass:"is-affixed",minWidth:false};var e=function(){function h(e){var t=this;var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};s(this,h);this.options=h.extend(n,i);this.sidebar="string"===typeof e?document.querySelector(e):e;if("undefined"===typeof this.sidebar)throw new Error("There is no specific sidebar element.");this.sidebarInner=false;this.container=this.sidebar.parentElement;this.affixedType="STATIC";this.direction="down";this.support={transform:false,transform3d:false};this._initialized=false;this._reStyle=false;this._breakpoint=false;this.dimensions={translateY:0,maxTranslateY:0,topSpacing:0,lastTopSpacing:0,bottomSpacing:0,lastBottomSpacing:0,sidebarHeight:0,sidebarWidth:0,containerTop:0,containerHeight:0,viewportHeight:0,viewportTop:0,lastViewportTop:0};["handleEvent"].forEach(function(e){t[e]=t[e].bind(t)});this.initialize()}t(h,[{key:"initialize",value:function e(){var i=this;this._setSupportFeatures();if(this.options.innerWrapperSelector){this.sidebarInner=this.sidebar.querySelector(this.options.innerWrapperSelector);if(null===this.sidebarInner)this.sidebarInner=false}if(!this.sidebarInner){var t=document.createElement("div");t.setAttribute("class","inner-wrapper-sticky");this.sidebar.appendChild(t);while(this.sidebar.firstChild!=t){t.appendChild(this.sidebar.firstChild)}this.sidebarInner=this.sidebar.querySelector(".inner-wrapper-sticky")}if(this.options.containerSelector){var n=document.querySelectorAll(this.options.containerSelector);n=Array.prototype.slice.call(n);n.forEach(function(e,t){if(!e.contains(i.sidebar))return;i.container=e});if(!n.length)throw new Error("The container does not contains on the sidebar.")}this.scrollContainer=this.options.scrollContainer?document.querySelector(this.options.scrollContainer):undefined;if("function"!==typeof this.options.topSpacing)this.options.topSpacing=parseInt(this.options.topSpacing)||0;if("function"!==typeof this.options.bottomSpacing)this.options.bottomSpacing=parseInt(this.options.bottomSpacing)||0;this._widthBreakpoint();this.calcDimensions();this.stickyPosition();this.bindEvents();this._initialized=true}},{key:"bindEvents",value:function e(){var t=this;this.eventTarget=this.scrollContainer?this.scrollContainer:window;this.eventTarget.addEventListener("resize",this,{passive:true,capture:false});this.eventTarget.addEventListener("scroll",this,{passive:true,capture:false});this.sidebar.addEventListener("update"+d,this);if("undefined"!==typeof ResizeObserver){var i=new ResizeObserver(function(){return t.handleEvent()});i.observe(this.sidebarInner);i.observe(this.container)}}},{key:"handleEvent",value:function e(t){this.updateSticky(t)}},{key:"calcDimensions",value:function e(){if(this._breakpoint)return;var t=this.dimensions;t.containerTop=h.offsetRelative(this.container).top;t.containerHeight=this.container.clientHeight;t.containerBottom=t.containerTop+t.containerHeight;t.sidebarHeight=this.sidebarInner.offsetHeight;t.sidebarWidth=this.sidebarInner.offsetWidth;t.viewportHeight=window.innerHeight;t.maxTranslateY=t.containerHeight-t.sidebarHeight;this._calcDimensionsWithScroll()}},{key:"_calcDimensionsWithScroll",value:function e(){var t=this.dimensions;t.sidebarLeft=h.offsetRelative(this.sidebar).left;if(this.scrollContainer){t.viewportTop=th