From 1150da9a36d521bcff52ff08b784f7a5608aa5fa Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 17 Sep 2018 16:27:00 +0200 Subject: [PATCH] nieuws: include admin edit javascript on subpages --- nieuws/edit.js | 33 +++++++++++++++++++-------------- nieuws/index.php | 8 ++++---- 2 files changed, 23 insertions(+), 18 deletions(-) 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); + } +}); diff --git a/nieuws/index.php b/nieuws/index.php index 7397357..1a52011 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -4,6 +4,10 @@ include 'nieuws.inc.php'; $replyform = $Page == 'melding' && !empty($User); @list ($year, $page) = explode('/', trim($Args, '/')); +if (!empty($User['admin'])) { + print ''."\n"; +} + if ($page and !is_numeric($page)) { $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL; $article = new ArchiveArticle("$Page$Args.html"); @@ -62,7 +66,3 @@ if ($year) { print placeholder_include('nieuws', [$match]); return 1; } - -if (!empty($User['admin'])) { - print ''."\n"; -} -- 2.30.0