I would like to request that an event be fired prior to submitting the form via post/ajax submit.

ckeditor.utils.js
Here are the two functions that need changed for such a request (notice new event "beforeDrupalFormSaved"):
Line# ~160

Drupal.ckeditorOff = function(textarea_id) {
        if (!CKEDITOR.instances || typeof(CKEDITOR.instances[textarea_id]) == 'undefined') {
            return;
        }
        if (!CKEDITOR.env.isCompatible) {
            return;
        }
        if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id)
            delete Drupal.ckeditorInstance;

		CKEDITOR.instances[textarea_id].fire("beforeDrupalFormSaved");
        $("#" + textarea_id).val(CKEDITOR.instances[textarea_id].getData());
        CKEDITOR.instances[textarea_id].destroy(true);

        $("#" + textarea_id).next(".grippie").css("display", "block");
    };

Line# ~230

if (typeof(Drupal.Ajax) != 'undefined' && typeof(Drupal.Ajax.plugins) != 'undefined') {
        Drupal.Ajax.plugins.CKEditor = function(hook, args) {
            if (hook === 'submit' && typeof(CKEDITOR.instances) != 'undefined') {
                for (var i in CKEDITOR.instances) {
					CKEDITOR.instances[i].fire("beforeDrupalFormSaved");
                    CKEDITOR.instances[i].updateElement();
				}
            }
            return true;
        };
    }

Adding this event allows for custom processing of data output. I have written a module that I intend to release, that integrates GeSHi Filter. The above changes must be made for it to operate without need for .patch files.
I would assume the unobtrusive nature of the above, would lend towards a steadfast modification.

CommentFileSizeAuthor
#1 ckeditor.utils_.js_.patch1.03 KBlonewolfcode
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lonewolfcode’s picture

FileSize
1.03 KB

Attached patch file

Here is the project now associated with this: http://drupal.org/sandbox/lonewolfcode/1624868
And the request for full-project access: http://drupal.org/node/1627738

mkesicki’s picture

Priority: Critical » Normal
lonewolfcode’s picture

In order to give this a little more credence, let me ask you this:

If you are Javascript, and you want to perform changes to CKEditor's value (ie. editor.getData() ) before it is destroyed, and before the data is stored outside of CKEditor, how would you achieve such a task?

Using something like editor.on('destroy', function(event) {...}); won't suffice, because once the editor is being destroyed, it's too late -- the data that will be submitted to Drupal has already been retrieved and stored.
It's very simple. ckeditor.utils.js, performs the following:

  1. $('#'+id).val(CKEDITOR.instances[id].getData());
  2. CKEDITOR.instances[id].destroy()

It get's the value, immediately stores it in the original DOM textarea using jquery, and then destroys ckeditor. Ckeditor has no warning that it is about to be destroyed. And how is .getData event to know that it is the last time it will be called?

That is why I make this request, and I hope that someone understands a.) the usefulness of having this event fired, and b.) the fact that firing it when nothing is listening has no effect - and so integrating this event has no potential for problems for users that do not need it. Especially given the unique identifier used when firing it.

I will continue looking for a way to achieve the same functionality without firing an event before ckeditor.utils.js destroys CKEditor. And if someone by chance has a better solution or theory, I would love nothing more than to discuss it. :)
Otherwise, I suppose I can only hope that this request gets some attention...

Thanks to whomever reads this.