MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* ============================= Selector =============================== */ /* Description: Improves the display functionality of content. Note: Used for Template:Selector. Author: KhangND */ var max = 30; // max number of fields var containers = $('.sel-container'); var fields = $('.fields');

for (indx = 0; indx < containers.length; indx++) { var cur = indx + 1; var selector = '#select' + cur; $(fields[indx]).attr('id', 'select' + cur);

//Prepare options var options = ""; for (i = 1; i <= max; i++) { text = $(selector + ' #option' + i).text; if (text !== '') { options += "" + text + " "; $(selector + ' #option' + i).css('display', 'none'); }   }

//Append to container $(containers[indx]).append("" + options + " "); }

//Onchange handler function change(indx) { var selector = '#select' + indx; var option = $('#selector' + indx).val; for (i = 1; i <= max; i++) { if (i != option) $(selector + ' #changefield' + i).css('display', 'none'); else $(selector + ' #changefield' + i).css('display', 'block'); } }

/* ======================= Gallery spoiler alert ======================== */ /* Description: Display or hide the gallery that contains spoiler. Note: Used for Template:Spoiler/Gallery Author: KhangND */ var _alert = ".spoiler-alert"; $(_alert).next("div").hide;

$(_alert + " span").click(function {   $(this).attr('id') === "y" ?        $(this).parents(_alert).next("div").fadeIn :        $(this).parents(_alert).next("div").hide;    $(this).parents(_alert).hide; });

/* ====================================================================== */ /* Add a custom button to the edit toolbar */ if (mwCustomEditButtons) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "https://vignette.wikia.nocookie.net/fireemblem/images/c/c8/Button_redirect.png/revision/latest?cb=20090312204241", "speedTip": "Redirect", "tagOpen": "", "tagClose": "", "sampleText": "#REDIRECT " }; }