MediaWiki:Common.js: verschil tussen versies
Uit Dorpsbelang Den Hout
Regel 1: | Regel 1: | ||
// JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers <script> | // JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers <script> | ||
+ | var offset=0; | ||
+ | function loadMoreBerichten(set){ | ||
+ | offset += set; | ||
+ | |||
+ | |||
+ | var wikitext = `{{#ask:[[Class::Bericht]][[Domein::{{SERVERNAME}}]]|?Datum|?Titel|?Bericht|?Image|link=none|limit=`+offset+`|format=complexarray|name=@berichten}}<!-- | ||
+ | -->{{#camap:@berichten|@@@| | ||
+ | <div class="col-md-6"> | ||
+ | <div class="card"><!-- | ||
+ | -->{{#tag:html|<div class="card-top" style="background-image:url('{{#if:@@@[Image]|{{filepath:{{#replace:@@@[Image]|Bestand:|}}}}|https://cdn.mos.cms.futurecdn.net/VSy6kJDNq2pSXsCzb6cvYF-1024-80.jpg.webp}}')"> | ||
+ | </div>}}<!-- | ||
+ | --><div class="card-bottom"> | ||
+ | <div><small><b>{{#if:@@@[Datum]|{{#time:d M Y|@@@[Datum]|nl}} }}</b></small></div> | ||
+ | <h2>@@@[Titel]</h2> | ||
+ | <div class="text-read-more">{{#regex:@@@[Bericht]|/<[^>]*>/|<nowiki/> <nowiki/>}} <i> {{#widget:link|type=a|href=@@@[cafullurl]|text=Lees meer|class=red}}</i></div> | ||
+ | </div> | ||
+ | </div> | ||
+ | </div> | ||
+ | |}}` | ||
+ | |||
+ | var params = { | ||
+ | action: 'parse', | ||
+ | text: wikitext, | ||
+ | contentmodel: 'wikitext', | ||
+ | format: 'json' | ||
+ | }, | ||
+ | api = new mw.Api(); | ||
+ | api.post( params ).done( function ( data ) { | ||
+ | console.log(data.parse.text['*']) | ||
+ | var newrow = document.createElement('div'); | ||
+ | newrow.classList.add('row') | ||
+ | newrow.insertBefore(document.querySelector('.fa-plus').closest('.col-md-6')) | ||
+ | entry.target.innerHTML = data.parse.text['*']; | ||
+ | |||
+ | )} | ||
+ | |||
+ | } | ||
+ | |||
function removeFile(el, file){ | function removeFile(el, file){ | ||
Versie van 19 aug 2020 21:52
// JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers <script> var offset=0; function loadMoreBerichten(set){ offset += set; var wikitext = `{{#ask:[[Class::Bericht]][[Domein::{{SERVERNAME}}]]|?Datum|?Titel|?Bericht|?Image|link=none|limit=`+offset+`|format=complexarray|name=@berichten}}<!-- -->{{#camap:@berichten|@@@| <div class="col-md-6"> <div class="card"><!-- -->{{#tag:html|<div class="card-top" style="background-image:url('{{#if:@@@[Image]|{{filepath:{{#replace:@@@[Image]|Bestand:|}}}}|https://cdn.mos.cms.futurecdn.net/VSy6kJDNq2pSXsCzb6cvYF-1024-80.jpg.webp}}')"> </div>}}<!-- --><div class="card-bottom"> <div><small><b>{{#if:@@@[Datum]|{{#time:d M Y|@@@[Datum]|nl}} }}</b></small></div> <h2>@@@[Titel]</h2> <div class="text-read-more">{{#regex:@@@[Bericht]|/<[^>]*>/|<nowiki/> <nowiki/>}} <i> {{#widget:link|type=a|href=@@@[cafullurl]|text=Lees meer|class=red}}</i></div> </div> </div> </div> |}}` var params = { action: 'parse', text: wikitext, contentmodel: 'wikitext', format: 'json' }, api = new mw.Api(); api.post( params ).done( function ( data ) { console.log(data.parse.text['*']) var newrow = document.createElement('div'); newrow.classList.add('row') newrow.insertBefore(document.querySelector('.fa-plus').closest('.col-md-6')) entry.target.innerHTML = data.parse.text['*']; )} } 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; }) }