nieuws: include admin edit javascript on subpages
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 17 Sep 2018 14:27:00 +0000 (16:27 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 Sep 2018 15:15:46 +0000 (17:15 +0200)
nieuws/edit.js
nieuws/index.php

index 6f3f54fa7856e7dc3a93072bd4c8208da0f45621..0061b025a315b61608a034178177ead4ea1a1236 100644 (file)
@@ -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);
+       }
+});
index 73973574629bce60a06b8eb8a640cf37a39d43ad..1a520112da6663f1805f602829469f6c65a1ee99 100644 (file)
@@ -4,6 +4,10 @@ include 'nieuws.inc.php';
 $replyform = $Page == 'melding' && !empty($User);
 @list ($year, $page) = explode('/', trim($Args, '/'));
 
+if (!empty($User['admin'])) {
+       print '<script src="/nieuws/edit.js"></script>'."\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 '<script src="/nieuws/edit.js"></script>'."\n";
-}