xref: /webtrees/resources/views/modules/ckeditor/ckeditor-js.phtml (revision 2c6f1bd538f46b93645991518398bb087011cb42)
1<?php
2
3declare(strict_types=1);
4
5/**
6 * @var string $ckeditor_path
7 * @var string $language
8 */
9
10?>
11<script>
12  const CKEDITOR_BASEPATH = <?= json_encode($ckeditor_path, JSON_THROW_ON_ERROR) ?>;
13
14  (function () {
15    let elements = document.querySelectorAll('textarea.html-edit');
16
17    if (elements.length !== 0) {
18      let script = document.createElement('script');
19      script.src = <?= json_encode($ckeditor_path . 'ckeditor.js', JSON_THROW_ON_ERROR) ?>;
20      script.type = 'text/javascript';
21      script.onload = function () {
22        // Enable for all browsers
23        CKEDITOR.env.isCompatible = true;
24
25        // Disable toolbars
26        CKEDITOR.config.language = <?= json_encode(strtolower($language), JSON_THROW_ON_ERROR) ?>;
27        CKEDITOR.config.removePlugins = 'forms,newpage,preview,print,save,templates,flash,iframe';
28        CKEDITOR.config.extraAllowedContent = 'area[shape,coords,href,target,alt,title];map[name];img[usemap];*{*}(*)';
29
30        // Do not convert é to &eacute; in the editor
31        CKEDITOR.config.entities = false;
32
33        // Activate the editor
34        elements.forEach(element => CKEDITOR.replace(element.id));
35      };
36
37      document.querySelector('head').appendChild(script);
38    }
39  })();
40</script>
41