xref: /webtrees/resources/views/modules/ckeditor/ckeditor-js.phtml (revision 9d74ed0ab3ae61aa8ae07578e026f14020844ce9)
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 =
29          'area[shape,coords,href,target,alt,title];' +
30          'map[name];' +
31          'img[usemap];' +
32          'audio[controls,src];' +
33          'video[controls,height,poster,src,width];' +
34          '*{*}(*)';
35
36        // Do not convert é to &eacute; in the editor
37        CKEDITOR.config.entities = false;
38
39        // Activate the editor
40        elements.forEach(element => CKEDITOR.replace(element.id));
41      };
42
43      document.querySelector('head').appendChild(script);
44    }
45  })();
46</script>
47