MediaWiki:Common.js

From Waltharius
Revision as of 16:54, 24 July 2026 by HGL (talk | contribs)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
document.addEventListener('click', function (event) {
    var icon = event.target.closest(
        '.meter, .parallel, .commentary, .pictures, .outline, .comment, .word'
    );

    if (!icon) {
        return;
    }

    var textPanel = icon.querySelector(
        '.metertext, .paralleltext, .commentarytext, ' +
        '.picturestext, .outlinetext, .commenttext, .wordtext'
    );

    if (textPanel && textPanel.contains(event.target)) {
        return;
    }

    var isOpening = !icon.classList.contains('open');

    document.querySelectorAll(
        '.meter.open, .parallel.open, .commentary.open, ' +
        '.pictures.open, .outline.open, .comment.open, .word.open'
    ).forEach(function (openIcon) {
        if (openIcon !== icon) {
            openIcon.classList.remove('open');
        }
    });

    icon.classList.toggle('open');

    if (isOpening) {
        var iconPosition = icon.getBoundingClientRect();
        var rightMargin = 16;
        var availableWidth =
            document.documentElement.clientWidth -
            iconPosition.left -
            rightMargin;

        var preferredWidth =
            document.documentElement.clientWidth * 0.7;

        var popupWidth = Math.min(preferredWidth, availableWidth);

        icon.style.setProperty(
            '--popup-width',
            Math.max(popupWidth, 0) + 'px'
        );
    }
});