From 38f8cf6f075b11c9509c4bc562f6be8441a59503 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 5 Oct 2024 22:56:12 +1000 Subject: [PATCH] Allow middle-clicking the search button (resolves #1878) --- TASVideos/wwwroot/js/site-head.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/TASVideos/wwwroot/js/site-head.js b/TASVideos/wwwroot/js/site-head.js index 7e3dc7af1..b977d1b76 100644 --- a/TASVideos/wwwroot/js/site-head.js +++ b/TASVideos/wwwroot/js/site-head.js @@ -64,6 +64,22 @@ window.addEventListener("DOMContentLoaded", function () { rate(btn.dataset.pubId, true); }; }); + + // allow middle-clicking the search button to open in new tab + const searchBtnElem = document.querySelector(/*ul.navbar-nav */'form[action="/Search/Index"] button[type="submit"]'); + // is there a function for this? reverse Element.querySelector? + let searchFormElem = searchBtnElem.parentElement; + while (!(searchFormElem instanceof HTMLFormElement)) searchFormElem = searchFormElem.parentElement; + const linkElem = document.createElement("a"); + Array.from(searchBtnElem.attributes).forEach(attr => linkElem.setAttribute(attr.name, attr.value)); + linkElem.onclick = e => { + e.preventDefault(); + searchFormElem.requestSubmit(); + }; + linkElem.removeAttribute("type"); + linkElem.setAttribute("href", "/Search/Index"); + Array.from(searchBtnElem.children).forEach(e => linkElem.appendChild(e)); + searchBtnElem.replaceWith(linkElem); }); function rate(pubId, unrated) {