Updated for 1.9.2
[freeside.git] / httemplate / elements / fckeditor / editor / js / fckadobeair.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2010 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  * Compatibility code for Adobe AIR.\r
22  */\r
23 \r
24 if ( FCKBrowserInfo.IsAIR )\r
25 {\r
26         var FCKAdobeAIR = (function()\r
27         {\r
28                 /*\r
29                  * ### Private functions.\r
30                  */\r
31 \r
32                 var getDocumentHead = function( doc )\r
33                 {\r
34                         var head ;\r
35                         var heads = doc.getElementsByTagName( 'head' ) ;\r
36 \r
37                         if( heads && heads[0] )\r
38                                 head = heads[0] ;\r
39                         else\r
40                         {\r
41                                 head = doc.createElement( 'head' ) ;\r
42                                 doc.documentElement.insertBefore( head, doc.documentElement.firstChild ) ;\r
43                         }\r
44 \r
45                         return head ;\r
46                 } ;\r
47 \r
48                 /*\r
49                  * ### Public interface.\r
50                  */\r
51                 return {\r
52                         FCKeditorAPI_Evaluate : function( parentWindow, script )\r
53                         {\r
54                                 // TODO : This one doesn't work always. The parent window will\r
55                                 // point to an anonymous function in this window. If this\r
56                                 // window is destroyied the parent window will be pointing to\r
57                                 // an invalid reference.\r
58 \r
59                                 // Evaluate the script in this window.\r
60                                 eval( script ) ;\r
61 \r
62                                 // Point the FCKeditorAPI property of the parent window to the\r
63                                 // local reference.\r
64                                 parentWindow.FCKeditorAPI = window.FCKeditorAPI ;\r
65                         },\r
66 \r
67                         EditingArea_Start : function( doc, html )\r
68                         {\r
69                                 // Get the HTML for the <head>.\r
70                                 var headInnerHtml = html.match( /<head>([\s\S]*)<\/head>/i )[1] ;\r
71 \r
72                                 if ( headInnerHtml && headInnerHtml.length > 0 )\r
73                                 {\r
74                                         // Inject the <head> HTML inside a <div>.\r
75                                         // Do that before getDocumentHead because WebKit moves\r
76                                         // <link css> elements to the <head> at this point.\r
77                                         var div = doc.createElement( 'div' ) ;\r
78                                         div.innerHTML = headInnerHtml ;\r
79 \r
80                                         // Move the <div> nodes to <head>.\r
81                                         FCKDomTools.MoveChildren( div, getDocumentHead( doc ) ) ;\r
82                                 }\r
83 \r
84                                 doc.body.innerHTML = html.match( /<body>([\s\S]*)<\/body>/i )[1] ;\r
85 \r
86                                 //prevent clicking on hyperlinks and navigating away\r
87                                 doc.addEventListener('click', function( ev )\r
88                                         {\r
89                                                 ev.preventDefault() ;\r
90                                                 ev.stopPropagation() ;\r
91                                         }, true ) ;\r
92                         },\r
93 \r
94                         Panel_Contructor : function( doc, baseLocation )\r
95                         {\r
96                                 var head = getDocumentHead( doc ) ;\r
97 \r
98                                 // Set the <base> href.\r
99                                 head.appendChild( doc.createElement('base') ).href = baseLocation ;\r
100 \r
101                                 doc.body.style.margin   = '0px' ;\r
102                                 doc.body.style.padding  = '0px' ;\r
103                         },\r
104 \r
105                         ToolbarSet_GetOutElement : function( win, outMatch )\r
106                         {\r
107                                 var toolbarTarget = win.parent ;\r
108 \r
109                                 var targetWindowParts = outMatch[1].split( '.' ) ;\r
110                                 while ( targetWindowParts.length > 0 )\r
111                                 {\r
112                                         var part = targetWindowParts.shift() ;\r
113                                         if ( part.length > 0 )\r
114                                                 toolbarTarget = toolbarTarget[ part ] ;\r
115                                 }\r
116 \r
117                                 toolbarTarget = toolbarTarget.document.getElementById( outMatch[2] ) ;\r
118                         },\r
119 \r
120                         ToolbarSet_InitOutFrame : function( doc )\r
121                         {\r
122                                 var head = getDocumentHead( doc ) ;\r
123 \r
124                                 head.appendChild( doc.createElement('base') ).href = window.document.location ;\r
125 \r
126                                 var targetWindow = doc.defaultView;\r
127 \r
128                                 targetWindow.adjust = function()\r
129                                 {\r
130                                         targetWindow.frameElement.height = doc.body.scrollHeight;\r
131                                 } ;\r
132 \r
133                                 targetWindow.onresize = targetWindow.adjust ;\r
134                                 targetWindow.setTimeout( targetWindow.adjust, 0 ) ;\r
135 \r
136                                 doc.body.style.overflow = 'hidden';\r
137                                 doc.body.innerHTML = document.getElementById( 'xToolbarSpace' ).innerHTML ;\r
138                         }\r
139                 } ;\r
140         })();\r
141 \r
142         /*\r
143          * ### Overrides\r
144          */\r
145         ( function()\r
146         {\r
147                 // Save references for override reuse.\r
148                 var _Original_FCKPanel_Window_OnFocus   = FCKPanel_Window_OnFocus ;\r
149                 var _Original_FCKPanel_Window_OnBlur    = FCKPanel_Window_OnBlur ;\r
150                 var _Original_FCK_StartEditor                   = FCK.StartEditor ;\r
151 \r
152                 FCKPanel_Window_OnFocus = function( e, panel )\r
153                 {\r
154                         // Call the original implementation.\r
155                         _Original_FCKPanel_Window_OnFocus.call( this, e, panel ) ;\r
156 \r
157                         if ( panel._focusTimer )\r
158                                 clearTimeout( panel._focusTimer ) ;\r
159                 }\r
160 \r
161                 FCKPanel_Window_OnBlur = function( e, panel )\r
162                 {\r
163                         // Delay the execution of the original function.\r
164                         panel._focusTimer = FCKTools.SetTimeout( _Original_FCKPanel_Window_OnBlur, 100, this, [ e, panel ] ) ;\r
165                 }\r
166 \r
167                 FCK.StartEditor = function()\r
168                 {\r
169                         // Force pointing to the CSS files instead of using the inline CSS cached styles.\r
170                         window.FCK_InternalCSS                  = FCKConfig.BasePath + 'css/fck_internal.css' ;\r
171                         window.FCK_ShowTableBordersCSS  = FCKConfig.BasePath + 'css/fck_showtableborders_gecko.css' ;\r
172 \r
173                         _Original_FCK_StartEditor.apply( this, arguments ) ;\r
174                 }\r
175         })();\r
176 }\r