MediaWiki:Form.js

/* Any JavaScript here will be loaded for all users on every page load. */ /* @ By Princess Platinum @ Adds a pop up modal form for wlb.wikia.com @ License: CC-BY-NC-SA @ License Jurisdiction: International

//Array of language codes var langarray = ["EN", "CA", "BS", "DE", "ES", "FR", "IT", "JA", "MS", "NL", "PL"];

//The translation button text var buttontext = ["Create New Request", "U&#269;inite zahtjev", "Crear una nova sol · licitud", "Neue Anfrage Stellen", "Crear una nueva solicitud", "Créer une nouvelle requête", "Créer nouvelle demande", "No Button Translation", "Buat Permintaan New", "Maken Nieuw Aanvraag", "Utwórz nowe"];

//Variables for later on var $ = this.jQuery, mw = this.mediaWiki, lang, i,   template, button;

//Now for the others, we will keep them in an object for organization var wlb = { edittoken: mw.user.tokens.values.editToken, namespace: mw.config.get('wgNamespaceNumber'), pagename: mw.config.get('wgPageName'), server: mw.config.get('wgServer'), signature:  +  };

//Adds language classes to each tab $('.tabbernav').find('li').each(function (i) {   $(this).attr("id", langarray[i]); });

//gets the class of the currently clicked element $("ul.tabbernav").on('click', 'li', function (e) {   lang = $(this).attr("id");

//Switch function switch (window.lang) { case "EN": button = buttontext[0]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Items\'\'\': \n\n\'\'\'Extra information\'\'\': \n\n' + wlb.signature + '\n'; break; case "BS": console.log('null'); break; case "CA": button = buttontext[2]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Items\'\'\': \n\n\'\'\'Informació extra\'\'\': \n\n' + wlb.signature + '\n'; break; case "DE": button = buttontext[3]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Elemente\'\'\': \n\n\'\'\'Extrainformationen\'\'\': \n\n' + wlb.signature + '\n'; break; case "ES": button = buttontext[4]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Items\'\'\': \n\n\'\'\'Extra information\'\'\': \n\n' + wlb.signature + '\n'; break; case "FR": button = buttontext[5]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Items\'\'\': \n\n\'\'\'Information d\'extra\'\'\': ' + wlb.signature + '\n'; break; case "IT": console.log('null'); break; case "JA": button = buttontext[7]; template = '\n\n\'\'\'&#12454;&#12451;&#12461;\'\'\'&#65306; <&#12454;&#12451;&#12461;&#12398;URL&#12434;&#20837;&#21147;&#12375;&#12390;&#12367;&#12384;&#12373;&#12356;>\n\n\'\'\'&#38917;&#30446; \'\'\'&#65306; <&#32763;&#35379;&#12434;&#12362;&#39000;&#12356;&#12375;&#12383;&#12356;&#38917;&#30446; (3&#12388;&#12414;&#12391;)>\n\n\'\'\'&#12381;&#12398;&#20182;&#12398;&#24773;&#22577; \'\'\'&#65306; &#65308;&#12381;&#12398;&#20182;&#12398;&#24773;&#22577;&#12434;&#36861;&#21152;&#12375;&#12390;&#12367;&#12384;&#12373;&#12356;&#65288;&#20219;&#24847;&#65289;&#65310; \n\n' + wlb.signature + '\n'; break; case "MS": button = buttontext[8]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Sumber\'\'\': \n\n\'\'\'Maklumat tambahan\'\'\': <masukkan maklumat tambahan sini (tidak wajib diisi~)>\n\n' + wlb.signature + '\n'; break; case "NL": button = buttontext[9]; template = '\n\n\'\'\'Wiki\'\'\': <plaats hier de url van de wiki>\n\n\'\'\'Items\'\'\': <te vertalen pagina\'s (tot 3)>\n\n\'\'\'Extra informatie\'\'\': <andere informatie (optioneel)>\n\n' + wlb.signature + '\n'; break; case "PL": button = buttontext[10]; template = '\n\n\'\'\'Wiki\'\'\': \n\n\'\'\'Elementy\'\'\': <elementy do przet&#322;umaczenia (do 3)>\n\n\'\'\'Dodatkowe informacje\'\'\': <wpisz dodatkowe informacje (opcjonalnie)>\n\n' + wlb.signature + '\n'; break; default: console.log('null'); break; }       var buttonappend = '<a class="wikia-button" id="wlb-submit" onclick="openForm">' + button + '</a>'; document.getElementById("lang-" + lang).innerHTML = buttonappend; });

//This opens the form for the users to fill out

function openForm { $.showCustomModal("Request Form", '<form class="WikiaForm" method="" name=""> Title of the request: <input id="request-header" type="text" placeholder="Replace this with the title" style="width: 500px"/>  Information of your request. More information on how to file in your request can be found on top of the page. <textarea id="request-body" cols="80" rows="10">' + window.template + '   ', {        id: "requestWindow",        width: 650,        buttons: [{            id: "cancel",            message: "Cancel",            handler: function  {                cancelform;            }        }, {            id: "submit",            defaultButton: true,            message: "Submit",            handler: function  {                submitform;                setTimeout(cancelform, 1000);            }        }]    }); }

//Closes the form

function cancelform { $("#requestWindow").closeModal; }

//Submits the form

function submitform { var header = document.getElementById("request-header").value || 'null', body = document.getElementById("request-body").value, page = ' ' + body + ' ';

//Making sure the header isnt blank if (header === 'null') { alert("Please title your request!"); return; }

//Ajax URL var url = wlb.server + '/api.php?action=edit&title=' + encodeURIComponent(wlb.pagename) + '&section=new&sectiontitle=' + encodeURIComponent(header) + '&text=' + encodeURIComponent(page) + '&token=' + encodeURIComponent(wlb.edittoken);

$.post(url, function {        window.location.reload;    }); }

function start { $('div#EN').append('<a class="wikia-button" id="wlb-submit" onclick="openForm">Submit Request</a>'); }

addOnloadHook(start);