| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 3 | <head> |
|---|
| 4 | <title>destroy test</title> |
|---|
| 5 | |
|---|
| 6 | <script type="text/javascript" src="../ckeditor_source.js"></script> |
|---|
| 7 | </head> |
|---|
| 8 | <body> |
|---|
| 9 | <div> |
|---|
| 10 | <a href="javascript:;" onclick="runTests()">Start the tests</a> |
|---|
| 11 | </div> |
|---|
| 12 | <hr /> |
|---|
| 13 | |
|---|
| 14 | <div id="errors1"> |
|---|
| 15 | <b>Errors on #1:</b><br /> |
|---|
| 16 | </div> |
|---|
| 17 | <hr /> |
|---|
| 18 | |
|---|
| 19 | <div id="errors2"> |
|---|
| 20 | <b>Errors on #2:</b><br /> |
|---|
| 21 | </div> |
|---|
| 22 | <hr /> |
|---|
| 23 | |
|---|
| 24 | <div id="errors3"> |
|---|
| 25 | <b>Errors on #3:</b><br /> |
|---|
| 26 | </div> |
|---|
| 27 | <hr /> |
|---|
| 28 | |
|---|
| 29 | <form id="form1"> |
|---|
| 30 | <textarea id="editor1">CKEditor #1</textarea> |
|---|
| 31 | </form> |
|---|
| 32 | |
|---|
| 33 | <form id="form2"> |
|---|
| 34 | <textarea id="editor2">CKEditor #2</textarea> |
|---|
| 35 | </form> |
|---|
| 36 | |
|---|
| 37 | <form id="form3"> |
|---|
| 38 | <textarea id="editor3">CKEditor #3</textarea> |
|---|
| 39 | </form> |
|---|
| 40 | |
|---|
| 41 | <script type="text/javascript"> |
|---|
| 42 | function runTests() { |
|---|
| 43 | |
|---|
| 44 | // Shouldn't create errors. |
|---|
| 45 | createCKEditor(1); |
|---|
| 46 | destroyCKEditor(1); |
|---|
| 47 | |
|---|
| 48 | // If the editor instance isn't a descendant of document.body, things break. |
|---|
| 49 | createCKEditor(2); |
|---|
| 50 | destroyCKEditor(2, function() { |
|---|
| 51 | var new_el = document.createElement('div'); |
|---|
| 52 | new_el.appendChild(document.getElementById('form2')); |
|---|
| 53 | }); |
|---|
| 54 | |
|---|
| 55 | // Create an instance, and then replace the contents of the form |
|---|
| 56 | // and try to create a new one without calling destroy |
|---|
| 57 | CKEDITOR.on('instanceReady', function(e) { |
|---|
| 58 | if (e.editor.name!='editor3') |
|---|
| 59 | return; |
|---|
| 60 | |
|---|
| 61 | e.removeListener(); |
|---|
| 62 | window.setTimeout( function(){ |
|---|
| 63 | var errors = document.getElementById('errors3'); |
|---|
| 64 | try { |
|---|
| 65 | document.getElementById('form3').innerHTML = '<textarea id="editor3">new replaced textarea</textarea>'; |
|---|
| 66 | CKEDITOR.replace(document.getElementById('editor3')); |
|---|
| 67 | errors.innerHTML += 'No Errors'; |
|---|
| 68 | } catch(err) { |
|---|
| 69 | errors.innerHTML += err.message + '<br />' + err.stack; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | }, 100); |
|---|
| 73 | }); |
|---|
| 74 | |
|---|
| 75 | CKEDITOR.replace(document.getElementById('editor3')); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | function createCKEditor(editor_id) { |
|---|
| 81 | window['ckInstanceReady'+editor_id] = false; |
|---|
| 82 | CKEDITOR.on('instanceReady', function(e) { |
|---|
| 83 | window['ckInstanceReady'+editor_id] = true; |
|---|
| 84 | }); |
|---|
| 85 | CKEDITOR.replace(document.getElementById('editor'+editor_id)); |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | function destroyCKEditor(editor_id, when_ready) { |
|---|
| 89 | window['ckInstanceInterval'+editor_id] = setInterval(function() { |
|---|
| 90 | if(window['ckInstanceReady'+editor_id]) { |
|---|
| 91 | clearInterval(window['ckInstanceInterval'+editor_id]); |
|---|
| 92 | |
|---|
| 93 | if(typeof when_ready == 'function') |
|---|
| 94 | when_ready(); |
|---|
| 95 | |
|---|
| 96 | var ckinstance = CKEDITOR.instances['editor'+editor_id], |
|---|
| 97 | errors = document.getElementById('errors'+editor_id); |
|---|
| 98 | |
|---|
| 99 | try { |
|---|
| 100 | ckinstance.destroy(); |
|---|
| 101 | errors.innerHTML += 'No Errors'; |
|---|
| 102 | } catch(err) { |
|---|
| 103 | //throw(err); |
|---|
| 104 | window.errors = err; |
|---|
| 105 | errors.innerHTML += err.message + '<br />' + err.stack; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | }, 500); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | </script> |
|---|
| 112 | |
|---|
| 113 | </body> |
|---|
| 114 | </html> |
|---|