~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/_source/internals/fck_1_gecko.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ/*
 
2
 * FCKeditor - The text editor for internet
 
3
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 
4
 * 
 
5
 * Licensed under the terms of the GNU Lesser General Public License:
 
6
 *              http://www.opensource.org/licenses/lgpl-license.php
 
7
 * 
 
8
 * For further information visit:
 
9
 *              http://www.fckeditor.net/
 
10
 * 
 
11
 * "Support Open Source software. What about a donation today?"
 
12
 * 
 
13
 * File Name: fck_1_gecko.js
 
14
 *      This is the first part of the "FCK" object creation. This is the main
 
15
 *      object that represents an editor instance.
 
16
 *      (Gecko specific implementations)
 
17
 * 
 
18
 * File Authors:
 
19
 *              Frederico Caldeira Knabben (fredck@fckeditor.net)
 
20
 */
 
21
 
 
22
FCK.Description = "FCKeditor for Gecko Browsers" ;
 
23
 
 
24
FCK.InitializeBehaviors = function()
 
25
{
 
26
        /*
 
27
        window.document.onblur = function(e)
 
28
        {
 
29
                return FCK.Events.FireEvent( "OnBlur" ) ;
 
30
        }
 
31
 
 
32
        window.document.onfocus = function()
 
33
        {
 
34
                return FCK.Events.FireEvent( "OnFocus" ) ;
 
35
        }
 
36
        */
 
37
 
 
38
        // Enable table borders visibility.
 
39
        if ( FCKConfig.ShowBorders ) 
 
40
        {
 
41
                var oStyle = FCKTools.AppendStyleSheet( this.EditorDocument, FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css' ) ;
 
42
                oStyle.setAttribute( '_fcktemp', 'true' ) ;
 
43
        }
 
44
 
 
45
        // Disable Right-Click
 
46
        var oOnContextMenu = function( e )
 
47
        {
 
48
                e.preventDefault() ;
 
49
                FCK.ShowContextMenu( e.clientX, e.clientY ) ;
 
50
        }
 
51
        this.EditorDocument.addEventListener( 'contextmenu', oOnContextMenu, true ) ;
 
52
 
 
53
        // Handle pasting operations.
 
54
        var oOnKeyDown = function( e )
 
55
        {
 
56
 
 
57
                // START iCM Modifications
 
58
                /*
 
59
                // Need to amend carriage return key handling so inserts block element tags rather than BR all the time
 
60
                if ( e.which == 13 && !e.shiftKey && !e.ctrlKey && !e.altKey && !FCKConfig.UseBROnCarriageReturn && !FCK.Events.FireEvent( "OnEnter" ) )
 
61
                {
 
62
                        e.preventDefault() ;
 
63
                        e.stopPropagation() ;
 
64
                }
 
65
                // Amend backspace handling so correctly removes empty block elements i.e. those block elements containing nothing or
 
66
                // just the bogus BR node
 
67
                if ( e.which == 8 && !e.shiftKey && !e.ctrlKey && !e.altKey && !FCKConfig.UseBROnCarriageReturn && !FCK.Events.FireEvent( "OnBackSpace" ) )
 
68
                {
 
69
                        e.preventDefault() ;
 
70
                        e.stopPropagation() ;
 
71
                }
 
72
                */
 
73
                // END iCM Modifications
 
74
 
 
75
                var bPrevent ;
 
76
 
 
77
                if ( e.ctrlKey && !e.shiftKey && !e.altKey )
 
78
                {
 
79
                        switch ( e.which ) 
 
80
                        {
 
81
                                case 66 :       // B
 
82
                                case 98 :       // b
 
83
                                        FCK.ExecuteNamedCommand( 'bold' ) ; bPrevent = true ;
 
84
                                        break;
 
85
                                case 105 :      // i
 
86
                                case 73 :       // I
 
87
                                        FCK.ExecuteNamedCommand( 'italic' ) ; bPrevent = true ;
 
88
                                        break;
 
89
                                case 117 :      // u
 
90
                                case 85 :       // U
 
91
                                        FCK.ExecuteNamedCommand( 'underline' ) ; bPrevent = true ;
 
92
                                        break;
 
93
                                case 86 :       // V
 
94
                                case 118 :      // v
 
95
                                        bPrevent = ( FCK.Status != FCK_STATUS_COMPLETE || !FCK.Events.FireEvent( "OnPaste" ) ) ;
 
96
                                        break ;
 
97
                        }
 
98
                }
 
99
                else if ( e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode == 45 )    // SHIFT + <INS>
 
100
                        bPrevent = ( FCK.Status != FCK_STATUS_COMPLETE || !FCK.Events.FireEvent( "OnPaste" ) ) ;
 
101
                
 
102
                if ( bPrevent ) 
 
103
                {
 
104
                        e.preventDefault() ;
 
105
                        e.stopPropagation() ;
 
106
                }
 
107
        }
 
108
        this.EditorDocument.addEventListener( 'keypress', oOnKeyDown, true ) ;
 
109
 
 
110
        this.ExecOnSelectionChange = function()
 
111
        {
 
112
                FCK.Events.FireEvent( "OnSelectionChange" ) ;
 
113
        }
 
114
 
 
115
        this.ExecOnSelectionChangeTimer = function()
 
116
        {
 
117
                if ( FCK.LastOnChangeTimer )
 
118
                        window.clearTimeout( FCK.LastOnChangeTimer ) ;
 
119
 
 
120
                FCK.LastOnChangeTimer = window.setTimeout( FCK.ExecOnSelectionChange, 100 ) ;
 
121
        }
 
122
 
 
123
        this.EditorDocument.addEventListener( 'mouseup', this.ExecOnSelectionChange, false ) ;
 
124
 
 
125
        // On Gecko, firing the "OnSelectionChange" event on every key press started to be too much
 
126
        // slow. So, a timer has been implemented to solve performance issues when tipying to quickly.
 
127
        this.EditorDocument.addEventListener( 'keyup', this.ExecOnSelectionChangeTimer, false ) ;
 
128
 
 
129
        this._DblClickListener = function( e )
 
130
        {
 
131
                FCK.OnDoubleClick( e.target ) ;
 
132
                e.stopPropagation() ;
 
133
        }
 
134
        this.EditorDocument.addEventListener( 'dblclick', this._DblClickListener, true ) ;
 
135
 
 
136
        this._OnLoad = function()
 
137
        {
 
138
                if ( this._FCK_HTML )
 
139
                {
 
140
                        this.document.body.innerHTML = this._FCK_HTML ;
 
141
                        this._FCK_HTML = null ;
 
142
                        
 
143
                        if ( !FCK_StartupValue )
 
144
                                FCK.ResetIsDirty() ;
 
145
                }
 
146
        }
 
147
        this.EditorWindow.addEventListener( 'load', this._OnLoad, true ) ;
 
148
 
 
149
//      var oEditorWindow_OnUnload = function()
 
150
//      {
 
151
//              FCK.EditorWindow.location = 'fckblank.html' ;
 
152
//      }
 
153
//      this.EditorWindow.addEventListener( 'unload', oEditorWindow_OnUnload, true ) ;
 
154
 
 
155
//      var oEditorWindow_OnFocus = function()
 
156
//      {
 
157
//              FCK.MakeEditable() ;
 
158
//      }
 
159
//      this.EditorWindow.addEventListener( 'focus', oEditorWindow_OnFocus, true ) ;
 
160
}
 
161
 
 
162
FCK.MakeEditable = function()
 
163
{
 
164
        try 
 
165
        {
 
166
                FCK.EditorDocument.designMode = 'on' ;
 
167
 
 
168
                // Tell Gecko to use or not the <SPAN> tag for the bold, italic and underline.
 
169
                FCK.EditorDocument.execCommand( 'useCSS', false, !FCKConfig.GeckoUseSPAN ) ;
 
170
 
 
171
                // Analysing Firefox 1.5 source code, it seams that there is support for a 
 
172
                // "insertBrOnReturn" command. Applying it gives no error, but it doesn't 
 
173
                // gives the same behavior that you have with IE. It works only if you are
 
174
                // already inside a paragraph and it doesn't render correctly in the first enter.
 
175
                // FCK.EditorDocument.execCommand( 'insertBrOnReturn', false, false ) ;
 
176
                
 
177
                // Tell Gecko (Firefox 1.5+) to enable or not live resizing of objects (by Alfonso Martinez)
 
178
                FCK.EditorDocument.execCommand( 'enableObjectResizing', false, !FCKConfig.DisableImageHandles ) ;
 
179
                
 
180
                // Disable the standard table editing features of Firefox.
 
181
                FCK.EditorDocument.execCommand( 'enableInlineTableEditing', false, !FCKConfig.DisableTableHandles ) ;
 
182
        }
 
183
        catch (e) {}
 
184
}
 
185
 
 
186
FCK.Focus = function()
 
187
{
 
188
        try
 
189
        {
 
190
//              window.focus() ;
 
191
                FCK.EditorWindow.focus() ;
 
192
        }
 
193
        catch(e) {}
 
194
}
 
195
 
 
196
// @Packager.Compactor.Remove.Start
 
197
if ( FCKBrowserInfo.IsSafari )
 
198
{
 
199
FCK.SetHTML = function( html, forceWYSIWYG )
 
200
{
 
201
        if( window.console ) window.console.log( 'FCK.SetHTML()' ) ;    // @Packager.Compactor.RemoveLine
 
202
 
 
203
        sHtml =
 
204
                FCKConfig.DocType +
 
205
                '<html dir="' + FCKConfig.ContentLangDirection + '">' +
 
206
                '<head><title></title>' +
 
207
                '<link href="' + FCKConfig.EditorAreaCSS + '" rel="stylesheet" type="text/css" />' +
 
208
                '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
209
 
 
210
//      sHtml += FCK.TempBaseTag ;
 
211
        sHtml += '</head><body>' + html  + '</body></html>' ;
 
212
        
 
213
        this.EditorDocument.open() ;
 
214
        this.EditorDocument.write( sHtml ) ;
 
215
        this.EditorDocument.close() ;
 
216
 
 
217
//      this.InitializeBehaviors() ;
 
218
        
 
219
//      FCK.MakeEditable() ;
 
220
        FCK.EditorDocument.designMode = 'on' ;
 
221
        FCK.OnAfterSetHTML() ;
 
222
}
 
223
}
 
224
else
 
225
{
 
226
// @Packager.Compactor.Remove.End
 
227
FCK.SetHTML = function( html, forceWYSIWYG )
 
228
{
 
229
        // Firefox can't handle correctly the editing of the STRONG and EM tags. 
 
230
        // We must replace them with B and I.
 
231
        html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ;
 
232
        html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ;
 
233
        html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
 
234
        html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
 
235
 
 
236
        if ( forceWYSIWYG || FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
237
        {
 
238
                html = FCKConfig.ProtectedSource.Protect( html ) ;
 
239
                html = FCK.ProtectUrls( html ) ;
 
240
 
 
241
                // Gecko has a lot of bugs mainly when handling editing features.
 
242
                // To avoid an Aplication Exception (that closes the browser!) we
 
243
                // must first write the <HTML> contents with an empty body, and
 
244
                // then insert the body contents.
 
245
                // (Oh yes... it took me a lot of time to find out this workaround)
 
246
 
 
247
                if ( FCKConfig.FullPage && FCKRegexLib.BodyContents.test( html ) )
 
248
                {
 
249
                        // Add the <BASE> tag to the input HTML.
 
250
                        if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) )
 
251
                                html = html.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
 
252
 
 
253
                        html = html.replace( FCKRegexLib.HeadCloser, '<link href="' + FCKConfig.BasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" /></head>' ) ;
 
254
 
 
255
                        // Extract the BODY contents from the html.
 
256
                        var oMatch              = html.match( FCKRegexLib.BodyContents ) ;
 
257
                        var sOpener             = oMatch[1] ;   // This is the HTML until the <body...> tag, inclusive.
 
258
                        var sContents   = oMatch[2] ;   // This is the BODY tag contents.
 
259
                        var sCloser             = oMatch[3] ;   // This is the HTML from the </body> tag, inclusive.
 
260
 
 
261
                        var sHtml = sOpener + '&nbsp;' + sCloser ;
 
262
 
 
263
/*
 
264
                        if ( !this._Initialized )
 
265
                        {
 
266
                                FCK.EditorDocument.designMode = "on" ;
 
267
 
 
268
                                // Tell Gecko to use or not the <SPAN> tag for the bold, italic and underline.
 
269
                                FCK.EditorDocument.execCommand( "useCSS", false, !FCKConfig.GeckoUseSPAN ) ;
 
270
 
 
271
                                this._Initialized = true ;
 
272
                        }
 
273
*/
 
274
                        FCK.MakeEditable() ;
 
275
 
 
276
                        this.EditorDocument.open() ;
 
277
                        this.EditorDocument.write( sHtml ) ;
 
278
                        this.EditorDocument.close() ;
 
279
 
 
280
                        if ( this.EditorDocument.body )
 
281
                                this.EditorDocument.body.innerHTML = sContents ;
 
282
                        else
 
283
                                this.EditorWindow._FCK_HTML = sContents ;
 
284
 
 
285
                        this.InitializeBehaviors() ;
 
286
                }
 
287
                else
 
288
                {
 
289
                        /* TODO: Wait stable and remove it.
 
290
                        sHtml =
 
291
                                '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
 
292
                                '<html dir="' + FCKConfig.ContentLangDirection + '">' +
 
293
                                '<head><title></title>' +
 
294
                                '<link href="' + FCKConfig.EditorAreaCSS + '" rel="stylesheet" type="text/css" />' +
 
295
                                '<link href="' + FCKConfig.BasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
296
 
 
297
                        sHtml += FCK.TempBaseTag ;
 
298
 
 
299
                        sHtml += '</head><body>&nbsp;</body></html>' ;
 
300
                        */
 
301
 
 
302
                        if ( !this._Initialized )
 
303
                        {
 
304
                                this.EditorDocument.dir = FCKConfig.ContentLangDirection ;
 
305
 
 
306
                                var sHtml =
 
307
                                        '<title></title>' +
 
308
                                        '<link href="' + FCKConfig.EditorAreaCSS + '" rel="stylesheet" type="text/css" />' +
 
309
                                        '<link href="' + FCKConfig.BasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' +
 
310
                                        FCK.TempBaseTag ;
 
311
 
 
312
                                this.EditorDocument.getElementsByTagName("HEAD")[0].innerHTML = sHtml ;
 
313
 
 
314
                                this.InitializeBehaviors() ;
 
315
 
 
316
                                this._Initialized = true ;
 
317
                        }
 
318
 
 
319
                        // On Gecko we must disable editing before setting the BODY innerHTML.
 
320
//                      FCK.EditorDocument.designMode = 'off' ;
 
321
 
 
322
                        if ( html.length == 0 )
 
323
                                FCK.EditorDocument.body.innerHTML = GECKO_BOGUS ;
 
324
                        else if ( FCKRegexLib.EmptyParagraph.test( html ) )
 
325
                                FCK.EditorDocument.body.innerHTML = html.replace( FCKRegexLib.TagBody, '>' + GECKO_BOGUS + '<' ) ;
 
326
                        else
 
327
                                FCK.EditorDocument.body.innerHTML = html ;
 
328
                        
 
329
                        FCK.MakeEditable() ;
 
330
                }
 
331
 
 
332
                FCK.OnAfterSetHTML() ;
 
333
        }
 
334
        else
 
335
                document.getElementById('eSourceField').value = html ;
 
336
}
 
337
}       // @Packager.Compactor.RemoveLine
 
 
b'\\ No newline at end of file'