!function(){class t{constructor(t,e){this.container=t,this.selectorText=e.replace(/^\./,""),this.button=this.container.querySelector(e+"__button"),this.sidebar=document.querySelector(".ld-focus-sidebar"),this.sidebarTransitionLength=300,this.sidebarToggle=document.getElementById("ld-focus-sidebar-toggle"),this.header=document.querySelector(".ld-focus-header"),this.headerTransitionLength=300,this.body=document.querySelector(e+"__body"),this.focusTabletBreakpoint=1023,this.focusMobileBreakpoint=768,this.windowWidth=window.innerWidth,this.isMobile=this.windowWidth<=this.focusMobileBreakpoint,this.focusModeResizeTimeout=150}init(){this.button.addEventListener("click",this.toggleState.bind(this)),this.sidebar.addEventListener("ld-focus-sidebar-opened",this.sidebarVisibilityStateChange.bind(this,!0)),this.sidebar.addEventListener("ld-focus-sidebar-closed",this.sidebarVisibilityStateChange.bind(this,!1)),["pointerenter","pointerdown"].forEach((t=>{this.container.addEventListener(t,this.detectMouseEvents.bind(this))})),["resize","orientationchange"].forEach((t=>{window.addEventListener(t,this.handleResize.bind(this))})),this.initializeSidebar(this.getState().sidebar),this.windowWidth>this.focusMobileBreakpoint&&this.getState().active&&this.enable()}enable(){this.container.classList.add(this.selectorText+"--active"),this.setState({active:!0}),this.toggleHeader(!1),this.toggleSidebar(!1),this.button.setAttribute("aria-expanded","false")}disable(){this.container.classList.remove(this.selectorText+"--active"),this.setState({active:!1}),this.toggleHeader(!0),this.toggleSidebar(!this.isMobile),this.button.setAttribute("aria-expanded","true")}toggleState(){this.getState().active?this.disable():this.enable()}getState(){const t=this.selectorText+"_"+this.container.dataset?.course_id,e=JSON.parse(sessionStorage.getItem(t));return Object.assign({active:this.container.classList.contains(this.selectorText+"--active"),sidebar:!this.sidebar.classList.contains("ld-focus-sidebar-collapsed")},e)}setState(t){const e=this.selectorText+"_"+this.container.dataset?.course_id,i=this.getState();t=Object.assign(i,t),sessionStorage.setItem(e,JSON.stringify(t))}sidebarVisibilityStateChange(t){this.container.classList.toggle(this.selectorText+"--focus-mode-sidebar-opened",t),this.container.classList.toggle(this.selectorText+"--focus-mode-sidebar-closed",!t),this.setState({sidebar:t})}detectMouseEvents(t){"mouse"===t.pointerType?this.container.classList.add(this.selectorText+"--pointer-device"):this.container.classList.remove(this.selectorText+"--pointer-device")}handleResize(){this.windowWidth!==window.innerWidth&&setTimeout((()=>{window.requestAnimationFrame((()=>{this.windowWidth=window.innerWidth;const t=this.isMobile;this.windowWidth<=this.focusMobileBreakpoint?this.isMobile=!0:this.isMobile=!1,this.getState().active&&t!==this.isMobile&&(this.isMobile?(this.disable(),this.setState({active:!0})):this.enable())}))}),this.focusModeResizeTimeout)}initializeSidebar(){if(this.windowWidth<=this.focusMobileBreakpoint)return void this.loaded();const t=this.getState().sidebar;if(this.windowWidth<=this.focusTabletBreakpoint&&t){const e=setInterval((()=>{this.sidebar.parentElement.classList.contains("ld-focus-initial-transition")||(this.forceSidebarState(t).then((()=>{this.loaded()})),clearTimeout(e))}),20)}else this.forceSidebarState(t).then((()=>{this.getState().active||this.loaded()}))}forceSidebarState(t){return new Promise((e=>{t===!this.sidebar.parentElement.classList.contains("ld-focus-sidebar-collapsed")&&e();const i=setInterval((()=>{this.sidebarToggle.click(),t===!this.sidebar.parentElement.classList.contains("ld-focus-sidebar-collapsed")&&(clearInterval(i),setTimeout((()=>{e()}),this.sidebarTransitionLength))}),20)}))}loaded(){this.body.classList.add(this.selectorText+"__body--loaded")}toggleHeader(t){t&&(this.header.style.visibility="",this.header.offsetHeight),this.header.style.opacity=t?"":"0",t||setTimeout((()=>{this.header.style.visibility="hidden"}),this.headerTransitionLength)}toggleSidebar(t){const e=this.getState();this.forceSidebarState(t).then((()=>{this.setState({sidebar:e.sidebar})})),t&&(this.sidebar.style.display="",this.sidebar.offsetHeight),this.sidebar.style.opacity=t?"":"0",t||setTimeout((()=>{this.sidebar.style.display="none",this.loaded()}),this.sidebarTransitionLength)}}var e;e=".ld-presenter-mode",document.querySelectorAll(e).forEach((i=>{new t(i,e).init()}))}();