| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 3 | |
|---|
| 4 | <head> |
|---|
| 5 | |
|---|
| 6 | <script type="text/javascript"> |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | var instance = null; |
|---|
| 10 | |
|---|
| 11 | function loadScript() { |
|---|
| 12 | if (!window.CKEDITOR || window.CKEDITOR == 'undefined') { |
|---|
| 13 | /* Replace URL to your ckeditor.js file */ |
|---|
| 14 | getScript("ckeditor.js"); |
|---|
| 15 | |
|---|
| 16 | } |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | function getScript(url){ |
|---|
| 20 | var scriptTag = document.createElement("script"); |
|---|
| 21 | scriptTag.setAttribute("type", "text/javascript"); |
|---|
| 22 | scriptTag.setAttribute("src", url); |
|---|
| 23 | document.getElementsByTagName("head")[0].appendChild(scriptTag); |
|---|
| 24 | console.log('aaa'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | function checkIfRTELoaded() { |
|---|
| 28 | if (typeof(window.CKEDITOR) != 'undefined') { |
|---|
| 29 | if (window.CKEDITOR.status && |
|---|
| 30 | window.CKEDITOR.status != 'unloaded' && |
|---|
| 31 | window.CKEDITOR.status != 'loading') { |
|---|
| 32 | return true; |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | return false; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | function destroy() { |
|---|
| 39 | if (instance) |
|---|
| 40 | instance.destroy(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function newEditor(){ |
|---|
| 44 | if (!this.checkIfRTELoaded()) { |
|---|
| 45 | setTimeout(newEditor, 400); |
|---|
| 46 | return; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | instance = CKEDITOR.appendTo( 'div1', |
|---|
| 50 | { |
|---|
| 51 | on : |
|---|
| 52 | { |
|---|
| 53 | instanceReady : function( ev ) |
|---|
| 54 | { |
|---|
| 55 | ev.editor.on( 'contentDom', function( evt ) |
|---|
| 56 | { |
|---|
| 57 | evt.removeListener(); |
|---|
| 58 | ev.editor.resetDirty(); |
|---|
| 59 | ev.editor.resetUndo(); |
|---|
| 60 | }); |
|---|
| 61 | ev.editor.setData( '<div><h1>Hello<\/h1><\/div>' ); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | ); |
|---|
| 66 | } |
|---|
| 67 | </script> |
|---|
| 68 | </head> |
|---|
| 69 | <body > |
|---|
| 70 | <div id="Test Description"> |
|---|
| 71 | This test case loads the editor "on demand", meaning that the ckeditor script is added to the DOM only when the first instance of the |
|---|
| 72 | editor is required. <br /> |
|---|
| 73 | Loading the script is via a script inclusion into the head node of the document. Then the newEditor() method is called, polling until the |
|---|
| 74 | CKEDITOR object is loaded. After loading, the new instance is created. <br /> |
|---|
| 75 | The call fails to properly initialize the editor on first call (evidenced by lack of focus ability and no content), everytime in Firefox 3. <br /> |
|---|
| 76 | When the first instance is destroyed and another |
|---|
| 77 | one created, the editor is initialized properly. The problem occurs only on the first load. |
|---|
| 78 | </div> |
|---|
| 79 | |
|---|
| 80 | <hr /> |
|---|
| 81 | |
|---|
| 82 | <div id="buttons"> |
|---|
| 83 | <input type="button" onclick="return destroy();" value="Destroy Editor" /> |
|---|
| 84 | <input type="button" onclick="loadScript(); newEditor();" value="New Editor" /> |
|---|
| 85 | </div> |
|---|
| 86 | <div id="div1"></div> |
|---|
| 87 | </body> |
|---|
| 88 | </html> |
|---|