MediaWiki:Common.js: Difference between revisions

From Hidden Mickey Wiki

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 35: Line 35:
/* Settings dropdown test */
/* Settings dropdown test */
$(function() {
$(function() {
    // Find the container that holds the right-side user dropdown
     var navbarRight = $('#mw-navbar-right');
     var userDropdown = $('#mw-navbar-right');


     if (userDropdown.length) {
     if (navbarRight.length) {
         // Create a new dropdown placeholder
         // Create a Settings dropdown placeholder
         var settingsDropdown = $(`
         var settingsDropdown = $(`
             <div class="dropdown" id="mw-navbar-settings" style="display:inline-block; margin-right:8px;">
             <div id="mw-navbar-settings" class="dropdown" style="display:inline-flex; align-items:center; margin-left:12px;">
                 <button class="mw-settings-btn">⚙ Settings ▼</button>
                 <button class="mw-settings-btn" style="padding:6px 12px;">⚙ Settings ▼</button>
             </div>
             </div>
         `);
         `);


         // Insert it immediately before the user dropdown
         // Append it as the last item (to the right of the user menu)
         userDropdown.before(settingsDropdown);
         navbarRight.append(settingsDropdown);
     } else {
     } else {
         console.log("User dropdown (#mw-navbar-right) not found");
         console.log("Navbar right container not found");
     }
     }
});
});

Revision as of 13:55, 15 September 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// JavaScript code to save checkbox state and restore it when the page loads
$(document).ready(function() {
    // Function to save the state of checkboxes to localStorage
    function saveCheckboxState() {
        $('input[type="checkbox"]').each(function() {
            localStorage.setItem($(this).attr('id'), $(this).prop('checked'));
        });
    }

    // Function to load the state of checkboxes from localStorage
    function loadCheckboxState() {
        $('input[type="checkbox"]').each(function() {
            const savedState = localStorage.getItem($(this).attr('id'));
            if (savedState !== null) {
                $(this).prop('checked', savedState === 'true');
            }
        });
    }

    // Load the saved checkbox state when the page is loaded
    loadCheckboxState();

    // Save the checkbox state whenever a checkbox is changed
    $('input[type="checkbox"]').change(function() {
        saveCheckboxState();
    });
});

// Adjust the search box width
$(document).ready(function () {
    $('#searchInput').css('width', '600px'); // Adjust width as needed
});

/* Settings dropdown test */
$(function() {
    var navbarRight = $('#mw-navbar-right');

    if (navbarRight.length) {
        // Create a Settings dropdown placeholder
        var settingsDropdown = $(`
            <div id="mw-navbar-settings" class="dropdown" style="display:inline-flex; align-items:center; margin-left:12px;">
                <button class="mw-settings-btn" style="padding:6px 12px;">⚙ Settings ▼</button>
            </div>
        `);

        // Append it as the last item (to the right of the user menu)
        navbarRight.append(settingsDropdown);
    } else {
        console.log("Navbar right container not found");
    }
});