nieuws: include admin edit javascript on subpages
[minimedit.git] / nieuws / edit.js
1 document.addEventListener('DOMContentLoaded', () => {
2         var overview = document.getElementById('news');
3         if (overview) {
4                 var editlink = document.createElement('a');
5                 editlink.className = 'nav';
6                 editlink.appendChild(document.createTextNode('Nieuw artikel'));
7                 editlink.onclick = function () {
8                         var today = new Date().toJSON().slice(0, 10).split('-');
9                         var input = prompt('Paginalink (beknopte titel)', '');
10                         if (!input) return false;
11                         var url = today[0] + '/' + today[1] + '-' + today[2] + '-' +
12                                 input.toLowerCase().replace(/[^a-z0-9]+/g, '-').trim();
13                         var title = encodeURIComponent(input.trim());
14                         window.location = window.location.pathname+'/'+url+'?edit='+title+'#edit';
15                         return false;
16                 };
17                 overview.appendChild(editlink);
18         }
19 });