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().
This commit is contained in:
helicopetr 2014-12-12 11:18:27 +01:00
parent 4d8faa3728
commit 978788fd17
3 changed files with 8 additions and 2 deletions

View File

@ -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'));
}
});

View File

@ -1,3 +1,3 @@
<div class="django-ckeditor-widget" data-field-id="{{id}}" style="display: inline-block;">
<textarea{{ final_attrs|safe }} data-processed="0" data-config='{{config|safe}}' data-id="{{id}}" data-type="ckeditortype">{{ value }}</textarea>
<textarea{{ final_attrs|safe }} data-processed="0" data-config='{{config|safe}}' data-external-plugin-resources='{{external_plugin_resources|safe}}' data-id="{{id}}" data-type="ckeditortype">{{ value }}</textarea>
</div>

View File

@ -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)
}))