2
* FCKeditor - The text editor for internet
3
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
* Licensed under the terms of the GNU Lesser General Public License:
6
* http://www.opensource.org/licenses/lgpl-license.php
8
* For further information visit:
9
* http://www.fckeditor.net/
11
* "Support Open Source software. What about a donation today?"
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)
19
* Frederico Caldeira Knabben (fredck@fckeditor.net)
22
FCK.Description = "FCKeditor for Gecko Browsers" ;
24
FCK.InitializeBehaviors = function()
27
window.document.onblur = function(e)
29
return FCK.Events.FireEvent( "OnBlur" ) ;
32
window.document.onfocus = function()
34
return FCK.Events.FireEvent( "OnFocus" ) ;
38
// Enable table borders visibility.
39
if ( FCKConfig.ShowBorders )
41
var oStyle = FCKTools.AppendStyleSheet( this.EditorDocument, FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css' ) ;
42
oStyle.setAttribute( '_fcktemp', 'true' ) ;
45
// Disable Right-Click
46
var oOnContextMenu = function( e )
49
FCK.ShowContextMenu( e.clientX, e.clientY ) ;
51
this.EditorDocument.addEventListener( 'contextmenu', oOnContextMenu, true ) ;
53
// Handle pasting operations.
54
var oOnKeyDown = function( e )
57
// START iCM Modifications
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" ) )
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" ) )
73
// END iCM Modifications
77
if ( e.ctrlKey && !e.shiftKey && !e.altKey )
83
FCK.ExecuteNamedCommand( 'bold' ) ; bPrevent = true ;
87
FCK.ExecuteNamedCommand( 'italic' ) ; bPrevent = true ;
91
FCK.ExecuteNamedCommand( 'underline' ) ; bPrevent = true ;
95
bPrevent = ( FCK.Status != FCK_STATUS_COMPLETE || !FCK.Events.FireEvent( "OnPaste" ) ) ;
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" ) ) ;
105
e.stopPropagation() ;
108
this.EditorDocument.addEventListener( 'keypress', oOnKeyDown, true ) ;
110
this.ExecOnSelectionChange = function()
112
FCK.Events.FireEvent( "OnSelectionChange" ) ;
115
this.ExecOnSelectionChangeTimer = function()
117
if ( FCK.LastOnChangeTimer )
118
window.clearTimeout( FCK.LastOnChangeTimer ) ;
120
FCK.LastOnChangeTimer = window.setTimeout( FCK.ExecOnSelectionChange, 100 ) ;
123
this.EditorDocument.addEventListener( 'mouseup', this.ExecOnSelectionChange, false ) ;
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 ) ;
129
this._DblClickListener = function( e )
131
FCK.OnDoubleClick( e.target ) ;
132
e.stopPropagation() ;
134
this.EditorDocument.addEventListener( 'dblclick', this._DblClickListener, true ) ;
136
this._OnLoad = function()
138
if ( this._FCK_HTML )
140
this.document.body.innerHTML = this._FCK_HTML ;
141
this._FCK_HTML = null ;
143
if ( !FCK_StartupValue )
147
this.EditorWindow.addEventListener( 'load', this._OnLoad, true ) ;
149
// var oEditorWindow_OnUnload = function()
151
// FCK.EditorWindow.location = 'fckblank.html' ;
153
// this.EditorWindow.addEventListener( 'unload', oEditorWindow_OnUnload, true ) ;
155
// var oEditorWindow_OnFocus = function()
157
// FCK.MakeEditable() ;
159
// this.EditorWindow.addEventListener( 'focus', oEditorWindow_OnFocus, true ) ;
162
FCK.MakeEditable = function()
166
FCK.EditorDocument.designMode = 'on' ;
168
// Tell Gecko to use or not the <SPAN> tag for the bold, italic and underline.
169
FCK.EditorDocument.execCommand( 'useCSS', false, !FCKConfig.GeckoUseSPAN ) ;
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 ) ;
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 ) ;
180
// Disable the standard table editing features of Firefox.
181
FCK.EditorDocument.execCommand( 'enableInlineTableEditing', false, !FCKConfig.DisableTableHandles ) ;
186
FCK.Focus = function()
191
FCK.EditorWindow.focus() ;
196
// @Packager.Compactor.Remove.Start
197
if ( FCKBrowserInfo.IsSafari )
199
FCK.SetHTML = function( html, forceWYSIWYG )
201
if( window.console ) window.console.log( 'FCK.SetHTML()' ) ; // @Packager.Compactor.RemoveLine
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" />' ;
210
// sHtml += FCK.TempBaseTag ;
211
sHtml += '</head><body>' + html + '</body></html>' ;
213
this.EditorDocument.open() ;
214
this.EditorDocument.write( sHtml ) ;
215
this.EditorDocument.close() ;
217
// this.InitializeBehaviors() ;
219
// FCK.MakeEditable() ;
220
FCK.EditorDocument.designMode = 'on' ;
221
FCK.OnAfterSetHTML() ;
226
// @Packager.Compactor.Remove.End
227
FCK.SetHTML = function( html, forceWYSIWYG )
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>' ) ;
236
if ( forceWYSIWYG || FCK.EditMode == FCK_EDITMODE_WYSIWYG )
238
html = FCKConfig.ProtectedSource.Protect( html ) ;
239
html = FCK.ProtectUrls( html ) ;
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)
247
if ( FCKConfig.FullPage && FCKRegexLib.BodyContents.test( html ) )
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 ) ;
253
html = html.replace( FCKRegexLib.HeadCloser, '<link href="' + FCKConfig.BasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" /></head>' ) ;
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.
261
var sHtml = sOpener + ' ' + sCloser ;
264
if ( !this._Initialized )
266
FCK.EditorDocument.designMode = "on" ;
268
// Tell Gecko to use or not the <SPAN> tag for the bold, italic and underline.
269
FCK.EditorDocument.execCommand( "useCSS", false, !FCKConfig.GeckoUseSPAN ) ;
271
this._Initialized = true ;
276
this.EditorDocument.open() ;
277
this.EditorDocument.write( sHtml ) ;
278
this.EditorDocument.close() ;
280
if ( this.EditorDocument.body )
281
this.EditorDocument.body.innerHTML = sContents ;
283
this.EditorWindow._FCK_HTML = sContents ;
285
this.InitializeBehaviors() ;
289
/* TODO: Wait stable and remove it.
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" />' ;
297
sHtml += FCK.TempBaseTag ;
299
sHtml += '</head><body> </body></html>' ;
302
if ( !this._Initialized )
304
this.EditorDocument.dir = FCKConfig.ContentLangDirection ;
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" />' +
312
this.EditorDocument.getElementsByTagName("HEAD")[0].innerHTML = sHtml ;
314
this.InitializeBehaviors() ;
316
this._Initialized = true ;
319
// On Gecko we must disable editing before setting the BODY innerHTML.
320
// FCK.EditorDocument.designMode = 'off' ;
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 + '<' ) ;
327
FCK.EditorDocument.body.innerHTML = html ;
332
FCK.OnAfterSetHTML() ;
335
document.getElementById('eSourceField').value = html ;
337
} // @Packager.Compactor.RemoveLine
b'\\ No newline at end of file'