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UAAA,GAAG,GAEvC,OAAO,WAAa,QAAAG,EAAAH,UAAAC,OAATG,EAAI,IAAAC,MAAAF,GAAAG,EAAA,EAAAA,EAAAH,EAAAG,IAAJF,EAAIE,GAAAN,UAAAM,GACbC,aAAaT,GACbA,EAAQU,YAAW,WACjBX,EAAKY,W,EAAYL,EACnB,GAAGL,EACL,CACF,C","sources":["webpack://@upstatement/harvard-law-school-wp-theme/./static/js/components/sticky-sidebar.js","webpack://@upstatement/harvard-law-school-wp-theme/./static/js/utils/throttle-debounce.js"],"sourcesContent":["import { debounce } from '@src/utils';\nconst BP_SIDEBAR = 768;\n\nclass StickySidebar {\n constructor(el) {\n this.el = el;\n this.body = document.querySelector('body');\n this.sidebarTopEl = el.querySelector('.sticky-sidebar__top');\n this.sidebarBottomEl = document.querySelector('.sticky-sidebar__bottom');\n this.siteFooterEl = document.querySelector('.footer');\n this.siteNavEl = document.querySelector('.nav');\n this.wpAdminBar = document.querySelector('#wpadminbar');\n\n // Bind.\n this.checkSidebar = debounce(this.checkSidebarFn.bind(this), 100);\n\n // Run on load\n this.checkSidebarFn();\n\n // And on window resize\n window.addEventListener('resize', this.checkSidebar);\n }\n\n checkSidebarFn() {\n const buffer = 10; // extra padding\n const siteFooterHeight = this.siteFooterEl ? this.siteFooterEl.offsetHeight : 0;\n const siteNavHeight = this.siteNavEl ? this.siteNavEl.offsetHeight : 0;\n const wpAdminBarHeight = this.wpAdminBar ? this.wpAdminBar.offsetHeight : 0;\n\n // Available space: site nav and footer aren't on the screen at the same time, so just take the larger\n const containerHeight =\n window.innerHeight - (buffer + wpAdminBarHeight + Math.max(siteNavHeight, siteFooterHeight));\n\n // Contents\n const contentsTopHeight = this.sidebarTopEl ? this.sidebarTopEl.offsetHeight : 0;\n const contentsBottomHeight = this.sidebarBottomEl ? this.sidebarBottomEl.offsetHeight : 0;\n const contentsHeight = contentsTopHeight + contentsBottomHeight;\n\n const sidebarActive = window.matchMedia(`(min-width: ${BP_SIDEBAR}px)`).matches;\n\n if (\n sidebarActive &&\n contentsHeight < containerHeight &&\n !this.body.classList.contains('single-event')\n ) {\n this.body.classList.remove('sidebar-overflow');\n } else {\n this.body.classList.add('sidebar-overflow');\n }\n }\n\n deinit() {\n window.removeEventListener('resize', this.checkSidebar);\n }\n}\n\nexport default StickySidebar;\n","export const debounce = (func, timeout = 15) => {\n let timer;\n return (...args) => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n func.apply(this, args);\n }, timeout);\n };\n};\n\nexport const throttle = (func, timeFrame) => {\n let lastTime = 0;\n return function(...args) {\n const now = new Date();\n if (now - lastTime >= timeFrame) {\n func(...args);\n lastTime = now;\n }\n };\n};\n"],"names":["StickySidebar","el","_classCallCheck","this","body","document","querySelector","sidebarTopEl","sidebarBottomEl","siteFooterEl","siteNavEl","wpAdminBar","checkSidebar","debounce","checkSidebarFn","bind","window","addEventListener","key","value","siteFooterHeight","offsetHeight","siteNavHeight","wpAdminBarHeight","containerHeight","innerHeight","Math","max","contentsHeight","matchMedia","concat","matches","classList","contains","remove","add","removeEventListener","func","timer","timeout","arguments","length","undefined","_len","args","Array","_key","clearTimeout","setTimeout","apply"],"sourceRoot":""}