head: load edit script before body
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 7 Dec 2020 14:23:49 +0000 (15:23 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Dec 2020 02:01:43 +0000 (03:01 +0100)
Introduce $Page->head for html head output.

Allows editor setup before running other javascript.

head.inc.php
page.inc.php

index 4082b92b77748498a8b42caa3afbce9118cbd687..9ff649579398ad3dcaee9d350a11e839677a0c1b 100644 (file)
@@ -15,5 +15,6 @@
 <?php } ?>
        <meta property="og:type" content="<?= $Page->meta['og:type'] ?? 'website' ?>" />
        <meta property="og:url" content="https://<?= $_SERVER['HTTP_HOST'] . '/' . htmlspecialchars($Page->link) ?>" />
+<?php if (isset($Page->head)) print $Page->head; ?>
 </head>
 <body>
index 8eba91bdac04d80ccd3f8566197e67fe476cbee8..17e7c807269f444df3a9e8589bee7ff674a533b3 100644 (file)
@@ -1,4 +1,15 @@
 <?php
+if ($User and $User->admin("edit {$Page->link}")) {
+       $ckesrc = '/lib/ckeditor'; # local install
+       if (!file_exists(DOCROOT . $ckesrc)) {
+               $ckesrc = '//cdn.ckeditor.com/4.15.1/full-all'; # remote fallback
+       }
+       ob_start();
+       printf("<script>var ckesrc = '%s'</script>\n", "$ckesrc/ckeditor.js");
+       print '<script src="/edit/page.js"></script>'."\n";
+       $Page->head = ob_get_clean();
+}
+
 include_once 'head.inc.php';
 
 print "<header>\n";
@@ -43,17 +54,6 @@ register_shutdown_function(function () {
        print '<footer>';
        @include 'footer.inc.html';
        print "</footer>\n";
-
-       global $User, $Page;
-       if ($User and $User->admin("edit {$Page->link}")) {
-               $ckesrc = '/lib/ckeditor'; # local install
-               if (!file_exists(DOCROOT . $ckesrc)) {
-                       $ckesrc = '//cdn.ckeditor.com/4.15.1/full-all'; # remote fallback
-               }
-               printf("<script>var ckesrc = '%s'</script>\n", "$ckesrc/ckeditor.js");
-               print '<script src="/edit/page.js"></script>'."\n";
-       }
-
        print "</body></html>\n";
 });