Hello
I've got a lightbox on my website (just wo divs, toggle theri status form display=none to display=block). In this lightbox I'm initializing 4 instances of ckeditor.
<textarea class="editor" name="editor1"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor2"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor3"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor4"><p>Initial value.</p></textarea>
<script type="text/javascript">
CKEDITOR.replaceAll( 'editor' );
</script>
When I'm opening the "lighbox" everything works and I see the 4 editors. Now I'm closing this box. (Set div to display=hidden and set the innerHTML to null).
And if I want to reopen the lightbox (with the same sourcecode) I'll get this errormessage:
uncaught exception: [CKEDITOR.editor] The instance "editor1" already exists.
Does anybody know a way to solve this problem?
I've got a lightbox on my website (just wo divs, toggle theri status form display=none to display=block). In this lightbox I'm initializing 4 instances of ckeditor.
<textarea class="editor" name="editor1"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor2"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor3"><p>Initial value.</p></textarea>
<textarea class="editor" name="editor4"><p>Initial value.</p></textarea>
<script type="text/javascript">
CKEDITOR.replaceAll( 'editor' );
</script>
When I'm opening the "lighbox" everything works and I see the 4 editors. Now I'm closing this box. (Set div to display=hidden and set the innerHTML to null).
And if I want to reopen the lightbox (with the same sourcecode) I'll get this errormessage:
uncaught exception: [CKEDITOR.editor] The instance "editor1" already exists.
Does anybody know a way to solve this problem?
Re: Problems with JavaScript and CKEditor
CKEDITOR.remove(editor)
Re: Problems with JavaScript and CKEditor
Now I inserted this simple code:
delete CKEDITOR.instances[ 'editor1' ];
delete CKEDITOR.instances[ 'editor2' ];
delete CKEDITOR.instances[ 'editor3' ];
delete CKEDITOR.instances[ 'editor4' ];
This Work. I have no idea why javscript ignoring the the remove statement.
Re: Problems with JavaScript and CKEditor
Re: Problems with JavaScript and CKEditor
Re: Problems with JavaScript and CKEditor
Thanks, appreciate the reference to the destroy function and your work.
I personally like passing in instance names instead of objects for management type classes as it's a little easier for non js folks to grasp. Just my opinion however.
CKEDITOR.remove('editarea');
or
var o=CKEDITOR.instances['editarea'];
if (o) o.destroy();
Re: Problems with JavaScript and CKEditor
Re: Problems with JavaScript and CKEditor
Found the post very useful, also would like to share my own expierence. Firstly, CKEditor (previous FCKeditor) is great tool. Use it it many projects. Recently, faced the problem, when browser consumes to much computer memory. The project where I used FCKEditor 2.6.5 was Ajax based. So FCKeditor was loaded and unloaded for many times without refreshing the page. By saying "unloaded", I simply mean that div's with FCKEditor where set to empty (innerHtml=''). Firstly, installed Firefox addon 'Memory leak', so now I could monitor memory consumtion. I noticed that everytime I loaded FCK, memory was reserved by FF and never freed (have to mention that checked it only on Firefox 2.5.8). For instance, after reloading FCK for 30 times, FF took 63MB (2.1MB/load). It was obvious that the problem was in API. Tried to Google and the anser was to check if an instance is already initialized, and if true, clear some API variables:
But this solution didn't help my much. So I thought that maybe this problem is solved in newer FCKeditor version. Set up CKEditor 3.1. The situation was better. After 50 reloads increase in memory was 24-29MB (0.5MB/load). Well it is 4 times beter than FCK 2.6.5. It is not perfect, but is better. Besides CK loads faster. Code that I used for CK.
If someone found better solution, please share...
Re: Problems with JavaScript and CKEditor
Kamiro did provide a much better code using the API:
Re: Problems with JavaScript and CKEditor
Can someone check memory consumption in their Firefox (I have 3.6 with all addons disabled). The sample is already in CKEditor package (v3.2) "_samples/ajax.html". Simply load the page, load editor, check memory consumption of FF in "Windows Task Manager" and press "Remove Editor" and "Create Editor" buttons. Do this for 50 times and check how much memory FF uses. The difference will be memory leak. Destroy() is used for removal, so memory should be always released.
My statistics are:
Firefox started, page loaded, editor loaded - 46MB
After pressing "Remove Editor" and "Create Editor" for 100 memory consumption of FF is 84MB. Diff - 38 (0.38MB/load).
Checked this on Chrome, IE8 there is no memory leak...
Hm...
Re: Problems with JavaScript and CKEditor
That will be fixed if you apply this patch: http://dev.fckeditor.net/ticket/4555 although there are still other parts of code to review.
But remember, if you don't call editor.destroy() then you won't get any benefit.
Re: Problems with JavaScript and CKEditor
This works fine when opening the first record to edit. Opening subsequent records without reloading the page generates an error. This is because CKEditor is trying to create a new instance with the same field name (and corresponding HTML element name).
The documentation is, in my opinion, misleading:
Not only is it misspelled, but it doesn't clearly explain the syntax used. Worse, the statement "This function is available for internal use mainly" is vague and put me off trying to use this method for a while.
Anyway, if you can't instantiate a CKEditor and you find you need to remove an existing instance, here is the code that I used.
Warning, I tried using the destroy() method mentioned elsewhere in this thread and I got exceptions thrown within the ckeditor core code when trying in IE 8. Using the remove() method alleviated this:
Re: Problems with JavaScript and CKEditor
The documentation is updated from last post in this topic and it says that external code should use CKEDITOR.editor.prototype.destroy to avoid memory leaks.
Example is here:
http://docs.cksource.com/ckeditor_api/s ... ml#destroy