forked from binary-com/deriv-developers-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderiv.min.js
1 lines (1 loc) · 4.37 KB
/
deriv.min.js
1
function openMobileDropdown(){const e=document.getElementById("doc-menu-header").nextElementSibling;e.classList.add("show-dropdown")}function handleHamburgerClick(){const e=document.getElementById("canvas-menu");e&&(e.classList.toggle("show-canvas"),e.classList.contains("show-canvas")?(document.addEventListener("click",handleOutsideCanvasClick),this.src="/img/close.svg"):(document.removeEventListener("click",handleOutsideCanvasClick),this.src="/img/hamburger_menu.svg"))}function handleOutsideCanvasClick(e){const t=document.getElementById("canvas-menu"),n=document.getElementById("main-nav");t.contains(e.target)||n.contains(e.target)||(t.classList.remove("show-canvas"),document.getElementById("hamburger").src="/img/hamburger_menu.svg",document.removeEventListener("click",handleOutsideCanvasClick))}function handleDropdownClick(e){const t=document.getElementById("doc-menu-header").nextElementSibling;t.classList.toggle("show-dropdown")}function setCopyButton(){const e=document.getElementsByClassName("copy-button");if(e)for(let t=0;t<e.length;t++)e[t].removeEventListener("click",handleDropdownClick),e[t].addEventListener("click",handleCodeCopyClick)}function handleCodeCopyClick(){let e,t=this.parentNode;if(!t)return;if("card-light"===t.className)e=t.children[0].textContent.trim();else if(t=t.nextElementSibling,14===t.children.length){t=t.children;let n=document.getElementById("demo-language").value;for(let l=0;l<t.length;l++)t[l].attributes[0].value===n&&(e=t[l].textContent)}else e=t.textContent;let n=document.createElement("textarea");document.body.appendChild(n),n.value=e,n.select(),document.execCommand("copy"),document.body.removeChild(n)}window.onload=function(){setSideBarActive(),setNavbarActive(),setMobileNavbarActive(),setAccordionActive(),handleMobileNav(),handleMobileNavDropdown(),setCopyButton()},window.onhashchange=(e=>{setSideBarPlaygroundActive()});const setAccordionActive=()=>{let e=document.getElementsByClassName("accordion-header");if(e)for(let t=0;t<e.length;t++)e[t].addEventListener("click",function(){this.classList.toggle("active");let e=this.children[1];this.classList.contains("active")?(e.src="/img/minus.svg",e.style.transform="rotate(90deg)"):(e.src="/img/plus.svg",e.style.transform="rotate(0deg)");let t=this.nextElementSibling;t.style.display="block"===t.style.display?"none":"block"})},setNavbarActive=()=>{let e=document.getElementById("navbar");if(!e)return;let t=window.location.pathname.split("/")[1].replaceAll("/","");for(let n=0;n<e.children.length;n++){if(""===t){e.children[0].classList.add("selected");break}if(e.children[n].id===t){e.children[n].classList.add("selected");break}}},setMobileNavbarActive=()=>{const e=document.getElementById("canvas-menu");if(!e)return;let t,n=window.location.pathname.split("/")[1].replaceAll("/","");if("docs"===n){openMobileDropdown();let e=window.location.pathname.split("/")[2].replaceAll("/","");t=e||"quickstart"}else t="playground"===n?"playground_link":"home";const l=document.getElementById(t);l.classList.add("selected")},setSideBarActive=()=>{let e=document.getElementById("sidebar");if(!e)return;let t=window.location.pathname.replace("docs","").replaceAll("/","");for(let n=0;n<e.children.length;n++){if(""===t){e.children[1].classList.add("selected");break}if(e.children[n].id===t){let t=e.children[n];t.classList.add("selected");break}}},setSideBarPlaygroundActive=()=>{let e=document.getElementById("playground-sidebar");if(!e)return;for(let t=0;t<e.children.length;t++){let n=e.children[t];n.classList.remove("selected")}let t=window.location.hash.substr(1);for(let n=0;n<e.children.length;n++)if(e.children[n].getAttribute("value")===t){let t=e.children[n];t.classList.add("selected");break}},addPlaygroundLinkEventHandler=()=>{let e=document.getElementById("playground-sidebar");if(e)for(let t=1;t<e.children.length;t++){let n=e.children[t];n.removeEventListener("click",e=>updateSelect(e)),n.addEventListener("click",e=>updateSelect(e))}},updateSelect=e=>{$("#api-call-selector").val(e.srcElement.getAttribute("value")),$("#api-call-selector").trigger("change"),setSideBarPlaygroundActive()},handleMobileNav=()=>{const e=document.getElementById("hamburger");e&&(e.removeEventListener("click",handleHamburgerClick),e.addEventListener("click",handleHamburgerClick))},handleMobileNavDropdown=()=>{let e=document.getElementById("doc-menu-header");e&&(e.removeEventListener("click",handleDropdownClick),e.addEventListener("click",handleDropdownClick))};