1 document.addEventListener('DOMContentLoaded', () => {
2 var nav = document.querySelector('#news .nav');
4 var editlink = document.createElement('a');
5 editlink.appendChild(document.createTextNode('Nieuw artikel'));
6 editlink.onclick = function () {
7 var today = new Date().toJSON().slice(0, 10).split('-');
8 var input = prompt('Paginalink (beknopte titel)', '');
9 if (!input) return false;
10 var url = today[0] + '/' + today[1] + '-' + today[2] + '-' +
11 input.toLowerCase().replace(/[^a-z0-9]+/g, '-').trim();
12 var title = encodeURIComponent(input.trim());
13 window.location = window.location.pathname+'/'+url+'?edit='+title+'#edit';
16 nav.appendChild(document.createTextNode(' '));
17 nav.appendChild(editlink);
20 var editlink = document.querySelector('a[href="#edit"]');
21 if (!editlink) return;
22 editlink.addEventListener('click', () => {
23 document.querySelectorAll('.tags input').forEach(tagoption => {
24 tagoption.removeAttribute('disabled');
25 tagoption.addEventListener('change', () => {
26 let editpost = '/edit/nieuws/tag' + window.location.pathname;
27 let params = new URLSearchParams;
28 params.append('tag', tagoption.value);
29 params.append('value', tagoption.checked ? 1 : 0);
33 credentials: 'same-origin',
36 if (res.status != 200) {
37 return res.text().then(body => {
38 throw `foutcode ${res.status}: ${body}`;
43 alert(`Tag aanpassen mislukt: ${error}`);