I was looking for a way to get the FCKeditor to work with the AHAH module. I was searching these websites to get more info however I am unsure on how to modify the drupal module to achieve this.

http://magia3e.wordpress.com/2007/01/21/fckeditor-ajax-and-edit-in-place...

http://blog.zunch.com/post/Using_FCKEditor_in_AJAX.html

Can anyone help me?

Comments

Jorrit’s picture

Status: Active » Postponed (maintainer needs more info)

Is it still not working out of the box?

jhodgdon’s picture

I was just testing this with FCKEditor 6.x-2.0-alpha5, and did some debugging to figure out what is going on.

Here's what I did, to reproduce this bug:

0. Install FCKEditor and make sure the profile is set up to use FCK on all text area fields.
1. Using CCK, create a content type with a multiple-valued text area field in it.
2. Go to Create Content; add a new node of this content type.
3. So far so good: the edit screen shows up with FCK editing on the body, as well as my text area fields.
4. Click on the dynamic CCK AJAX/AHAH "add another item" button. The new text area item is added, but FCK editing is NOT enabled for this field.

After a while debugging the problem, it appears that the issue is this: (you may know this, but I thought since I spent the time debugging I might as well write it all down):

a) When the page is first loaded, the FCK editor is added to textarea elements in forms because of hook_elements in fckeditor.module -- which tells Drupal to process all textarea elements and turn them into editors (if they have the right IDs).

b) This is accomplished by function fckeditor_process_textarea() (in fckeditor.module). The fckeditor_process_textarea() function gives each textarea some class attributes such as "fckeditor", which works fine. Also, in the course of processing, the fckeditor_process_textarea() function creates some JavaScript that sets up an array called fckInstances. After each editor instance JS is configured, the PHP function calls drupal_add_js() to add it as a new element in the fckInstances JavaScript array, storing the editor information for that text area (indexed by the text area's ID). This JS works fine when the document is being loaded for the first time (the JS is added to the document head), but it doesn't work during AHAH, because the JS doesn't get added to the document or to the returned AJAX response (I actually got the entire response from Firebug and it definitely isn't there).

c) When the page is loaded, and again after an AHAH moment, the Drupal.attachBehaviors JavaScript function calls into Drupal.behaviors.fckeditor (in fckeditor.utils.js). This function goes through all textarea elements in the document (if it's document load) or in the AHAH content (for an AHAH moment) that have class "fckeditor". So far, so good -- it will find the new text area that was added. However, the next line of the function says "if it doesn't have an entry in fckInstances, skip it". The new text area does not have an entry in the array, so it is skipped. Then it enables the FCK editor on any fields that were in fckInstances, and you can still edit those fields.

That's what's happening... basically, only textarea elements that exist when the page is first loaded can ever be FCK-editor-ized, with the current module architecture, as far as I can tell. Not sure how to fix that.

smartango’s picture

What if I have developed a module that load form via ajax and I can execute code after loading form?

something like:

$("#tipologia-wrapper").load(uri
,function() {
//code
});

where uri is uri of a drupal callback that generate form. What is the code here?

jhodgdon’s picture

Just a note that the WYSIWIG API module does work with AHAH. And you can use several editors with it, including FCK.

The reason it works is that that module keys off whether a field has an input format rather than being plain text, and it doesn't try to detect everything on the page on page load, but does it more dynamically.

Jorrit’s picture

Version: 5.x-2.0-beta » 6.x-2.x-dev
Category: support » feature
Status: Postponed (maintainer needs more info) » Active
Jorrit’s picture

Version: 6.x-2.x-dev » master
Status: Active » Postponed

In the next version, javascript needs to be revised to support scenarios like this.

Jorrit’s picture

Status: Postponed » Closed (won't fix)