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/script.min.js

1 line
6.7 KiB
JavaScript
Raw Normal View History

2023-09-08 01:45:46 -07:00
var pressbook=pressbook||{};function pressbookDomReady(e){if("function"==typeof e)return"interactive"===document.readyState||"complete"===document.readyState?e():void document.addEventListener("DOMContentLoaded",e,!1)}Math.easeInOutQuad=function(e,t,n,a){return(e/=a/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t},pressbook.setupMainMenu={init:function(){var e,t,n,a,o,i,s,r=document.getElementById("site-navigation");r&&(t=r.getElementsByTagName("ul")[0],e=r.querySelector(".primary-menu-toggle"),void 0===t?e&&(e.style.display="none"):(t.classList.add("nav-menu"),t=r.querySelectorAll(".main-navigation-arrow-btn"),n=r.querySelectorAll("li > a"),a=r.querySelectorAll("li:not(.menu-item-has-children) > a"),o=r.querySelectorAll("li:last-child:not(.menu-item-has-children) > a"),i=r.querySelector(".primary-menu-search"),s=r.querySelector(".primary-menu-search-toggle"),this.toggleTouchClass(r),this.toggleNavigation(e,r),this.collapseIfClickOutside(e,r),this.collapseIfEscapeKeyPress(e,r),this.collapseOnResize(e,r),this.toggleSubmenu(t,n,a,o),this.trapFocusInModal(r),this.toggleSearch(s,i),this.trapFocusInSearch(i)))},toggleTouchClass:function(e){const t="main-navigation--touch";function n(){return"ontouchstart"in window||0<navigator.maxTouchPoints||0<navigator.msMaxTouchPoints}n()&&e.classList.add(t),window.addEventListener("resize",function(){n()?e.classList.add(t):e.classList.remove(t)})},toggleNavigation:function(t,n){t&&t.addEventListener("click",function(e){e.preventDefault(),n.classList.toggle("toggled"),t&&("true"===t.getAttribute("aria-expanded")?t.setAttribute("aria-expanded","false"):t.setAttribute("aria-expanded","true"))})},collapseIfClickOutside:function(t,n){const a=this;document.addEventListener("click",function(e){n.contains(e.target)||(n.classList.remove("toggled"),t&&t.setAttribute("aria-expanded","false"),[].forEach.call(n.querySelectorAll(".focus"),function(e){e.classList.remove("focus")}),[].forEach.call(n.querySelectorAll(".main-navigation-arrow-btn"),function(e){e.setAttribute("aria-expanded","false")}),a.collapseSearchForm(n))})},collapseIfEscapeKeyPress:function(t,n){const a=this;document.addEventListener("keyup",function(e){"Escape"===e.key&&(n.classList.remove("toggled"),t&&t.setAttribute("aria-expanded","false"),a.collapseSearchForm(n))})},collapseOnResize:function(e,t){window.addEventListener("resize",function(){window.matchMedia("screen and (min-width: 768px)").matches&&(t.classList.remove("toggled"),e)&&e.setAttribute("aria-expanded","false")})},toggleSubmenu:function(e,t,n,a){function o(){for(var e=this,t=!1;"ul"!==e.tagName.toLowerCase();)"li"!==e.tagName.toLowerCase()||t||e.classList.contains("focus")||(t=e),e=e.parentElement;[].forEach.call(e.querySelectorAll(".focus"),function(e){e.classList.remove("focus")}),[].forEach.call(e.querySelectorAll(".main-navigation-arrow-btn"),function(e){e.setAttribute("aria-expanded","false")}),t&&(t.classList.add("focus"),this.setAttribute("aria-expanded","true"))}function i(e){var t=this.parentElement,n="Tab"===e.key,e=e.shiftKey;n&&e&&t.classList.contains("focus")?(t.classList.remove("focus"),this.setAttribute("aria-expanded","false")):!n||e||t.classList.contains("focus")||(t.classList.add("focus"),this.setAttribute("aria-expanded","true"))}function s(){for(var e=this,t=!1;!e.classList.contains("nav-menu");)t||"ul"!==e.tagName.toLowerCase()||([].forEach.call(e.querySelectorAll(".focus"),function(e){e.classList.remove("focus")}),[].forEach.call(e.querySelectorAll(".main-navigation-arrow-btn"),function(e){e.setAttribute("aria-expanded","false")}),t=!0),e=e.parentElement}function r(){for(var e=this;!e.classList.contains("nav-menu");)"li"===e.tagName.toLowerCase()&&!e.classList.contains("focus")&&(e.classList.add("focus"),e.querySelector(".main-navigation-arrow-btn"))&&this.setAttribute("aria-expanded","true"),e=e.parentElement}function c(e){var t,n=this,a="Tab"===e.key,e=e.shiftKey;if(a&&!e){for(;t=function(e){for(;(e=e.nextSibling)&&1!==e.nodeType;);return e}(n),n=n.parentElement,!t;);[].forEach.call(n.querySelectorAll(".focus"),function(e){e.classList.remove("focus")}),[].f