import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckiecleanup.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKIECleanup Class: a generic class used as a tool to remove IE leaks.\r
22  */\r
23 \r
24 var     FCKIECleanup = function( attachWindow )\r
25 {\r
26         // If the attachWindow already have a cleanup object, just use that one.\r
27         if ( attachWindow._FCKCleanupObj )\r
28                 this.Items = attachWindow._FCKCleanupObj.Items ;\r
29         else\r
30         {\r
31                 this.Items = new Array() ;\r
32 \r
33                 attachWindow._FCKCleanupObj = this ;\r
34                 FCKTools.AddEventListenerEx( attachWindow, 'unload', FCKIECleanup_Cleanup ) ;\r
35 //              attachWindow.attachEvent( 'onunload', FCKIECleanup_Cleanup ) ;\r
36         }\r
37 }\r
38 \r
39 FCKIECleanup.prototype.AddItem = function( dirtyItem, cleanupFunction )\r
40 {\r
41         this.Items.push( [ dirtyItem, cleanupFunction ] ) ;\r
42 }\r
43 \r
44 function FCKIECleanup_Cleanup()\r
45 {\r
46         if ( !this._FCKCleanupObj || ( FCKConfig.MsWebBrowserControlCompat && !window.FCKUnloadFlag ) )\r
47                 return ;\r
48 \r
49         var aItems = this._FCKCleanupObj.Items ;\r
50 \r
51         while ( aItems.length > 0 )\r
52         {\r
53 \r
54                 // It is important to remove from the end to the beginning (pop()),\r
55                 // because of the order things get created in the editor. In the code,\r
56                 // elements in deeper position in the DOM are placed at the end of the\r
57                 // cleanup function, so we must cleanup then first, otherwise IE could\r
58                 // throw some crazy memory errors (IE bug).\r
59                 var oItem = aItems.pop() ;\r
60                 if ( oItem )\r
61                         oItem[1].call( oItem[0] ) ;\r
62         }\r
63 \r
64         this._FCKCleanupObj = null ;\r
65 \r
66         if ( CollectGarbage )\r
67                 CollectGarbage() ;\r
68 }\r