After adding this plugin you can register a new event listener on a CKEditor instance to get notified whenever the content changes (well, in fact it might fire even in some situations where there are no real changes, but it's up to you what to do and perform other checks)
Further explanations at the post in my blog.
Plugin sponsored by Falcana.
License
Licensed under the terms of any of the following licenses at your choice: GPL, LGPL and MPL.
Download
onChange version 1.6:
download link
Installation
1. Extract the contents of the file into the "plugins" folder of CKEditor.
2. In the CKEditor configuration file (config.js) add the following code:
config.extraPlugins = 'onchange';
Re: onChange event. Get an event when the content changes
Note that if you destroy the editor, then due to the 100ms delay, this callback gets called but there is no editor!
So I would recommend one of the following:
1. do nothing (maybe it doesn't matter if your callback crashes in this case) (but it seems to leave ckeditor in a buggy state, if your callback uses e.editor.getData() (this leads to an error))
2. in your callback function(e), check whether the editor still exists (I don't see how to do this, since e.editor does still exist and looks about the same) and deal with it as you like (this approach could lose the last 100ms of editing, probably not a problem if events are coming from a user's mouse and the system performance is fine, otherwise could be buggy)
3. postpone the destruction with an even longer timeout (easy, but relies on the system not being overloaded, and not very extendable to work with many plugins)
4. to destroy, trigger a change event before postponing the destruction (like 3) to ensure at least one final change will always fire before the destruction
5. modify this plugin (onchange) to modify the destruction mechanism to cancel pending callbacks and call the callback directly before proceeding with the destruction, perhaps with some clear signal that this is the final callback.
(3) and (4) assume you have control over all ways the editor might be destroyed, which in the general case (like in the presence of arbitrary other plugins) won't be true.
(5) would seem to be the best, but I don't know a good way to hook into the destruction.
-Matt
Re: onChange event. Get an event when the content changes
Adding is enough to prevent firing the event after the editor has been destroyed.
If you want to do something else, then you just have to listen for that same event; I don't think that it's good to fire any extra events while the editor is being destroyed because otherwise some code might attempt to do things without realizing that the instance will go away.
I'm gonna update now the plugin to include this patch.
Re: onChange event. Get an event when the content changes
I agree that there's no need for onchange to notify about destruction, since (as you show) it's so easy to do it directly.
But I think that if the timer was going, then there was (probably) a change that the callback never heard about yet, so in this case the callback should be called one final time before the editor is destroyed, just to keep onchange's promise of notifying after any change.
This could come up if say a custom toolbar button does some final formatting and then closes the editor, in which case there would be no delay between the change and the destruction.
Re: onChange event. Get an event when the content changes
What the problem was: I have a toolbar button that closes the window, and for some reason (maybe afterCommandExec?) it triggers a change event. (Contrast this with the ajax.html sample page, which doesn't fire a change event when the "remove editor" button is pressed.) Then my change event callback contains:
and this gets called when the "close editor" button is pressed, and this generates an error.
But with the following patch to onchange/plugin.js, the problem is fixed. There is still a change event when the button is pressed, but now getData() works correctly every time, so it's no problem.
Re: onChange event. Get an event when the content changes
Destroying the editor from a button is not usual and most of the times leads to any kind of problems as that's not the expected behavior.
See for example this other post: viewtopic.php?f=11&t=24324
You could try to help him because according to your comments that's what you are doing.
Re: onChange event. Get an event when the content changes
Destroying the editor is a supported action and it seems fairly easy to get a button to do it safely, as described in that thread. Whether it's "usual" or not probably depends very much on your application.
The more plugins that work well together, the better!
Hi,
Hi,
It's an hold post but always usefull, i try to make it work with ckeditor 4 but it's not working correctly :( event is fire when i press enter but not on other keys... And if i use toolbar button event is fire to.
Can you give me a way to make it work on 4 version please ?
Thanks
CKSource stated that they are
CKSource stated that they are going to release their own version, so I stopped updating the plugin as it didn't make sense to waste my time here.
Ho ok ! I understand :)
Ho ok ! I understand :) thanks !
Is there a place where I can
Is there a place where I can get updates on a CKSource version? I'd like this functionality, but seem to have fallen into a dead zone between this plugin support and the new release.
Here's the ticket: http://dev
Here's the ticket: http://dev.ckeditor.com/ticket/9794
It seems that it would have been easier and quicker for Drupal to start using the existing plugin and due to the magic of open source improve it to meet whatever requirements they had, but as CKSource agreed to meet their requirements and create a new one from scratch I prefer to spend my time doing other things instead of updating a plugin that I don't use (it's already hard enough try to keep updated the plugins and patches for all the issues that CKSource doesn't fix)