graphdb-workbench
Version:
The web application for GraphDB APIs
1 lines • 1.34 kB
JavaScript
const INTERACTIVE_ELEMENTS_SELECTOR='button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])';class HtmlUtil{static setDocumentBodyOverflow(t){const e=document.body.style.overflow;return document.body.style.overflow=t,e}static hideDocumentBodyOverflow(){return HtmlUtil.setDocumentBodyOverflow("hidden")}static focusNextElement(t,e=INTERACTIVE_ELEMENTS_SELECTOR){const o=Array.from(t.querySelectorAll(e));if(o.length>0){const t=o.indexOf(document.activeElement),e=o[(t+1)%o.length];e&&e.focus()}}static focusPreviousElement(t,e=INTERACTIVE_ELEMENTS_SELECTOR){const o=Array.from(t.querySelectorAll(e));if(o.length>0){const t=o.indexOf(document.activeElement),e=o[(t-1+o.length)%o.length];e&&e.focus()}}static preventLeavingDialog(t,e){"Tab"===e.key&&(e.preventDefault(),e.shiftKey?HtmlUtil.focusPreviousElement(t):HtmlUtil.focusNextElement(t))}static focusElement(t){const e=document.querySelector(t);null==e||e.focus()}static scrollElementIntoView(t,e={block:"nearest"}){const o=document.querySelector(t);o&&o.scrollIntoView(e)}static waitForElement(t){return new Promise((e,o)=>{const n=new MutationObserver(()=>{try{const o=document.querySelector(t);o&&(n.disconnect(),e(o))}catch(t){n.disconnect(),o(t)}});n.observe(document.body,{subtree:!0,childList:!0,attributes:!0})})}}export{HtmlUtil as H};