diff --git a/djangocms_text_ckeditor/cms_plugins.py b/djangocms_text_ckeditor/cms_plugins.py index 7ab7f95..9c2d4e9 100644 --- a/djangocms_text_ckeditor/cms_plugins.py +++ b/djangocms_text_ckeditor/cms_plugins.py @@ -22,7 +22,7 @@ class TextPlugin(CMSPluginBase): Returns the Django form Widget to be used for the text area """ - return TextEditorWidget(attrs={'class': 'CMS_CKEditor'}, installed_plugins=plugins, pk=pk, placeholder=placeholder, plugin_language=language) + return TextEditorWidget(installed_plugins=plugins, pk=pk, placeholder=placeholder, plugin_language=language) def get_form_class(self, request, plugins, pk, placeholder, language): """ diff --git a/djangocms_text_ckeditor/fields.py b/djangocms_text_ckeditor/fields.py index b4382ee..64476b2 100644 --- a/djangocms_text_ckeditor/fields.py +++ b/djangocms_text_ckeditor/fields.py @@ -11,12 +11,12 @@ except ImportError: class HTMLField(models.TextField): def formfield(self, **kwargs): - defaults = {'widget': TextEditorWidget(attrs={'class': 'CMS_CKEditor'})} + defaults = {'widget': TextEditorWidget()} defaults.update(kwargs) # override the admin widget if defaults['widget'] == admin_widgets.AdminTextareaWidget: - defaults['widget'] = TextEditorWidget(attrs={'class': 'CMS_CKEditor'}) + defaults['widget'] = TextEditorWidget() return super(HTMLField, self).formfield(**defaults) diff --git a/djangocms_text_ckeditor/templates/cms/plugins/widgets/ckeditor.html b/djangocms_text_ckeditor/templates/cms/plugins/widgets/ckeditor.html index 2b079c3..5385d8c 100644 --- a/djangocms_text_ckeditor/templates/cms/plugins/widgets/ckeditor.html +++ b/djangocms_text_ckeditor/templates/cms/plugins/widgets/ckeditor.html @@ -15,8 +15,8 @@ // CMS.$ will be passed for $ $(document).ready(function () { function initCMSCKEditor() { - if ($('.CMS_CKEditor:visible').length > 0) { - $('.CMS_CKEditor:visible').each(function() { + if ($('.{{ ckeditor_class }}:visible').length > 0) { + $('.{{ ckeditor_class }}:visible').each(function() { $(this).hide(); var container = $(this).attr('id'); diff --git a/djangocms_text_ckeditor/widgets.py b/djangocms_text_ckeditor/widgets.py index 25b1aa9..eac3dae 100644 --- a/djangocms_text_ckeditor/widgets.py +++ b/djangocms_text_ckeditor/widgets.py @@ -16,6 +16,16 @@ class TextEditorWidget(Textarea): installed_plugins is a list of plugins to display that are text_enabled """ + if attrs is None: + attrs = {} + + self.ckeditor_class = 'CMS_CKEditor' + if self.ckeditor_class not in attrs.get('class', '').join(' '): + new_class = attrs.get('class', '') + ' %s' % self.ckeditor_class + attrs.update({ + 'class': new_class.strip() + }) + super(TextEditorWidget, self).__init__(attrs) self.installed_plugins = installed_plugins self.pk = pk @@ -28,6 +38,7 @@ class TextEditorWidget(Textarea): def render_additions(self, name, value, attrs=None): language = get_language().split('-')[0] context = { + 'ckeditor_class': self.ckeditor_class, 'name': name, 'language': language, 'settings': language.join(json.dumps(text_settings.CKEDITOR_SETTINGS).split("{{ language }}")),