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