2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Creation and initialization of the "FCK" object. This is the main
22
* object that represents an editor instance.
23
* (IE specific implementations)
26
FCK.Description = "FCKeditor for Internet Explorer 5.5+" ;
28
FCK._GetBehaviorsStyle = function()
30
if ( !FCK._BehaviorsStyle )
32
var sBasePath = FCKConfig.BasePath ;
33
var sTableBehavior = '' ;
36
// The behaviors should be pointed using the BasePath to avoid security
37
// errors when using a different BaseHref.
38
sStyle = '<style type="text/css" _fcktemp="true">' ;
40
if ( FCKConfig.ShowBorders )
41
sTableBehavior = 'url(' + sBasePath + 'css/behaviors/showtableborders.htc)' ;
43
// Disable resize handlers.
44
sStyle += 'INPUT,TEXTAREA,SELECT,.FCK__Anchor,.FCK__PageBreak,.FCK__InputHidden' ;
46
if ( FCKConfig.DisableObjectResizing )
49
sTableBehavior += ' url(' + sBasePath + 'css/behaviors/disablehandles.htc)' ;
52
sStyle += ' { behavior: url(' + sBasePath + 'css/behaviors/disablehandles.htc) ; }' ;
54
if ( sTableBehavior.length > 0 )
55
sStyle += 'TABLE { behavior: ' + sTableBehavior + ' ; }' ;
57
sStyle += '</style>' ;
58
FCK._BehaviorsStyle = sStyle ;
61
return FCK._BehaviorsStyle ;
64
function Doc_OnMouseUp()
66
if ( FCK.EditorWindow.event.srcElement.tagName == 'HTML' )
69
FCK.EditorWindow.event.cancelBubble = true ;
70
FCK.EditorWindow.event.returnValue = false ;
74
function Doc_OnPaste()
76
var body = FCK.EditorDocument.body ;
78
body.detachEvent( 'onpaste', Doc_OnPaste ) ;
80
var ret = FCK.Paste( !FCKConfig.ForcePasteAsPlainText && !FCKConfig.AutoDetectPasteFromWord ) ;
82
body.attachEvent( 'onpaste', Doc_OnPaste ) ;
87
function Doc_OnDblClick()
89
FCK.OnDoubleClick( FCK.EditorWindow.event.srcElement ) ;
90
FCK.EditorWindow.event.cancelBubble = true ;
93
function Doc_OnSelectionChange()
95
// Don't fire the event if no document is loaded.
96
if ( !FCK.IsSelectionChangeLocked && FCK.EditorDocument )
97
FCK.Events.FireEvent( "OnSelectionChange" ) ;
100
function Doc_OnDrop()
102
if ( FCK.MouseDownFlag )
104
FCK.MouseDownFlag = false ;
108
if ( FCKConfig.ForcePasteAsPlainText )
110
var evt = FCK.EditorWindow.event ;
112
if ( FCK._CheckIsPastingEnabled() || FCKConfig.ShowDropDialog )
113
FCK.PasteAsPlainText( evt.dataTransfer.getData( 'Text' ) ) ;
115
evt.returnValue = false ;
116
evt.cancelBubble = true ;
120
FCK.InitializeBehaviors = function( dontReturn )
122
// Set the focus to the editable area when clicking in the document area.
123
// TODO: The cursor must be positioned at the end.
124
this.EditorDocument.attachEvent( 'onmouseup', Doc_OnMouseUp ) ;
126
// Intercept pasting operations
127
this.EditorDocument.body.attachEvent( 'onpaste', Doc_OnPaste ) ;
129
// Intercept drop operations
130
this.EditorDocument.body.attachEvent( 'ondrop', Doc_OnDrop ) ;
132
// Reset the context menu.
133
FCK.ContextMenu._InnerContextMenu.AttachToElement( FCK.EditorDocument.body ) ;
135
this.EditorDocument.attachEvent("onkeydown", FCK._KeyDownListener ) ;
137
this.EditorDocument.attachEvent("ondblclick", Doc_OnDblClick ) ;
139
this.EditorDocument.attachEvent("onbeforedeactivate", function(){ FCKSelection.Save() ; } ) ;
141
// Catch cursor selection changes.
142
this.EditorDocument.attachEvent("onselectionchange", Doc_OnSelectionChange ) ;
144
FCKTools.AddEventListener( FCK.EditorDocument, 'mousedown', Doc_OnMouseDown ) ;
147
FCK.InsertHtml = function( html )
149
html = FCKConfig.ProtectedSource.Protect( html ) ;
150
html = FCK.ProtectEvents( html ) ;
151
html = FCK.ProtectUrls( html ) ;
152
html = FCK.ProtectTags( html ) ;
155
FCKSelection.Restore() ;
156
FCK.EditorWindow.focus() ;
158
FCKUndo.SaveUndoStep() ;
160
// Gets the actual selection.
161
var oSel = FCKSelection.GetSelection() ;
163
// Deletes the actual selection contents.
164
if ( oSel.type.toLowerCase() == 'control' )
167
// Using the following trick, any comment in the beginning of the HTML will
169
html = '<span id="__fakeFCKRemove__" style="display:none;">fakeFCKRemove</span>' + html ;
172
oSel.createRange().pasteHTML( html ) ;
174
// Remove the fake node
175
var fake = FCK.EditorDocument.getElementById('__fakeFCKRemove__') ;
176
// If the span is the only child of a node (so the inserted HTML is beyond that),
177
// remove also that parent that isn't needed. #1537
178
if (fake.parentNode.childNodes.length == 1)
179
fake = fake.parentNode ;
180
fake.removeNode( true ) ;
182
FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
184
// For some strange reason the SaveUndoStep() call doesn't activate the undo button at the first InsertHtml() call.
185
this.Events.FireEvent( "OnSelectionChange" ) ;
188
FCK.SetInnerHtml = function( html ) // IE Only
190
var oDoc = FCK.EditorDocument ;
191
// Using the following trick, any comment in the beginning of the HTML will
193
oDoc.body.innerHTML = '<div id="__fakeFCKRemove__"> </div>' + html ;
194
oDoc.getElementById('__fakeFCKRemove__').removeNode( true ) ;
197
function FCK_PreloadImages()
199
var oPreloader = new FCKImagePreloader() ;
201
// Add the configured images.
202
oPreloader.AddImages( FCKConfig.PreloadImages ) ;
204
// Add the skin icons strip.
205
oPreloader.AddImages( FCKConfig.SkinPath + 'fck_strip.gif' ) ;
207
oPreloader.OnComplete = LoadToolbarSetup ;
211
// Disable the context menu in the editor (outside the editing area).
212
function Document_OnContextMenu()
214
return ( event.srcElement._FCKShowContextMenu == true ) ;
216
document.oncontextmenu = Document_OnContextMenu ;
218
function FCK_Cleanup()
220
this.LinkedField = null ;
221
this.EditorWindow = null ;
222
this.EditorDocument = null ;
225
FCK._ExecPaste = function()
227
// As we call ExecuteNamedCommand('Paste'), it would enter in a loop. So, let's use a semaphore.
228
if ( FCK._PasteIsRunning )
231
if ( FCKConfig.ForcePasteAsPlainText )
233
FCK.PasteAsPlainText() ;
237
var sHTML = FCK._CheckIsPastingEnabled( true ) ;
239
if ( sHTML === false )
240
FCKTools.RunFunction( FCKDialog.OpenDialog, FCKDialog, ['FCKDialog_Paste', FCKLang.Paste, 'dialog/fck_paste.html', 400, 330, 'Security'] ) ;
243
if ( FCKConfig.AutoDetectPasteFromWord && sHTML.length > 0 )
245
var re = /<\w[^>]*(( class="?MsoNormal"?)|(="mso-))/gi ;
246
if ( re.test( sHTML ) )
248
if ( confirm( FCKLang.PasteWordConfirm ) )
250
FCK.PasteFromWord() ;
256
// Instead of inserting the retrieved HTML, let's leave the OS work for us,
257
// by calling FCK.ExecuteNamedCommand( 'Paste' ). It could give better results.
259
// Enable the semaphore to avoid a loop.
260
FCK._PasteIsRunning = true ;
262
FCK.ExecuteNamedCommand( 'Paste' ) ;
264
// Removes the semaphore.
265
delete FCK._PasteIsRunning ;
268
// Let's always make a custom implementation (return false), otherwise
269
// the new Keyboard Handler may conflict with this code, and the CTRL+V code
270
// could result in a simple "V" being pasted.
274
FCK.PasteAsPlainText = function( forceText )
276
if ( !FCK._CheckIsPastingEnabled() )
278
FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ;
282
// Get the data available in the clipboard in text format.
285
sText = clipboardData.getData("Text") ;
289
if ( sText && sText.length > 0 )
291
// Replace the carriage returns with <BR>
292
sText = FCKTools.HTMLEncode( sText ) ;
293
sText = FCKTools.ProcessLineBreaks( window, FCKConfig, sText ) ;
295
var closeTagIndex = sText.search( '</p>' ) ;
296
var startTagIndex = sText.search( '<p>' ) ;
298
if ( ( closeTagIndex != -1 && startTagIndex != -1 && closeTagIndex < startTagIndex )
299
|| ( closeTagIndex != -1 && startTagIndex == -1 ) )
301
var prefix = sText.substr( 0, closeTagIndex ) ;
302
sText = sText.substr( closeTagIndex + 4 ) ;
303
this.InsertHtml( prefix ) ;
306
// Insert the resulting data in the editor.
307
FCKUndo.SaveLocked = true ;
308
this.InsertHtml( sText ) ;
309
FCKUndo.SaveLocked = false ;
313
FCK._CheckIsPastingEnabled = function( returnContents )
315
// The following seams to be the only reliable way to check is script
316
// pasting operations are enabled in the security settings of IE6 and IE7.
317
// It adds a little bit of overhead to the check, but so far that's the
318
// only way, mainly because of IE7.
320
FCK._PasteIsEnabled = false ;
322
document.body.attachEvent( 'onpaste', FCK_CheckPasting_Listener ) ;
324
// The execCommand in GetClipboardHTML will fire the "onpaste", only if the
325
// security settings are enabled.
326
var oReturn = FCK.GetClipboardHTML() ;
328
document.body.detachEvent( 'onpaste', FCK_CheckPasting_Listener ) ;
330
if ( FCK._PasteIsEnabled )
332
if ( !returnContents )
338
delete FCK._PasteIsEnabled ;
343
function FCK_CheckPasting_Listener()
345
FCK._PasteIsEnabled = true ;
348
FCK.GetClipboardHTML = function()
350
var oDiv = document.getElementById( '___FCKHiddenDiv' ) ;
354
oDiv = document.createElement( 'DIV' ) ;
355
oDiv.id = '___FCKHiddenDiv' ;
357
var oDivStyle = oDiv.style ;
358
oDivStyle.position = 'absolute' ;
359
oDivStyle.visibility = oDivStyle.overflow = 'hidden' ;
360
oDivStyle.width = oDivStyle.height = 1 ;
362
document.body.appendChild( oDiv ) ;
365
oDiv.innerHTML = '' ;
367
var oTextRange = document.body.createTextRange() ;
368
oTextRange.moveToElementText( oDiv ) ;
369
oTextRange.execCommand( 'Paste' ) ;
371
var sData = oDiv.innerHTML ;
372
oDiv.innerHTML = '' ;
377
FCK.CreateLink = function( url, noUndo )
379
// Creates the array that will be returned. It contains one or more created links (see #220).
380
var aCreatedLinks = new Array() ;
381
var isControl = FCKSelection.GetType() == 'Control' ;
382
var selectedElement = isControl && FCKSelection.GetSelectedElement() ;
384
// Remove any existing link in the selection.
385
// IE BUG: Unlinking a floating control selection that is not inside a link
386
// will collapse the selection. (#3677)
387
if ( !( isControl && !FCKTools.GetElementAscensor( selectedElement, 'a' ) ) )
388
FCK.ExecuteNamedCommand( 'Unlink', null, false, !!noUndo ) ;
390
if ( url.length > 0 )
392
// If there are several images, and you try to link each one, all the images get inside the link:
393
// <img><img> -> <a><img></a><img> -> <a><img><img></a> due to the call to 'CreateLink' (bug in IE)
397
var oLink = this.EditorDocument.createElement( 'A' ) ;
400
// Get the selected object
401
var oControl = selectedElement ;
402
// Put the link just before the object
403
oControl.parentNode.insertBefore(oLink, oControl) ;
404
// Move the object inside the link
405
oControl.parentNode.removeChild( oControl ) ;
406
oLink.appendChild( oControl ) ;
411
// Generate a temporary name for the link.
412
var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ;
414
// Use the internal "CreateLink" command to create the link.
415
FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl, false, !!noUndo ) ;
417
// Look for the just create link.
418
var oLinks = this.EditorDocument.links ;
420
for ( i = 0 ; i < oLinks.length ; i++ )
422
var oLink = oLinks[i] ;
424
// Check it this a newly created link.
425
// getAttribute must be used. oLink.url may cause problems with IE7 (#555).
426
if ( oLink.getAttribute( 'href', 2 ) == sTempUrl )
428
var sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL).
430
oLink.innerHTML = sInnerHtml ; // Restore the innerHTML.
432
// If the last child is a <br> move it outside the link or it
433
// will be too easy to select this link again #388.
434
var oLastChild = oLink.lastChild ;
435
if ( oLastChild && oLastChild.nodeName == 'BR' )
437
// Move the BR after the link.
438
FCKDomTools.InsertAfterNode( oLink, oLink.removeChild( oLastChild ) ) ;
441
aCreatedLinks.push( oLink ) ;
446
return aCreatedLinks ;
449
function _FCK_RemoveDisabledAtt()
451
this.removeAttribute( 'disabled' ) ;
454
function Doc_OnMouseDown( evt )
456
var e = evt.srcElement ;
458
// Radio buttons and checkboxes should not be allowed to be triggered in IE
459
// in editable mode. Otherwise the whole browser window may be locked by
460
// the buttons. (#1782)
461
if ( e.nodeName && e.nodeName.IEquals( 'input' ) && e.type.IEquals( ['radio', 'checkbox'] ) && !e.disabled )
464
FCKTools.SetTimeout( _FCK_RemoveDisabledAtt, 1, e ) ;