Skip to content

Commit

Permalink
Added public API to enable/disable the editor.
Browse files Browse the repository at this point in the history
The functions django_wysiwyg_enable() / django_wysiwyg_disable() can be called
by other scripts to enable/disable an editor on demand. This is particulary
useful for dynamic interfaces (e.g. Ajax) where elements are swapped on demand.
  • Loading branch information
vdboor committed Nov 26, 2010
1 parent 248a59f commit bcdef95
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
18 changes: 17 additions & 1 deletion django_wysiwyg/templates/django_wysiwyg/ckeditor/includes.html
Expand Up @@ -4,4 +4,20 @@
{% endcomment %}

<script type="text/javascript" src="{{ DJANGO_WYSIWYG_MEDIA_URL }}ckeditor.js"></script>
<script type="text/javascript" src="{{ DJANGO_WYSIWYG_MEDIA_URL }}sample.css"></script>
<script type="text/javascript" src="{{ DJANGO_WYSIWYG_MEDIA_URL }}sample.css"></script>
<script type="text/javascript">
function django_wysiwyg_enable(editor_name, field_id, config)
{
window[editor_name] = CKEDITOR.replace(field_id, config);
}

function django_wysiwyg_disable(editor_name)
{
var editor = window[editor_name];
if(editor)
{
editor.destroy(/*noUpdate=*/false);
window[editor_name] = null;
}
}
</script>
Expand Up @@ -5,8 +5,6 @@

<script type="text/javascript">
YAHOO.util.Event.onAvailable("{{ field_id }}", function() {
var config = django_wysiwyg_editor_configs['{{ field_id }}'] || django_wysiwyg_editor_config;
window['{{ editor_name }}'] = new YAHOO.widget.Editor("{{ field_id }}", config);
window['{{ editor_name }}'].render();
django_wysiwyg_enable('{{ editor_name }}', '{{ field_id }}');
});
</script>
20 changes: 20 additions & 0 deletions django_wysiwyg/templates/django_wysiwyg/yui/includes.html
Expand Up @@ -162,4 +162,24 @@
]
}
};

function django_wysiwyg_enable(editor_name, field_id, config)
{
if(!config) {
config = django_wysiwyg_editor_configs[field_id] || django_wysiwyg_editor_config;
}
window[editor_name] = new YAHOO.widget.Editor(field_id, config);
window[editor_name].render();
}

function django_wysiwyg_disable(editor_name)
{
var editor = window[editor_name];
if(editor)
{
editor.saveHTML();
editor.destroy();
window[editor_name] = null;
}
}
</script>

0 comments on commit bcdef95

Please sign in to comment.