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.
Comments
Comment #1
eugene.ilyin CreditAttribution: eugene.ilyin commentedI 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.
Comment #2
eugene.ilyin CreditAttribution: eugene.ilyin commentedComment #3
IRuslan CreditAttribution: IRuslan commentedEarlier 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?
Comment #4
eugene.ilyin CreditAttribution: eugene.ilyin commentedI 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.
Comment #5
IRuslan CreditAttribution: IRuslan at DrupalJedi commentedHi,
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.
Comment #6
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commentedHello.
Thank you for your correction. I've checked it with ckeditor 4.5.4 and it works well.
Comment #8
IRuslan CreditAttribution: IRuslan at DrupalJedi commentedGreat. Pushed to dev.
Comment #9
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commentedStrange but this code wasn't applied in the last dev version :(
Comment #10
IRuslan CreditAttribution: IRuslan at DrupalJedi commentedRe-checked, all is ok.
Comment #11
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commentedSeems I was wrong. Thank you.