Files
ipam/static/js/subnet.min.js
T
2025-12-27 02:08:52 +00:00

14 lines
2.7 KiB
JavaScript

document.addEventListener("DOMContentLoaded",()=>{let e=document.querySelectorAll("form"),t=null;for(let o of e)if("/search"!==o.action&&"POST"===o.method){t=o;break}if(t&&!document.querySelector('input[placeholder="Search by IP or Hostname"]')){t.addEventListener("submit",e=>{e.preventDefault()});let l=document.createElement("input");l.type="text",l.placeholder="Search by IP or Hostname",l.className="p-2 w-full rounded-lg bg-gray-200 dark:bg-zinc-800 border border-gray-600 focus:outline-none focus:border-blue-400 mb-4 text-center",t.insertAdjacentElement("beforebegin",l),l.addEventListener("keypress",e=>{if("Enter"===e.key){e.preventDefault();let t=l.value.toLowerCase(),o=document.querySelectorAll("tbody tr");o.forEach(e=>{let o=e.querySelector("td:nth-child(1)").textContent.toLowerCase(),l=e.querySelector("td:nth-child(2)").textContent.toLowerCase();o.includes(t)||l.includes(t)?(e.style.backgroundColor="rgba(59, 130, 246, 0.5)",e.scrollIntoView({behavior:"smooth",block:"center"}),setTimeout(()=>{e.style.backgroundColor=""},3e3)):e.style.backgroundColor=""})}})}let r=document.getElementById("toggle-desc"),n=document.querySelectorAll(".desc-col"),s=document.getElementById("desc-col-header"),a=!1;r&&r.addEventListener("click",function(){a=!a,n.forEach(e=>e.classList.toggle("hidden",!a)),s&&s.classList.toggle("hidden",!a),r.textContent=a?"Hide Descriptions":"Show Descriptions"});let d=document.createElement("button");d.innerHTML='<i class="fas fa-arrow-up"></i>',d.style.fontSize="26px",d.className="fixed bottom-5 right-5 bg-gray-200 dark:bg-zinc-800 text-black dark:text-white p-3 rounded-full shadow-lg hidden",d.style.width="60px",d.style.height="60px",d.style.borderRadius="50%",document.body.appendChild(d);let c=document.createElement("style");if(c.textContent=`
@keyframes bob {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-5px);
}
}
.bobbing {
animation: bob 1.5s infinite;
}
`,document.head.appendChild(c),d.classList.add("bobbing"),window.addEventListener("scroll",()=>{window.scrollY>200?d.classList.remove("hidden"):d.classList.add("hidden")}),d.addEventListener("click",()=>{window.scrollTo({top:0,behavior:"smooth"})}),requestAnimationFrame(()=>{let e=document.documentElement.scrollHeight>document.documentElement.clientHeight;e&&0===window.scrollY&&(window.scrollBy(0,1),requestAnimationFrame(()=>{window.scrollBy(0,-1)}))}),window.location.hash){let i=window.location.hash.substring(1),b=document.getElementById(i);b&&setTimeout(()=>{b.scrollIntoView({behavior:"smooth",block:"center"}),b.style.backgroundColor="rgba(59, 130, 246, 0.5)",setTimeout(()=>{b.style.backgroundColor=""},3e3)},100)}});