Skip to content

Commit 0e713b3

Browse files
authored
Set CKEDITOR_BASEPATH via data-attribute on script src (#95)
1 parent c44d17f commit 0e713b3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
from djangocms_text.editors import RTEConfig
2-
1+
from cms.utils.urlutils import static_with_version
32
from django.conf import settings
43
from django.templatetags.static import static
5-
6-
from cms.utils.urlutils import static_with_version
74
from django.utils.functional import lazy
5+
from django.utils.html import format_html, html_safe
6+
7+
from djangocms_text.editors import RTEConfig
8+
9+
10+
@html_safe
11+
class BasePath:
12+
def __str__(self):
13+
return format_html(
14+
'<script src="{scriptsrc}" data-ckeditor-basepath="{basepath}"></script>',
15+
scriptsrc=static("djangocms_text/js/basepath.js"),
16+
basepath=getattr(
17+
settings,
18+
"TEXT_CKEDITOR_BASE_PATH",
19+
lazy(static, str)("djangocms_text/vendor/ckeditor4/"),
20+
),
21+
)
822

923

1024
ckeditor4 = RTEConfig(
1125
name="ckeditor4",
1226
config="CKEDITOR",
1327
js=(
1428
static_with_version("cms/js/dist/bundle.admin.base.min.js"),
15-
"djangocms_text/js/basepath.js",
29+
BasePath(),
1630
"djangocms_text/vendor/ckeditor4/ckeditor.js",
1731
"djangocms_text/bundles/bundle.ckeditor4.min.js",
1832
),
1933
css={"all": ("djangocms_text/css/cms.ckeditor4.css",)},
2034
inline_editing=True,
2135
child_plugin_support=True,
22-
additional_context=dict(
23-
CKEDITOR_BASEPATH=getattr(
24-
settings, "TEXT_CKEDITOR_BASE_PATH", lazy(static, str)("djangocms_text/vendor/ckeditor4/")
25-
),
26-
),
2736
)

djangocms_text/contrib/text_ckeditor4/static/djangocms_text/js/basepath.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
// It's loaded in this script since we avoid inline scripts (to better support CSP headers) and it needs to be
44
// set before the CKEditor script is loaded which in turn needs to be loaded before the integration script.
55

6-
window.CKEDITOR_BASEPATH = JSON.parse(document.getElementById('cms-editor-cfg').textContent).CKEDITOR_BASEPATH;
6+
window.CKEDITOR_BASEPATH = document.currentScript.dataset.ckeditorBasepath
7+

0 commit comments

Comments
 (0)