Move initial CKEditor code to function and run it when '#container' ready.

This commit is contained in:
Arcady Usov 2014-04-13 23:39:51 +06:00
parent 47dc1824da
commit 6f4f59655a
1 changed files with 16 additions and 12 deletions

View File

@ -14,18 +14,7 @@
(function($) {
// CMS.$ will be passed for $
$(document).ready(function () {
// get the container id
var container = 'id_{{ name }}';
var prefixPos = container.indexOf('-__prefix__');
if (prefixPos != - 1) {
// in case the textarea is in an inline, we need to perform some replacements
var name = container.substring(0, prefixPos);
var replacement = $('#' + name + "-TOTAL_FORMS").val();
container = container.replace('__prefix__', replacement);
}
// initialize ckeditor only if the container exists and is ready
$('#'+container).ready(function() {
function initCKEditor(container) {
CMS.CKEditor.init(container, {{ settings|safe }}, {
'static_url': '{{ STATIC_URL }}',{% if placeholder %}
'add_plugin_url': '{{ placeholder.get_add_url }}',
@ -51,6 +40,21 @@ $(document).ready(function () {
'toolbar': 'HTMLField'
{% endif %}
});
}
// get the container id
var container = 'id_{{ name }}';
var prefixPos = container.indexOf('-__prefix__');
if (prefixPos != - 1) {
// in case the textarea is in an inline, we need to perform some replacements
var name = container.substring(0, prefixPos);
var replacement = $('#' + name + "-TOTAL_FORMS").val();
container = container.replace('__prefix__', replacement);
}
// initialize ckeditor only if the container exists and is ready
$('#'+container).ready(function() {
initCKEditor(container);
});
});
})(CMS.$);