I've got JS error when I'm trying to add asset into CKEditor 4.4.7.

Uncaught TypeError: undefined is not a function
in CKEDITOR.editable.CKEDITOR.tools.createClass.proto.insertElementIntoSelection

I've debugged it and I found that it happens due the CKEditor mechanics.
If in Drupal you have variable "theme_debug" which set as TRUE, then some comments will be added before and after your HTML code from template. When asset loaded by AJAX to has been inserted into CKEditor, HTML code of the asset will contain these special comments. CKEditor will take first node from given HTML as a wrapper, but if it will be not HTML tag you will get an error. Because CKEditor will try do call method .getRanges from it.

I loose some time to debug this situation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eugene.ilyin’s picture

I prepared patch to solve this problem. I don't think that it will happens often but we should avoid JS errors when debug mode is enabled.

eugene.ilyin’s picture

Status: Active » Needs review
IRuslan’s picture

Status: Needs review » Needs work

Earlier we had already similar problem with spaces at the beginning of html content.
I think we need to find out the initial reason of problem with CKEditor — why it's broken with some types of content at the beginning of html string?

eugene.ilyin’s picture

Status: Needs work » Needs review
FileSize
1.42 KB

I tried to find the better solution and I propose to don't create and element but insert response of ajax request as html into editor. It works for responses with text outside of html tags.

IRuslan’s picture

Hi,

i've closely reviewed behavior after applying of your patch and there are two problems:
1. Not all usages of insertAssetInEditor were corrected
2. Because insertHtml behavior different from insertElenent — editor selection is not properly set up after call. Because of this if will insert two assets without touching selection/focus — second insertion will fail — insertHtml does not set up proper selection after call.
See attached patch.

If someone able to test in on more recent versions of CKEditor i'm ready to push it to dev.

eugene.ilyin’s picture

Status: Needs review » Reviewed & tested by the community

Hello.

Thank you for your correction. I've checked it with ckeditor 4.5.4 and it works well.

  • IRuslan committed 6ae2185 on 7.x-1.x
    Issue #2513960 by eugene.ilyin, IRuslan: Trouble when I'm trying to add...
IRuslan’s picture

Status: Reviewed & tested by the community » Fixed

Great. Pushed to dev.

eugene.ilyin’s picture

Strange but this code wasn't applied in the last dev version :(

IRuslan’s picture

Re-checked, all is ok.

eugene.ilyin’s picture

Seems I was wrong. Thank you.

Status: Fixed » Closed (fixed)

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