mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-26 02:27:14 +00:00
1 line
7.6 KiB
JavaScript
1 line
7.6 KiB
JavaScript
|
(()=>{"use strict";function t(e,n){return!(!e||!e.classList.contains(n))||!!e.parentElement&&t(e.parentElement,n)}document.addEventListener("DOMContentLoaded",(function(){document.querySelectorAll("div.button").forEach((function(t){t.addEventListener("keydown",(function(e){var n=e.key;"Enter"!==n&&" "!==n||t.dispatchEvent(new MouseEvent("click"))}))}))}));function e(){return window.innerWidth<440?"mobile":window.innerWidth>=440&&window.innerWidth<900?"tablet":"desktop"}var n=function(){function t(t){this.trapElement=t,this.handleKeyDown=this.handleKeyDown.bind(this),this.trapElement.addEventListener("keydown",this.handleKeyDown)}return t.prototype.handleKeyDown=function(t){var e=Array.from(this.trapElement.querySelectorAll('[role="option"]')).filter((function(t){return"none"!==t.style.display&&-1!==t.tabIndex}));if(["Tab","ArrowDown","ArrowUp"].includes(t.key)&&0!==e.length){var n=e[0],o=e[e.length-1];if("ArrowUp"===t.key)if(document.activeElement===n)o.focus();else{var r=e.indexOf(document.activeElement);e[r-1].focus()}"ArrowDown"===t.key&&(document.activeElement===o?n.focus():(r=e.indexOf(document.activeElement),e[r+1].focus())),"Tab"===t.key&&(t.shiftKey?document.activeElement===n&&(o.focus(),t.preventDefault()):document.activeElement===o&&(n.focus(),t.preventDefault()))}},t.prototype.destroy=function(){this.trapElement.removeEventListener("keydown",this.handleKeyDown)},t}(),o='[data-role="dropdown"]',r='[data-role="dropdown-toggle"]',i='[data-role="dropdown-listbox"]';function l(t){var e,n,o=t.querySelectorAll(r);null==o||o.forEach(a),e=t.querySelector(i),n=o[0].offsetWidth,e&&(e.classList.toggle("dropdown--list_expanded"),e.classList.contains("dropdown--list_expanded")?c(e,n):c(e,void 0))}function a(t){t.classList.contains("button_dropdown")&&t.classList.toggle("button_dropdown_active")}function c(t,e){if(e){var n=parseInt(getComputedStyle(t).minWidth,10),o=isNaN(n)?e:Math.max(n,e);t.style.minWidth="".concat(o,"px")}else t.style.minWidth=""}function d(e){var n=e.target;t(n,"dropdown")&&"dropdown--overlay"!==n.className||document.querySelectorAll(o).forEach((function(t){var e,n;null===(e=t.querySelectorAll(r))||void 0===e||e.forEach((function(t){t.classList.remove("button_dropdown_active")})),null===(n=t.querySelectorAll(i))||void 0===n||n.forEach((function(t){t.classList.remove("dropdown--list_expanded"),t.style.minWidth=""}))}))}function u(t){t.tag.removeAttribute("style"),t.option.setAttribute("style","display: none")}function s(t){t.tag.setAttribute("style","display: none"),t.option.removeAttribute("style")}function f(t){var e,n=null===(e=t.querySelector(".checkbox--input"))||void 0===e?void 0:e.getAttribute("data-filter");n&&(-1===filteringContext.activeFilters.findIndex((function(t){return t===n}))?unfilterSourceset(n):filterSourceset(n)),refreshFiltering()}document.addEventListener("DOMContentLoaded",(function(){document.querySelectorAll(o).forEach((function(t){var e;null===(e=t.querySelectorAll(r))||void 0===e||e.forEach((function(e){e.addEventListener("click",(function(){return l(t)}))})),function(t){new n(t),t.addEventListener("keydown",(function(e){var n;"Escape"===e.key&&(l(t),null===(n=t.querySelector(r))||void 0===n||n.focus())}))}(t)})),document.addEventListener("click",d)})),document.addEventListener("DOMContentLoaded",(function(){var t=document.getElementById("navigation-wrapper"),n=document.getElementById("library-version"),o=document.getElementById("filter-section"),r=document.querySelector("#filter-section + .navigation-controls--btn"),i=document.getElementById("filter-section-dropdown");if(t&&n&&o&&r&&i){var l=null==o?void 0:o.querySelectorAll(".dropdown--option"),a=null==o?void 0:o.querySelectorAll(".platform-selector");if(a&&l)if(a.length===l.length){var c=Array.from({length:a.length}).map((function(t,e){return{tag:a[e],option:l[e]}})),d=c.map((function(t){return t.tag.getBoundingClientRect().width})),v=e(),m=new ResizeObserver((function(){var n=e();v!==n&&(c.forEach(u),d=function(t){return t.map((function(t){return t.tag.getBoundingClientRect().width}))}(c)),v=n,y(),m.unobserve(t)})),g=functi
|