Ticket #5441: ie_destroy_bug.html

File ie_destroy_bug.html, 4.3 KB (added by Marcos Wright Kuhns, 15 years ago)

An html file that can be used to reproduce the error in IE

Line 
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>CKEditor + Form + Google Chrome Mac bug</title>
5   
6    <script type="text/javascript">
7      CKEDITOR_BASEPATH = 'http://ckeditor.com/apps/ckeditor/3.2/';
8    </script>
9    <script type="text/javascript" src="http://ckeditor.com/apps/ckeditor/3.2/ckeditor.js?1269346523"></script>
10    <!--
11    <script type="text/javascript">
12      CKEDITOR_BASEPATH = 'http://localhost/javascripts/ckeditor_3.2/';
13    </script>
14    <script type="text/javascript" src="http://localhost/javascripts/ckeditor_3.2/ckeditor.js?1269378841"></script>
15    -->
16  </head>
17  <body>
18    <div>
19      <a href="javascript:;" onclick="patchThemeDestroy()">Patch CKEditor</a><br />
20      <a href="javascript:;" onclick="runTests()">Start the tests</a>
21    </div>
22    <hr />
23   
24    <div id="errors1">
25      <b>Errors on #1:</b><br />
26    </div>
27    <hr />
28   
29    <div id="errors2">
30      <b>Errors on #2:</b><br />
31    </div>
32    <hr />
33   
34    <form id="form1">
35      <textarea id="editor1">CKEditor #1</textarea>
36    </form>
37   
38    <form id="form2">
39      <textarea id="editor2">CKEditor #2</textarea>
40    </form>
41   
42    <script type="text/javascript">
43      function runTests() {
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     
56      function createCKEditor(editor_id) {
57        window['ckInstanceReady'+editor_id] = false;
58        CKEDITOR.on('instanceReady', function(e) {
59          window['ckInstanceReady'+editor_id] = true;
60        });
61        CKEDITOR.replace(document.getElementById('editor'+editor_id));
62      };
63     
64      function destroyCKEditor(editor_id, when_ready) {
65        window['ckInstanceInterval'+editor_id] = setInterval(function() {
66          if(window['ckInstanceReady'+editor_id]) {
67            clearInterval(window['ckInstanceInterval'+editor_id]);
68           
69            if(typeof when_ready == 'function')
70              when_ready();
71           
72            var ckinstance = CKEDITOR.instances['editor'+editor_id],
73              errors = document.getElementById('errors'+editor_id);
74
75            try {
76              ckinstance.destroy(true);
77              errors.innerHTML += 'No Errors';
78            } catch(err) {
79              //throw(err);
80              window.errors = err;
81              errors.innerHTML += err.message + '<br />' + err.stack;
82            }
83          }
84        }, 500);
85      }
86     
87      function patchThemeDestroy() {
88        CKEDITOR.themes.get('default').destroy = function( editor )
89                {
90                        var container = editor.container;
91     
92                        /*
93                         * IE BUG: Removing the editor DOM elements while the selection is inside
94                         * the editing area would break IE7/8's selection system. So we need to put
95                         * the selection back to the parent document without scrolling the window.
96                         * (#3812)
97                         */
98                        if ( CKEDITOR.env.ie )
99                        {
100                                container.setStyle( 'display', 'none' );
101     
102                                var $range = document.body.createTextRange(),
103                                  container_el = container.$,
104                                  in_body = false;
105     
106                                while (container_el = container_el.parentNode) {
107              if (container_el == document.body) in_body = true;
108            }
109     
110                                if(in_body)
111                                  $range.moveToElementText( container.$ );
112                                else
113                                  $range.moveToElementText( document.body );
114                                try
115                                {
116                                        // Putting the selection to a display:none element - this will certainly
117                                        // fail. But! We've just put the selection document back to the parent
118                                        // document without scrolling the window!
119                                        $range.select();
120                                }
121                                catch ( e ) {}
122                        }
123     
124                        if ( container )
125                                container.remove();
126     
127                        if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
128                        {
129                                editor.element.show();
130                                delete editor.element;
131                        }
132                };
133      };
134    </script>
135   
136  </body>
137</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy