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