I have developed my own custom non-jQuery ajax solution for building web applications. Recently, I encountered compatibility issues with IE9 while using TinyMCE, so I am considering switching to CKeditor.
The editable content is contained within a div structured like this:
<div id='content'>
<div id='editable' contenteditable='true'>
This is a page of dynamically loaded inline text triggered by clicking links throughout the site.
</div>
</div>
However, when I attempt to retrieve data from the editable content using the methods provided in the CKeditor documentation, I encounter an error.
I use this code:
CKEDITOR.instances.editable.getData();
This results in the following error:
Uncaught TypeError: Cannot call method 'getData' of undefined
It seems like the editor is not properly recognized in the DOM. I have tried iterating through all editors to find the editor name, but no name is found.
I have attempted the following:
for(var i in CKEDITOR.instances) {
alert(CKEDITOR.instances[i].name);
}
However, the alert returns blank, indicating that no name is associated with it.
Despite my efforts, I have been unsuccessful in getting the editable text to display a menu above it as shown in the Massive Inline Editing Example
Any help or guidance would be greatly appreciated.
Jason Silver
UPDATE:
Although I am admitting my lack of knowledge here, I had not encountered "contenteditable='true'" before. I assumed that since I could input text inline, the editor had been initialized somehow. Now, I am questioning whether the editor is actually applied to my div.
UPDATE 2:
Upon further investigation, I discovered that the div is not present when the script is initially executed. The editable div is injected into the DOM using AJAX. This raised the question of whether there is another command that needs to be executed to apply the editor to that div. To test this theory, I added a button to the page with an onclick event:
var editor, html = ''; config = {}; editor = CKEDITOR.appendTo('editable', config, html );
Unfortunately, this resulted in an error in Chrome:
Uncaught TypeError: Cannot call method 'equals' of undefined
+ CKEDITOR.tools.extend.getEditor ckeditor.js:101
b ckeditor.js:252
CKEDITOR.appendTo ckeditor.js:257
onclick www.pediatricjunction.com:410
Am I on the right track? Is there a different method to instruct CKEditor to apply the editor to a div programmatically?
UPDATE 3:
Thanks to a suggestion from @Reinmar, I decided to test a theory. To check if this would solve the issue, I added a button above the content editable div calling CKEDITOR.inlineAll() and inline('editable') respectively:
<input type='button' onclick=\"CKEDITOR.inlineAll();\" value='InlineAll'/>
<input type='button' onclick=\"CKEDITOR.inline('editable');\" value='Inline'/>
<input type='button' onclick=\"var editor = CKEDITOR.inline( document.getElementById( 'editable' ) );\" value='getElementById'/>
Unfortunately, Chrome returned the same error for all three buttons:
Uncaught TypeError: Cannot call method 'equals' of undefined ckeditor.js:101
+ CKEDITOR.tools.extend.getEditor ckeditor.js:101
CKEDITOR.inline ckeditor.js:249
CKEDITOR.inlineAll ckeditor.js:250
onclick
UPDATE 4:
Upon further investigation, I have identified that the issue is related to json2007.js, a script I use in combination with Real Simple History (RSH.js). These scripts are designed to manage ajax history to prevent the loss of AJAX page views as users navigate through the browser's history.
Here is a demo page: http://jsfiddle.net/jasonsilver/3CqPv/2/