From 978788fd17597338562c5f2ed6ca496e9b83c5ed Mon Sep 17 00:00:00 2001 From: helicopetr Date: Fri, 12 Dec 2014 11:18:27 +0100 Subject: [PATCH] Restore external-plugin-resources handling. This change re-adds functionality for adding external plugin resources. The resources, defined in the field, are passed to the widget, which renders them into the data-external-plugin-resources attribute. In ckeditor-init.js, this data attribute is read and the resources are added to the CKEditor, using CKEditor.plugins.addExternal(). --- ckeditor/static/ckeditor/ckeditor-init.js | 3 +++ ckeditor/templates/ckeditor/widget.html | 2 +- ckeditor/widgets.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ckeditor/static/ckeditor/ckeditor-init.js b/ckeditor/static/ckeditor/ckeditor-init.js index f3bd877..c588ca9 100644 --- a/ckeditor/static/ckeditor/ckeditor-init.js +++ b/ckeditor/static/ckeditor/ckeditor-init.js @@ -29,6 +29,9 @@ $('textarea[data-type=ckeditortype]').each(function(){ if($(this).data('processed') == "0" && $(this).attr('id').indexOf('__prefix__') == -1){ $(this).data('processed',"1"); + $($(this).data('external-plugin-resources')).each(function(){ + CKEDITOR.plugins.addExternal(this[0], this[1], this[2]); + }); CKEDITOR.replace($(this).attr('id'), $(this).data('config')); } }); diff --git a/ckeditor/templates/ckeditor/widget.html b/ckeditor/templates/ckeditor/widget.html index 74e81df..6ae1308 100644 --- a/ckeditor/templates/ckeditor/widget.html +++ b/ckeditor/templates/ckeditor/widget.html @@ -1,3 +1,3 @@
- {{ value }} + {{ value }}
diff --git a/ckeditor/widgets.py b/ckeditor/widgets.py index eaa4027..9a4fbb4 100644 --- a/ckeditor/widgets.py +++ b/ckeditor/widgets.py @@ -107,10 +107,13 @@ class CKEditorWidget(forms.Textarea): if not self.config.get('language'): self.config['language'] = get_language() + # Force to text to evaluate possible lazy objects + external_plugin_resources = [[force_text(a), force_text(b), force_text(c)] for a, b, c in self.external_plugin_resources] + return mark_safe(render_to_string('ckeditor/widget.html', { 'final_attrs': flatatt(final_attrs), 'value': conditional_escape(force_text(value)), 'id': final_attrs['id'], 'config': json_encode(self.config), - 'external_plugin_resources' : self.external_plugin_resources + 'external_plugin_resources' : json_encode(external_plugin_resources) }))