Skip to content

Commit

Permalink
Merge 4c3e988 into 2a5ad56
Browse files Browse the repository at this point in the history
  • Loading branch information
ataylor32 committed Jan 11, 2017
2 parents 2a5ad56 + 4c3e988 commit 2f77b5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
25 changes: 25 additions & 0 deletions tinymce/static/django_tinymce/init_tinymce.js
Expand Up @@ -6,6 +6,31 @@ var django = django || {
function initTinyMCE($e) {
if ($e.parents('.empty-form').length == 0) { // Don't do empty inlines
var mce_conf = $.parseJSON($e.attr('data-mce-conf'));

// There is no way to pass a JavaScript function as an option
// because all options are serialized as JSON.
var fns = [
'color_picker_callback',
'file_browser_callback',
'file_picker_callback',
'images_dataimg_filter',
'images_upload_handler',
'paste_postprocess',
'paste_preprocess',
'setup',
'urlconverter_callback',
];
$.each(fns, function(i, fn_name) {
if (typeof mce_conf[fn_name] != 'undefined') {
if (mce_conf[fn_name].indexOf('(') != -1) {
mce_conf[fn_name] = eval('(' + mce_conf[fn_name] + ')');
}
else {
mce_conf[fn_name] = window[mce_conf[fn_name]];
}
}
});

var id = $e.attr('id');
if ('elements' in mce_conf && mce_conf['mode'] == 'exact') {
mce_conf['elements'] = id;
Expand Down
15 changes: 1 addition & 14 deletions tinymce/widgets.py
Expand Up @@ -61,19 +61,6 @@ def get_mce_config(self, attrs):
mce_config['elements'] = attrs['id']
return mce_config

def get_mce_json(self, mce_config):
# Fix for js functions
js_functions = {}
for k in ('paste_preprocess', 'paste_postprocess'):
if k in mce_config:
js_functions[k] = mce_config[k]
del mce_config[k]
mce_json = json.dumps(mce_config)
for k in js_functions:
index = mce_json.rfind('}')
mce_json = mce_json[:index] + ', ' + k + ':' + js_functions[k].strip() + mce_json[index:]
return mce_json

def render(self, name, value, attrs=None):
if value is None:
value = ''
Expand All @@ -86,7 +73,7 @@ def render(self, name, value, attrs=None):
final_attrs['class'] = ' '.join(final_attrs['class'].split(' ') + ['tinymce'])
assert 'id' in final_attrs, "TinyMCE widget attributes must contain 'id'"
mce_config = self.get_mce_config(final_attrs)
mce_json = self.get_mce_json(mce_config)
mce_json = json.dumps(mce_config)
if tinymce.settings.USE_COMPRESSOR:
compressor_config = {
'plugins': mce_config.get('plugins', ''),
Expand Down

0 comments on commit 2f77b5d

Please sign in to comment.