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