Skip to content

Commit

Permalink
Allow middle-clicking the search button (resolves #1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Oct 5, 2024
1 parent 34e13d2 commit 38f8cf6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions TASVideos/wwwroot/js/site-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 38f8cf6

Please sign in to comment.