MediaWiki:Common.js: Difference between revisions

From tol2kit for kwan lab
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function() {
    // Check if search box exists in the sidebar already
 
    if (!document.querySelector("#p-search")) {
 
        var sidebar = document.querySelector("#mw-panel"); // Find the sidebar
// Force all PDF links to open in a new tab
        if (sidebar) {
$(document).ready(function() {
            var searchBox = document.createElement("div");
    $('a[href$=".pdf"]').attr('target', '_blank');
            searchBox.id = "p-search";
            searchBox.innerHTML = `
                <form action="/index.php" method="get">
                    <input type="hidden" name="title" value="Special:Search">
                    <input type="search" name="search" placeholder="Search..." required>
                </form>
            `;
            sidebar.insertBefore(searchBox, sidebar.firstChild); // Add search box to the top of the sidebar
        }
    }
});
});

Latest revision as of 18:26, 30 May 2025

document.addEventListener("DOMContentLoaded", function() {


// Force all PDF links to open in a new tab
$(document).ready(function() {
    $('a[href$=".pdf"]').attr('target', '_blank');
});