#1255: Javascript error in Firefox: FCK is not defined
-------------------------+--------------------------------------------------
Reporter: gboissiere | Owner:
Type: Bug | Status: new
Priority: Normal | Milestone:
Component: General | Version:
Resolution: | Keywords: Confirmed Firefox
-------------------------+--------------------------------------------------
Comment(by serializer):
This can now be worked around. The fix for #234 includes a patch against
FCKeditor which adds a "PreventSubmitHandler" config option. By setting
this to true, the _AttachFormSubmitToAPI() in fckeditorapi.js will be
stopped. This means you will have to provide your own onsubmit event to
called the UpdateLinkedField() on all your editors.
The permanent fix for this problem needs investigation of the
_AttachFormSubmitToAPI function. The code has existed since rev. 18
(FredCK). There's a Firefox-specific (or at least IE-excluded) block that
takes the '''first''' event that was (already) attached, swaps it for a
new one, and keeps a reference to the old one:
{{{
// Attach to the onsubmit event.
FCKTools.AddEventListener( oForm, 'submit',
FCK.UpdateLinkedField ) ;
// IE sees oForm.submit function as an 'object'.
if ( !oForm._FCKOriginalSubmit && ( typeof( oForm.submit )
== 'function' || ( !oForm.submit.tagName && !oForm.submit.length ) ) )
{
// Save the original submit.
oForm._FCKOriginalSubmit = oForm.submit ;
// Create our replacement for the submit.
oForm.submit = FCKeditorAPI._FormSubmit ;
}
}}}
As you can see, an event listener is added (this is performed in a
Firefox-specific way by fck_gecko).
THEN, the submit event (with handlers to FCK attached) is stored in
_FCKOriginalSubmit and a '''new''' submit handler is introduced:
FCKeditorAPI._FormSubmit.
That handler is defined in a eval at the beginning of fckeditorapi.js:
{{{
'_FormSubmit : function()' +
'{' +
'for ( var name in
FCKeditorAPI.Instances )' +
'{' +
'var oEditor =
FCKeditorAPI.Instances[ name ] ;' +
'if (
oEditor.GetParentForm && oEditor.GetParentForm() == this )' +
'oEditor.UpdateLinkedField() ;' +
'}' +
'this._FCKOriginalSubmit() ;' +
'},' +
}}}
So:
* Each FCK's UpdateLinkedField method is attached as an event listener to
form.submit
* form.submit is stashed away in _FCKOriginalSubmit
* FCKeditorAPI._FormSubmit replaces the form.submit
* FCKeditorAPI._FormSubmit eventually runs, and first calls
UpdateLinkedField on every editor instance that exists
* THEN calls _FCKOriginalSubmit which is itself an UpdateLinkedField!
So, even with just one instance on a page, UpdateLinkedField is actually
getting called twice because the events have been nested.
Furthermore, if we introduce additional editor instances, they will
attempt to add further event listeners to the form.submit. This time since
_FCKOriginalSubmit already exists, the event swapping will not occur - due
to the if ( !oForm._FCKOriginalSubmit [...] ). BUT it's possible that 3rd-
party Javascript frameworks could be performing their own manipulation of
form.submit and even the form object itself ... so at the stage where we
are several AJAX updates down the line, and multiple instances of
FCKeditor have been created and destroyed, who knows what will be
happening... Also since form.submit is no longer the original event, but
is now FCKeditorAPI._FormSubmit, I'm not sure if the AddEventListener will
still behave as expected.
Now, the FCKeditorAPI._FormSubmit method is probably better, since it's
just one handler that needs attaching which will update all instances, as
opposed to using AddEventListener to attach an event handler for each and
every instance.
The notes on revision 18 mention a SourceForge BUG-1610790:
https://sourceforge.net/tracker/?func=detail&atid=543653&aid=1610790&group_id=75348
..But I can't view that URL because it's private - so it's not clear
exactly what that code's meant to be doing! I think the reason this bug is
Firefox-specific is because of the IE 'object' test.
Really, I'm not sure why the additional event manipulation is happening.
Is there a reason why the FCKTools.AddEventListener call isn't enough?
--
Ticket URL: <http://dev.fckeditor.net/ticket/1255#comment:7>
FCKeditor <http://www.fckeditor.net>
The text editor for Internet
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
FCKeditor-Trac mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fckeditor-trac