MediaWiki:Common.js: Difference between revisions

From Hidden Mickey Wiki

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 32: Line 32:
     $('#searchInput').css('width', '600px'); // Adjust width as needed
     $('#searchInput').css('width', '600px'); // Adjust width as needed
});
});
/* MediaWiki:Common.js */


(function () {
// Debug check — make sure the file runs
  var box = document.createElement('div');
console.log("✅ Common.js is running!");
  box.id = 'mw-test-settings';
  box.style.position = 'absolute';
  box.style.top = '10px';
  box.style.right = '10px';
  box.style.background = 'white';
  box.style.border = '1px solid #ccc';
  box.style.padding = '4px';
  box.style.zIndex = 9999;


  var btn = document.createElement('button');
// Wait for the page to be ready
  btn.textContent = 'Settings ▾';
$(document).ready(function () {
    // Avoid adding it multiple times
    if ($("#settings-menu").length) return;


  var list = document.createElement('ul');
    // Create a minimal dropdown
  list.style.listStyle = 'none';
    var menuHtml = `
  list.style.margin = '4px 0 0 0';
        <div id="settings-menu" style="position:relative; display:inline-block; margin-left:15px;">
  list.style.padding = '0';
          <button id="settings-button" style="padding:6px 12px; cursor:pointer;">
  list.style.display = 'none';
            Settings ▼
          </button>
          <div id="settings-dropdown" style="
                display:none;
                position:absolute;
                background:#fff;
                border:1px solid #ccc;
                min-width:150px;
                z-index:9999;
              ">
            <a href="/wiki/Special:Preferences" style="display:block; padding:8px;">Preferences</a>
            <a href="/wiki/Special:UserLogout" style="display:block; padding:8px;">Log out</a>
          </div>
        </div>
    `;


  ['Preferences', 'Watchlist'].forEach(function (txt) {
    // Append to personal tools (usually top-right)
     var li = document.createElement('li');
     $("#p-personal ul").first().append(
    var a = document.createElement('a');
        $("<li>").append(menuHtml)
    a.textContent = txt;
     );
    a.href = '/wiki/Special:' + txt;
    a.style.display = 'block';
    a.style.padding = '4px 8px';
    a.style.textDecoration = 'none';
    a.style.color = 'black';
    li.appendChild(a);
     list.appendChild(li);
  });


  btn.onclick = function () {
    // Toggle dropdown visibility
    list.style.display = (list.style.display === 'none') ? 'block' : 'none';
    $(document).on("click", "#settings-button", function () {
  };
        $("#settings-dropdown").toggle();
    });


  box.appendChild(btn);
    // Close dropdown when clicking elsewhere
  box.appendChild(list);
    $(document).on("click", function (e) {
  document.body.appendChild(box);
        if (!$(e.target).closest("#settings-menu").length) {
})();
            $("#settings-dropdown").hide();
        }
    });
});

Revision as of 15:27, 18 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
});
/* MediaWiki:Common.js */

// Debug check — make sure the file runs
console.log("✅ Common.js is running!");

// Wait for the page to be ready
$(document).ready(function () {
    // Avoid adding it multiple times
    if ($("#settings-menu").length) return;

    // Create a minimal dropdown
    var menuHtml = `
        <div id="settings-menu" style="position:relative; display:inline-block; margin-left:15px;">
          <button id="settings-button" style="padding:6px 12px; cursor:pointer;">
            Settings ▼
          </button>
          <div id="settings-dropdown" style="
                display:none;
                position:absolute;
                background:#fff;
                border:1px solid #ccc;
                min-width:150px;
                z-index:9999;
              ">
            <a href="/wiki/Special:Preferences" style="display:block; padding:8px;">Preferences</a>
            <a href="/wiki/Special:UserLogout" style="display:block; padding:8px;">Log out</a>
          </div>
        </div>
    `;

    // Append to personal tools (usually top-right)
    $("#p-personal ul").first().append(
        $("<li>").append(menuHtml)
    );

    // Toggle dropdown visibility
    $(document).on("click", "#settings-button", function () {
        $("#settings-dropdown").toggle();
    });

    // Close dropdown when clicking elsewhere
    $(document).on("click", function (e) {
        if (!$(e.target).closest("#settings-menu").length) {
            $("#settings-dropdown").hide();
        }
    });
});