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 | <form id="form1"> |
---|
25 | <textarea id="editor1">CKEditor #1</textarea> |
---|
26 | </form> |
---|
27 | |
---|
28 | <form id="form2"> |
---|
29 | <textarea id="editor2">CKEditor #2</textarea> |
---|
30 | </form> |
---|
31 | |
---|
32 | <script type="text/javascript"> |
---|
33 | function runTests() { |
---|
34 | // Shouldn't create errors. |
---|
35 | createCKEditor(1); |
---|
36 | destroyCKEditor(1); |
---|
37 | |
---|
38 | // If the editor instance isn't a descendant of document.body, things break. |
---|
39 | createCKEditor(2); |
---|
40 | destroyCKEditor(2, function() { |
---|
41 | var new_el = document.createElement('div'); |
---|
42 | new_el.appendChild(document.getElementById('form2')); |
---|
43 | }); |
---|
44 | }; |
---|
45 | |
---|
46 | function createCKEditor(editor_id) { |
---|
47 | window['ckInstanceReady'+editor_id] = false; |
---|
48 | CKEDITOR.on('instanceReady', function(e) { |
---|
49 | window['ckInstanceReady'+editor_id] = true; |
---|
50 | }); |
---|
51 | CKEDITOR.replace(document.getElementById('editor'+editor_id)); |
---|
52 | }; |
---|
53 | |
---|
54 | function destroyCKEditor(editor_id, when_ready) { |
---|
55 | window['ckInstanceInterval'+editor_id] = setInterval(function() { |
---|
56 | if(window['ckInstanceReady'+editor_id]) { |
---|
57 | clearInterval(window['ckInstanceInterval'+editor_id]); |
---|
58 | |
---|
59 | if(typeof when_ready == 'function') |
---|
60 | when_ready(); |
---|
61 | |
---|
62 | var ckinstance = CKEDITOR.instances['editor'+editor_id], |
---|
63 | errors = document.getElementById('errors'+editor_id); |
---|
64 | |
---|
65 | try { |
---|
66 | ckinstance.destroy(true); |
---|
67 | errors.innerHTML += 'No Errors'; |
---|
68 | } catch(err) { |
---|
69 | //throw(err); |
---|
70 | window.errors = err; |
---|
71 | errors.innerHTML += err.message + '<br />' + err.stack; |
---|
72 | } |
---|
73 | } |
---|
74 | }, 500); |
---|
75 | } |
---|
76 | |
---|
77 | </script> |
---|
78 | |
---|
79 | </body> |
---|
80 | </html> |
---|