MediaWiki:Gadget-CustomButtons.js
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.
$(document).ready(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 */
// Function to switch all tabs to the first tab (Magazine)
function showFirstTabs() {
$('.volDiffBox .tabber').each(function() {
var firstTab = $(this).find('.tabber__tab').first();
var tabContentId = firstTab.attr('aria-controls');
// Set the first tab as selected and active
firstTab.attr('aria-selected', 'true').addClass('tabber__tab--active');
$('#' + tabContentId).attr('aria-hidden', 'false').addClass('tabber__panel--active');
// Hide other tabs and their content
$(this).find('.tabber__tab').not(firstTab).attr('aria-selected', 'false').removeClass('tabber__tab--active');
$('#' + tabContentId).siblings('.tabber__panel').attr('aria-hidden', 'true').removeClass('tabber__panel--active');
});
}
// Function to switch all tabs to the second tab (Volume)
function showSecondTabs() {
$('.volDiffBox .tabber').each(function() {
var secondTab = $(this).find('.tabber__tab').eq(1);
var tabContentId = secondTab.attr('aria-controls');
// Set the second tab as selected and active
secondTab.attr('aria-selected', 'true').addClass('tabber__tab--active');
$('#' + tabContentId).attr('aria-hidden', 'false').addClass('tabber__panel--active');
// Hide other tabs and their content
$(this).find('.tabber__tab').not(secondTab).attr('aria-selected', 'false').removeClass('tabber__tab--active');
$('#' + tabContentId).siblings('.tabber__panel').attr('aria-hidden', 'true').removeClass('tabber__panel--active');
});
}
// Event listener for "Show Volume Pages" button
$('.volDiffBtn2').click(function() {
showSecondTabs();
});
// Event listener for "Show Magazine Pages" button
$('.volDiffBtn1').click(function() {
showFirstTabs();
});
});