MediaWiki:Gadget-CustomButtons.js

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 07:42, 26 July 2024 by Vish (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, 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: Press Ctrl-F5.
$(function() {
	/* Quote Template Buttons */
    $('.quote-buttons').each(function() {
        var $quoteBox = $(this).closest('.quoteBox');

        $(this).find('#showAllButton').click(function() {
            $quoteBox.find('.nihongo-english').css('display', 'inline');
            $quoteBox.find('.nihongo-japanese').css('display', 'inline');
            $quoteBox.find('.nihongo-bracket').css('display', 'inline');
            $quoteBox.find('.nihongo-romaji').remove(); // Remove any appended romaji spans
        });

        $(this).find('#showEnglishButton').click(function() {
            $quoteBox.find('.nihongo-english').css('display', 'inline');
            $quoteBox.find('.nihongo-japanese').css('display', 'none');
            $quoteBox.find('.nihongo-romaji').css('display', 'none');
            $quoteBox.find('.nihongo-bracket').css('display', 'none');
        });

        $(this).find('#showJapaneseButton').click(function() {
            $quoteBox.find('.nihongo-english').css('display', 'none');
            $quoteBox.find('.nihongo-japanese').css('display', 'inline');
            $quoteBox.find('.nihongo-romaji').css('display', 'none');
            $quoteBox.find('.nihongo-bracket').css('display', 'none');
        });

        $(this).find('#showRomajiButton').click(function() {
            $quoteBox.find('.nihongo-english').css('display', 'none');
            $quoteBox.find('.nihongo-bracket').css('display', 'none');

            $quoteBox.find('.nihongo-japanese').each(function() {
                var $japaneseElement = $(this);
                var romaji = $japaneseElement.data('content');

                if (romaji) {
                    if ($japaneseElement.next('.nihongo-romaji').length === 0) {
                        $japaneseElement.after('<span class="nihongo-romaji" style="display:inline; font-family:Meiryo">' + romaji + '</span>');
                    } else {
                        $japaneseElement.next('.nihongo-romaji').css('display', 'inline');
                    }
                    $japaneseElement.css('display', 'none');
                } else {
                    $japaneseElement.closest('.popup-wrapper').find('.nihongo-english').css('display', 'inline');
                    $japaneseElement.css('display', 'none');
                }
            });

            $quoteBox.find('.popup-box').css('display', 'none');
        });
    });
    
    /* DiffBox Template Buttons */
    $('.volDiffBtn1').click(function() {
        $('.volDiffImages .tabber').each(function() {
            var $sections = $(this).find('.tabber__section');
            if ($sections.length > 0) {
                $sections.eq(0).attr('aria-hidden', 'false'); // First tab
            }
            if ($sections.length > 1) {
                $sections.eq(1).attr('aria-hidden', 'true'); // Second tab
            }
        });
    });
    
    $('.volDiffBtn2').click(function() {
        $('.volDiffImages .tabber').each(function() {
            var $sections = $(this).find('.tabber__section');
            if ($sections.length > 0) {
                $sections.eq(0).attr('aria-hidden', 'true'); // First tab
            }
            if ($sections.length > 1) {
                $sections.eq(1).attr('aria-hidden', 'false'); // Second tab
            }
        });
    });
});