1. Open a panel in admin mode
2. Open "Add content" dialog on a pane
3. Select "New custom content". Window with CKEditor loaded appears:
4. Close the window using either "Close window" control or by pressing "Cancel" button.
5. Repeat adding custom content. Now the window lacks CKEditor:
and error message appears in js console:

I use jQuery 1.8 provided by latest jQuery Update dev

Members fund testing for the Drupal project. Drupal Association Learn more


OnkelTem’s picture

After digging in CKEditor sources I found location where this error is triggered:

getFrameDocument : function()
			var $ = this.$;

				// In IE, with custom document.domain, it may happen that
				// the iframe is not yet available, resulting in "Access
				// Denied" for the following property access.
			catch ( e )
				// Trick to solve this issue, forcing the iframe to get ready
				// by simply setting its "src" property.
				$.src = $.src;

				// In IE6 though, the above is not enough, so we must pause the
				// execution for a while, giving it time to think.
				if ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 )
						'javascript:document.write("' +
							'<script>' +
								'window.setTimeout(' +
									'function(){window.close();}' +
									',50);' +
							'</script>")' );

			return $ && new CKEDITOR.dom.document( $.contentWindow.document );

$ variable has iframe object. But $.contentWindow is NULL. I have no idea why this happens.

jcisio’s picture

Title: "Uncaught TypeError: Cannot read property 'document' of null" error when adding custom content on a panel » "Uncaught TypeError: Cannot read property 'document' of null" error when edit custom content pane twice
OnkelTem’s picture

I found the reason. Making a patch atm.

OnkelTem’s picture

Status: Active » Needs review
1.15 KB

This patch adds reaction on the 'CToolsDetachBehaviors' which is triggered when you close Ctools modal form (where Custom content appears). It finds and kills appropriate CKEdtior instance and now it can be relaunched correctly many times.

But this event triggered only when you close modal form using "Close Window" control button (in the upper right corner of the window). When you press "Cancel" button, this even isn't triggered and instead — standard Drupal detach behavior hook is called which doesn't kill the instance when "trigger" parameter equals to "serialize" (which is the case when you click "Cancel" button).

As far as I understand the correct behavior would be to kill CKEditor instance if Cancel is pressed. But I haven't find the way to get the information whether a form was submitted using "Save" or "Cancel" button — it just not available in a detach handler (even if having form object in context parameter). So this vulgar patch most likely is wrong:

diff --git a/includes/ckeditor.utils.js b/includes/ckeditor.utils.js
index 0a2aee8..ccd7c89 100644
--- a/includes/ckeditor.utils.js
+++ b/includes/ckeditor.utils.js
@@ -333,9 +333,9 @@ window.CKEDITOR_BASEPATH = Drupal.settings.ckeditor.editor_path;
     function(context, settings, trigger){
       $(context).find("textarea.ckeditor-mod.ckeditor-processed").each(function () {
         var ta_id=$(this).attr("id");
-        if (CKEDITOR.instances[ta_id])
+        if (CKEDITOR.instances[ta_id]) {
-        if(trigger != 'serialize') {
+        //if(trigger != 'serialize') {
jcisio’s picture

I think the attached patch is a proper fix.

jcisio’s picture

$().trigger is blocking, so this one remote the unnecessary part.

OnkelTem’s picture

#5 doesn't work for me.

1) Add custom content
2) Close using Cancel
3) Add again —> no CKEditor loaded.

UPDATED. #6 won't work either.

jcisio’s picture

Did you clear cache?

OnkelTem’s picture

Yes, I did.

jcisio’s picture

Any error? Could it be reproduced with a vanilla Drupal + CKEditor + Panels install?

I tested #6 and had different confirmations that it worked, but custom content pane edition, and with custom CTools modal. So I think you have another problem.

OnkelTem’s picture

I have no clean setup, as and I'm on Drupal + CKEditor + Panels git verions.
I believe the reason why #6 doesn't work — it doesn't resolve the issue "trigger = serialize" as I described in #4.

jcisio’s picture

It's difficult to debug if we don't have your specific environment. I think I'll commit #6 BTW. The "serialize" event is not a problem, CKEditor is removed on the "unload" event.

OnkelTem’s picture

How comes its not a problem if CKeditor gets detach with trigger = serialize and not removing its instance? It is not unloaded. Or what is unload event?

Have you tried adding custom content, canceling it, then adding again without closing Add content dialog?

jcisio’s picture

Status: Needs review » Fixed

Ah ok. I only closed the modal then open it again, and it worked. I didn't try the Cancel button. I think it is a bug in CTools Page Manager not to fire an appropriate event. We can't remove the editor in the "serialize" event, to avoid reinitialisation of another editor. Try to file an issue in CTools queue. Because in fact, when you press Cancel, even the modal is not closed, its content is replaced with a different one via an AJAX request, so it should fire an event.

In wysiwyg module, the same thing happens http://drupalcode.org/project/wysiwyg.git/blob/refs/heads/7.x-2.x:/wysiw.... I'm marking this issue as fixed then (patch #6, which is a simplified version of your patch #4, has been committed as it fixes the Close button).

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.