X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/bae682c87abd4a43231496979963a6bbb66ecc4e..1150da9a36d521bcff52ff08b784f7a5608aa5fa:/nieuws/edit.js diff --git a/nieuws/edit.js b/nieuws/edit.js index 6f3f54f..0061b02 100644 --- a/nieuws/edit.js +++ b/nieuws/edit.js @@ -1,14 +1,19 @@ -var editlink = document.createElement('a'); -editlink.className = 'nav'; -editlink.appendChild(document.createTextNode('Nieuw artikel')); -editlink.onclick = function () { - var today = new Date().toJSON().slice(0, 10).split('-'); - var input = prompt('Paginalink (beknopte titel)', ''); - if (!input) return false; - var url = today[0] + '/' + today[1] + '-' + today[2] + '-' + - input.toLowerCase().replace(/[^a-z0-9]+/g, '-').trim(); - var title = encodeURIComponent(input.trim()); - window.location = window.location.pathname+'/'+url+'?edit='+title+'#edit'; - return false; -}; -document.getElementById('news').appendChild(editlink); +document.addEventListener('DOMContentLoaded', () => { + var overview = document.getElementById('news'); + if (overview) { + var editlink = document.createElement('a'); + editlink.className = 'nav'; + editlink.appendChild(document.createTextNode('Nieuw artikel')); + editlink.onclick = function () { + var today = new Date().toJSON().slice(0, 10).split('-'); + var input = prompt('Paginalink (beknopte titel)', ''); + if (!input) return false; + var url = today[0] + '/' + today[1] + '-' + today[2] + '-' + + input.toLowerCase().replace(/[^a-z0-9]+/g, '-').trim(); + var title = encodeURIComponent(input.trim()); + window.location = window.location.pathname+'/'+url+'?edit='+title+'#edit'; + return false; + }; + overview.appendChild(editlink); + } +});