Right now it looks like tinyMCE is the only editor that correctly updates the active editor when there are multiple editors on the same page. This patch adds onFocus support to FCKeditor so that we can update the Drupal.wysiwyg.activeId variable when there are multiple FCKeditors on the same page. Unfortunately FCKeditor's API is pretty janky about registering events for all editors and doesn't provide a similar functionality natively, so we have to rely on this "special" function FCKeditor_OnComplete to register any events after editors have loaded.

See http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API

I tried to search for alternatives but it seems that this is the only supported way of registering events on all instances. Considering that WYSIWYG is the primary module responsible for handling FCKeditor, I think it's okay that we claim this function for our own use.

Comments

sun’s picture

Man, I should work less on core, more on my modules. How could I miss this fine issue?

I'll point TwoD to this issue (you can most often also ping him in IRC), since he spent *a lot* of time with implementing FCKeditor support.

twod’s picture

StatusFileSize
new1 KB

Hmmm, I should have looked closer at the TinyMCE implementation, completely missed that variable. Good catch quicksketch!

I agree with quicksketch, FCKeditor_OnComplete() should not be needed by anything else when using Wysiwyg API. Even Wysiwyg plugins should not need it as they aren't supposed to know which editor is active, so if they rely on that callback they're doing it wrong.

However, we don't actually need to use that callback to get the event handler in there.
Event handlers can be attached in a custom configuration file (fckeditor.config.js in our case). The code in that file gets executed while the editor instance is loading, before FCKeditor_OnComplete() is called, so the handler is guaranteed to be ready even before plugins are loaded.

To keep that config file as clean and generic as possible for different versions of FCKeditor, we call Drupal.wysiwyg.editor.instance.fckeditor.init() from that config file and pass it the "editor area instance" (the FCKeditor iframe's window object) as instance.
instance.FCK.Events will then be the equivalent of editorInstance.Events in the OnComplete callback.

quicksketch’s picture

This does look like a better approach, but I can't get it working at all. On my local using the latest CVS WYSIWYG HEAD code, it seems like Drupal.wysiwyg.editor.instance.fckeditor.init() doesn't ever get called at all, so this addition has no effect. Checking the Firebug console, does the Drupal.wysiwyg.activeId value change for you when switching between multiple editors on the same page?

twod’s picture

Yes the value changes for me, but it does not appear to be working if you just type Drupal.wysiwyg.activeId into the Firebug watch list. But if you run alert(Drupal.wysiwyg.activeId) in the console (or type javascript:alert(Drupal.wysiwyg.activeId) in the address bar) you should see the correct id. And of course you should also see it change if you put a breakpoint around there.

Now that I think about it a bit more, there is actually one case in which init() isn't called, and that's if you use the default settings for FCKeditor. The init() method must be called from the custom config file like I said before, but the custom config file is not loaded unless needed (which it usually is since people tend to want to change at least one setting/plugin/button). Not calling init works just fine in current HEAD as "all" it does is attach the Data Processor used by the Wysiwyg plugins. If there are no Wysiwyg plugins, the Data Processor is not needed.

sun’s picture

Damn situation. Looks like we need to invoke our custom initialization for the default configuration, too.

quicksketch’s picture

Ah, that's definitely my situation (I don't actually *use* FCKeditor, just test it). I was using the default configuration with no changes whatsoever.

itowler’s picture

I would love to use the imagefield / imagecache along with Fckeditor, but I am unsure of how to apply this patch.

I have downloaded and installed the Filefield insert module. but again, I am not sure how to apply this patch.. could someone please help me out here...

ian

twod’s picture

@itower This patch is made against the Wysiwyg API module and should thus be applied at the wysiwyg folder. See http://drupal.org/patch/apply for more detailed info.

I am not sure if this affects anything related to how FCKeditor works together with imagefield / imagecache, but if your problem involves Wysiwyg API being unaware of which field is actually active it might help.

(Btw, see the note about default settings in #4 if this appears to still not work.)

itowler’s picture

TwoD,

thanks for the help..... I had not caught that.... I have installed the WYSIWYG API and the tinymce via WYSIWYG, and everything is mostly working.... but I still have 2 issues...

1. I am using imagecache, and the imagefield image is supposed to link to the full size image and be displayed with thickbox. This works find when the image is below the body, and not part of it, but when it in the body the link gets stripped out for some reason... Any ideas?

2. How do I get the text in the body to "wrap" around the image once it is inserted into the body....(with fckeditor standalone, all you had to do was go to the image settings and "image align" right or left and the text would wrap).

Thanks for the work on this....

This module will be a godsend if I can get it to work the way I want it to..

quicksketch’s picture

Assigned: quicksketch » Unassigned
Status: Needs review » Needs work

itowler, please stay on topic. This issue is for fixing FCKeditor. Since you're using tinyMCE this isn't the appropriate place at all for such questions. I'd suggest keeping it in your other issue #479310: Add support for add'l CCK Formatters (Lightbox2, etc.).

Anyway per sun in #5:

Damn situation. Looks like we need to invoke our custom initialization for the default configuration, too.

This patch needs some work. It's beyond my current understanding of WYSIWYG to make the changes necessary that sun and TwoD are suggesting.

sun’s picture

Status: Needs work » Needs review

Do we want to commit this patch as is and tackle the instance initialization of FCKeditor without custom configuration in a separate issue?

If I'm not mistaken, that would allow quicksketch to (basically) remove the notice from filefield_insert's project page, because most people will (hopefully) configure the editor before trying anything.

sun’s picture

Status: Needs review » Fixed

Committed TwoD's patch from #479514-2: FCKeditor: Add internal, native plugins, which somehow ended up in issue nirvana ;)

Summary: We always intialize FCKeditor now, even if we want to apply the default settings.

This means that quicksketch can remove the notice from filefield_insert's project page when the next alpha of Wysiwyg API is out.

quicksketch’s picture

Awesome, thanks sun! Maybe that also means it's time for a beta release of FileField Insert since we only have a dev version right now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.