edit/page: add edit button in javascript
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 14:40:52 +0000 (15:40 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 21 Dec 2020 16:46:33 +0000 (17:46 +0100)
edit/head.inc.php
edit/page.js
page.inc.php

index 5c056a7c620077b15c541d9a55d5f60645bbd701..9759ec818a4e8cbac0bd34b21b1004c94bf61b2e 100644 (file)
@@ -11,6 +11,19 @@ if (!isset($Page->raw)) {
        $Page->body = NULL;
 }
 
+$editpage = $Page->link;
+if (is_dir($editpage)) {
+       if (file_exists("$editpage/index.html")) {
+               $editpage .= '/index.html';
+       }
+}
+else {
+       $editpage .= '.html';
+}
+if (file_exists($editpage) and !is_writable($editpage)) {
+       return;
+}
+
 if (isset($Page->raw)) {
        # restore meta tags in static contents for editing
        foreach (array_reverse($Page->meta) as $metaprop => $val) {
index 45d9e644cb9c28c4ede56d46f62b575bdb6813a4..7d20c655f60afe26fd928acfe1d316bf1f8f90bf 100644 (file)
@@ -175,8 +175,12 @@ CKEDITOR.on('instanceCreated', function (event) {
 
 if (pagebody) {
        // add edit link to menu
-       var editlink = document.querySelector('a[href="#edit"]');
-       if (editlink)
+       var editdiv = document.querySelector('header .login > p');
+       if (!editdiv) return;
+       var editlink = editdiv.appendChild(document.createElement('a'));
+       editlink.append('\u270D');
+       editlink.className = 'icon icon-edit';
+       editlink.href = '#edit';
        editlink.onclick = function (e) {
                editlink.style.fontWeight = 'bold';
                editlink.href = '';
index 3559e63b07fafff9f548411e8ee4f41c8db75daf..6ffd9cc6321cd0c05c07d8669137b61c9633068a 100644 (file)
@@ -10,20 +10,6 @@ if ($User and property_exists($User, 'login') and $User->login) {
                '<span class="icon icon-user">&#x1F464;</span>',
                '/login', $User->login
        );
-       if ($User->admin("edit {$Page->link}")) {
-               $editpage = $Page->link;
-               if (is_dir($editpage)) {
-                       if (file_exists("$editpage/index.html")) {
-                               $editpage .= '/index.html';
-                       }
-               }
-               else {
-                       $editpage .= '.html';
-               }
-               if (!file_exists($editpage) or is_writable($editpage)) {
-                       print ' <a class="icon icon-edit" href="#edit" title="wijzig">&#x270D;</a>';
-               }
-       }
        print "</p></div>\n";
 }
 $menu->place['login'] = ob_get_clean();