MediaWiki:Common.js: verschil tussen versies
Uit Dorpsbelang Den Hout
Regel 73: | Regel 73: | ||
mw.loader.using( ['ws.wsform.select2'] ).then( function () { | mw.loader.using( ['ws.wsform.select2'] ).then( function () { | ||
// This code is executed after the above modules are loaded. | // This code is executed after the above modules are loaded. | ||
− | + | // setSelect2(); | |
} ); | } ); | ||
Versie van 16 sep 2020 19:28
// JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers <script> function removeFile(el, file){ var message = confirm("Weet je zeker dat je dit bestand wilt verwijderen?") if(message == true){ var params = { action: 'delete', title: file, format: 'json' }, api = new mw.Api(); api.postWithToken( 'csrf', params ).done( function ( data ) { console.log( data ); el.closest('.upload-group').remove(); } ); } } function postBericht(el, template, mode){ var titel = ""; var domein = ""; var parameters = ""; var multiparameters = {}; var inputs = el.closest('form').querySelectorAll('textarea, input:not([name="mwreturn"] ):not([name="mwdb"] ):not([name="mwtoken"] ):not([type="file"]):not([name="mwaction"]):not([name="exclude"])'), i; for(i = 0; i < inputs.length; ++i){ if(inputs[i].name == "Titel"){titel = inputs[i].value}; if(inputs[i].name == "Domein"){domein = inputs[i].value}; if(inputs[i].type == "radio"){ if(inputs[i].checked){ parameters += '|'+inputs[i].name+'='+inputs[i].value; } }else{ if(inputs[i].name.includes("[]")){ if(!multiparameters[inputs[i].name.replace('[]', '')]){ multiparameters[inputs[i].name.replace('[]', '')] = []; } multiparameters[inputs[i].name.replace('[]', '')].push(inputs[i].value); }else{ parameters += '|'+inputs[i].name+'='+inputs[i].value; } } } if(mode == "domein"){ var url = domein.replace('.','-'); }else{ var url = domein.replace('.','-')+'/'+titel.replace(' ', '-'); } var multi = ""; for(i = 0; i < Object.keys(multiparameters).length; ++i){ multi += '|'+Object.keys(multiparameters)[i]+'='+multiparameters[Object.keys(multiparameters)[i]].toString(); } var wikitext = '{{'+template+parameters+multi+'}}' console.log(wikitext) var params = { action: 'edit', title: url, text: wikitext, format: 'json' }, api = new mw.Api(); api.postWithToken( 'csrf', params ).done( function ( html ) { window.location.href = window.location.origin+'/index.php/'+url; }) } mw.loader.using( ['ws.wsform.select2'] ).then( function () { // This code is executed after the above modules are loaded. // setSelect2(); } ); window.setSelect2 = function() { // Select2 if ($('select[data-inputtype="ws-select2"]')[0]) { mw.loader.using('ws.wsform.select2').then(function(script, textStatus) { $('select[data-inputtype="ws-select2"]').each(function() { var selectid = $(this).attr('id'); var selectoptionsid = 'select2options-' + selectid; var select2config = $("input#" + selectoptionsid).val(); var F = new Function(select2config); return (F()); }); }); } }; //js for file uplaod