[795] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * == BEGIN LICENSE == |
---|
| 6 | * |
---|
| 7 | * Licensed under the terms of any of the following licenses at your |
---|
| 8 | * choice: |
---|
| 9 | * |
---|
| 10 | * - GNU General Public License Version 2 or later (the "GPL") |
---|
| 11 | * http://www.gnu.org/licenses/gpl.html |
---|
| 12 | * |
---|
| 13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
| 14 | * http://www.gnu.org/licenses/lgpl.html |
---|
| 15 | * |
---|
| 16 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
| 17 | * http://www.mozilla.org/MPL/MPL-1.1.html |
---|
| 18 | * |
---|
| 19 | * == END LICENSE == |
---|
| 20 | * |
---|
| 21 | * Creation and initialization of the "FCK" object. This is the main |
---|
| 22 | * object that represents an editor instance. |
---|
| 23 | * (IE specific implementations) |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | FCK.Description = "FCKeditor for Internet Explorer 5.5+" ; |
---|
| 27 | |
---|
| 28 | FCK._GetBehaviorsStyle = function() |
---|
| 29 | { |
---|
| 30 | if ( !FCK._BehaviorsStyle ) |
---|
| 31 | { |
---|
| 32 | var sBasePath = FCKConfig.FullBasePath ; |
---|
| 33 | var sTableBehavior = '' ; |
---|
| 34 | var sStyle ; |
---|
| 35 | |
---|
| 36 | // The behaviors should be pointed using the FullBasePath to avoid security |
---|
| 37 | // errors when using a differente BaseHref. |
---|
| 38 | sStyle = '<style type="text/css" _fcktemp="true">' ; |
---|
| 39 | |
---|
| 40 | if ( FCKConfig.ShowBorders ) |
---|
| 41 | sTableBehavior = 'url(' + sBasePath + 'css/behaviors/showtableborders.htc)' ; |
---|
| 42 | |
---|
| 43 | // Disable resize handlers. |
---|
| 44 | sStyle += 'INPUT,TEXTAREA,SELECT,.FCK__Anchor,.FCK__PageBreak,.FCK__InputHidden' ; |
---|
| 45 | |
---|
| 46 | if ( FCKConfig.DisableObjectResizing ) |
---|
| 47 | { |
---|
| 48 | sStyle += ',IMG' ; |
---|
| 49 | sTableBehavior += ' url(' + sBasePath + 'css/behaviors/disablehandles.htc)' ; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | sStyle += ' { behavior: url(' + sBasePath + 'css/behaviors/disablehandles.htc) ; }' ; |
---|
| 53 | |
---|
| 54 | if ( sTableBehavior.length > 0 ) |
---|
| 55 | sStyle += 'TABLE { behavior: ' + sTableBehavior + ' ; }' ; |
---|
| 56 | |
---|
| 57 | sStyle += '</style>' ; |
---|
| 58 | FCK._BehaviorsStyle = sStyle ; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | return FCK._BehaviorsStyle ; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function Doc_OnMouseUp() |
---|
| 65 | { |
---|
| 66 | if ( FCK.EditorWindow.event.srcElement.tagName == 'HTML' ) |
---|
| 67 | { |
---|
| 68 | FCK.Focus() ; |
---|
| 69 | FCK.EditorWindow.event.cancelBubble = true ; |
---|
| 70 | FCK.EditorWindow.event.returnValue = false ; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function Doc_OnPaste() |
---|
| 75 | { |
---|
| 76 | return ( FCK.Status == FCK_STATUS_COMPLETE && FCK.Events.FireEvent( "OnPaste" ) ) ; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function Doc_OnKeyDown() |
---|
| 80 | { |
---|
| 81 | if ( FCK.EditorWindow ) |
---|
| 82 | { |
---|
| 83 | var e = FCK.EditorWindow.event ; |
---|
| 84 | |
---|
| 85 | if ( !( e.keyCode >=16 && e.keyCode <= 18 ) ) |
---|
| 86 | Doc_OnKeyDownUndo() ; |
---|
| 87 | } |
---|
| 88 | return true ; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function Doc_OnKeyDownUndo() |
---|
| 92 | { |
---|
| 93 | if ( !FCKUndo.Typing ) |
---|
| 94 | { |
---|
| 95 | FCKUndo.SaveUndoStep() ; |
---|
| 96 | FCKUndo.Typing = true ; |
---|
| 97 | FCK.Events.FireEvent( "OnSelectionChange" ) ; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | FCKUndo.TypesCount++ ; |
---|
| 101 | |
---|
| 102 | if ( FCKUndo.TypesCount > FCKUndo.MaxTypes ) |
---|
| 103 | { |
---|
| 104 | FCKUndo.TypesCount = 0 ; |
---|
| 105 | FCKUndo.SaveUndoStep() ; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function Doc_OnDblClick() |
---|
| 110 | { |
---|
| 111 | FCK.OnDoubleClick( FCK.EditorWindow.event.srcElement ) ; |
---|
| 112 | FCK.EditorWindow.event.cancelBubble = true ; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | function Doc_OnSelectionChange() |
---|
| 116 | { |
---|
| 117 | FCK.Events.FireEvent( "OnSelectionChange" ) ; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | FCK.InitializeBehaviors = function( dontReturn ) |
---|
| 121 | { |
---|
| 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 ) ; |
---|
| 125 | |
---|
| 126 | // Intercept pasting operations |
---|
| 127 | this.EditorDocument.body.attachEvent( 'onpaste', Doc_OnPaste ) ; |
---|
| 128 | |
---|
| 129 | // Reset the context menu. |
---|
| 130 | FCK.ContextMenu._InnerContextMenu.AttachToElement( FCK.EditorDocument.body ) ; |
---|
| 131 | |
---|
| 132 | // Build the "TAB" key replacement (if necessary). |
---|
| 133 | if ( FCKConfig.TabSpaces > 0 ) |
---|
| 134 | { |
---|
| 135 | window.FCKTabHTML = '' ; |
---|
| 136 | for ( i = 0 ; i < FCKConfig.TabSpaces ; i++ ) |
---|
| 137 | window.FCKTabHTML += " " ; |
---|
| 138 | } |
---|
| 139 | this.EditorDocument.attachEvent("onkeydown", Doc_OnKeyDown ) ; |
---|
| 140 | |
---|
| 141 | this.EditorDocument.attachEvent("ondblclick", Doc_OnDblClick ) ; |
---|
| 142 | |
---|
| 143 | // Catch cursor selection changes. |
---|
| 144 | this.EditorDocument.attachEvent("onselectionchange", Doc_OnSelectionChange ) ; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | FCK.InsertHtml = function( html ) |
---|
| 148 | { |
---|
| 149 | html = FCKConfig.ProtectedSource.Protect( html ) ; |
---|
| 150 | html = FCK.ProtectEvents( html ) ; |
---|
| 151 | html = FCK.ProtectUrls( html ) ; |
---|
| 152 | html = FCK.ProtectTags( html ) ; |
---|
| 153 | |
---|
| 154 | // FCK.Focus() ; |
---|
| 155 | FCK.EditorWindow.focus() ; |
---|
| 156 | |
---|
| 157 | FCKUndo.SaveUndoStep() ; |
---|
| 158 | |
---|
| 159 | // Gets the actual selection. |
---|
| 160 | var oSel = FCK.EditorDocument.selection ; |
---|
| 161 | |
---|
| 162 | // Deletes the actual selection contents. |
---|
| 163 | if ( oSel.type.toLowerCase() == 'control' ) |
---|
| 164 | oSel.clear() ; |
---|
| 165 | |
---|
| 166 | // Insert the HTML. |
---|
| 167 | oSel.createRange().pasteHTML( html ) ; |
---|
| 168 | |
---|
| 169 | FCKDocumentProcessor.Process( FCK.EditorDocument ) ; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | FCK.SetInnerHtml = function( html ) // IE Only |
---|
| 173 | { |
---|
| 174 | var oDoc = FCK.EditorDocument ; |
---|
| 175 | // Using the following trick, any comment in the begining of the HTML will |
---|
| 176 | // be preserved. |
---|
| 177 | oDoc.body.innerHTML = '<div id="__fakeFCKRemove__"> </div>' + html ; |
---|
| 178 | oDoc.getElementById('__fakeFCKRemove__').removeNode( true ) ; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | function FCK_PreloadImages() |
---|
| 182 | { |
---|
| 183 | var oPreloader = new FCKImagePreloader() ; |
---|
| 184 | |
---|
| 185 | // Add the configured images. |
---|
| 186 | oPreloader.AddImages( FCKConfig.PreloadImages ) ; |
---|
| 187 | |
---|
| 188 | // Add the skin icons strip. |
---|
| 189 | oPreloader.AddImages( FCKConfig.SkinPath + 'fck_strip.gif' ) ; |
---|
| 190 | |
---|
| 191 | oPreloader.OnComplete = LoadToolbarSetup ; |
---|
| 192 | oPreloader.Start() ; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | // Disable the context menu in the editor (outside the editing area). |
---|
| 196 | function Document_OnContextMenu() |
---|
| 197 | { |
---|
| 198 | return ( event.srcElement._FCKShowContextMenu == true ) ; |
---|
| 199 | } |
---|
| 200 | document.oncontextmenu = Document_OnContextMenu ; |
---|
| 201 | |
---|
| 202 | function FCK_Cleanup() |
---|
| 203 | { |
---|
| 204 | this.EditorWindow = null ; |
---|
| 205 | this.EditorDocument = null ; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | FCK.Paste = function() |
---|
| 209 | { |
---|
| 210 | // As we call ExecuteNamedCommand('Paste'), it would enter in a loop. So, let's use a semaphore. |
---|
| 211 | if ( FCK._PasteIsRunning ) |
---|
| 212 | return true ; |
---|
| 213 | |
---|
| 214 | if ( FCKConfig.ForcePasteAsPlainText ) |
---|
| 215 | { |
---|
| 216 | FCK.PasteAsPlainText() ; |
---|
| 217 | return false ; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | var sHTML = FCK._CheckIsPastingEnabled( true ) ; |
---|
| 221 | |
---|
| 222 | if ( sHTML === false ) |
---|
| 223 | FCKTools.RunFunction( FCKDialog.OpenDialog, FCKDialog, ['FCKDialog_Paste', FCKLang.Paste, 'dialog/fck_paste.html', 400, 330, 'Security'] ) ; |
---|
| 224 | else |
---|
| 225 | { |
---|
| 226 | if ( FCKConfig.AutoDetectPasteFromWord && sHTML.length > 0 ) |
---|
| 227 | { |
---|
| 228 | var re = /<\w[^>]*(( class="?MsoNormal"?)|(="mso-))/gi ; |
---|
| 229 | if ( re.test( sHTML ) ) |
---|
| 230 | { |
---|
| 231 | if ( confirm( FCKLang.PasteWordConfirm ) ) |
---|
| 232 | { |
---|
| 233 | FCK.PasteFromWord() ; |
---|
| 234 | return false ; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | // Instead of inserting the retrieved HTML, let's leave the OS work for us, |
---|
| 240 | // by calling FCK.ExecuteNamedCommand( 'Paste' ). It could give better results. |
---|
| 241 | |
---|
| 242 | // Enable the semaphore to avoid a loop. |
---|
| 243 | FCK._PasteIsRunning = true ; |
---|
| 244 | |
---|
| 245 | FCK.ExecuteNamedCommand( 'Paste' ) ; |
---|
| 246 | |
---|
| 247 | // Removes the semaphore. |
---|
| 248 | delete FCK._PasteIsRunning ; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | // Let's always make a custom implementation (return false), otherwise |
---|
| 252 | // the new Keyboard Handler may conflict with this code, and the CTRL+V code |
---|
| 253 | // could result in a simple "V" being pasted. |
---|
| 254 | return false ; |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | FCK.PasteAsPlainText = function() |
---|
| 258 | { |
---|
| 259 | if ( !FCK._CheckIsPastingEnabled() ) |
---|
| 260 | { |
---|
| 261 | FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ; |
---|
| 262 | return ; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | // Get the data available in the clipboard in text format. |
---|
| 266 | var sText = clipboardData.getData("Text") ; |
---|
| 267 | |
---|
| 268 | if ( sText && sText.length > 0 ) |
---|
| 269 | { |
---|
| 270 | // Replace the carriage returns with <BR> |
---|
| 271 | sText = FCKTools.HTMLEncode( sText ).replace( /\n/g, '<BR>' ) ; |
---|
| 272 | |
---|
| 273 | // Insert the resulting data in the editor. |
---|
| 274 | this.InsertHtml( sText ) ; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | FCK._CheckIsPastingEnabled = function( returnContents ) |
---|
| 279 | { |
---|
| 280 | // The following seams to be the only reliable way to check is script |
---|
| 281 | // pasting operations are enabled in the secutiry settings of IE6 and IE7. |
---|
| 282 | // It adds a little bit of overhead to the check, but so far that's the |
---|
| 283 | // only way, mainly because of IE7. |
---|
| 284 | |
---|
| 285 | FCK._PasteIsEnabled = false ; |
---|
| 286 | |
---|
| 287 | document.body.attachEvent( 'onpaste', FCK_CheckPasting_Listener ) ; |
---|
| 288 | |
---|
| 289 | // The execCommand in GetClipboardHTML will fire the "onpaste", only if the |
---|
| 290 | // security settings are enabled. |
---|
| 291 | var oReturn = FCK.GetClipboardHTML() ; |
---|
| 292 | |
---|
| 293 | document.body.detachEvent( 'onpaste', FCK_CheckPasting_Listener ) ; |
---|
| 294 | |
---|
| 295 | if ( FCK._PasteIsEnabled ) |
---|
| 296 | { |
---|
| 297 | if ( !returnContents ) |
---|
| 298 | oReturn = true ; |
---|
| 299 | } |
---|
| 300 | else |
---|
| 301 | oReturn = false ; |
---|
| 302 | |
---|
| 303 | delete FCK._PasteIsEnabled ; |
---|
| 304 | |
---|
| 305 | return oReturn ; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | function FCK_CheckPasting_Listener() |
---|
| 309 | { |
---|
| 310 | FCK._PasteIsEnabled = true ; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | FCK.InsertElement = function( element ) |
---|
| 314 | { |
---|
| 315 | FCK.InsertHtml( element.outerHTML ) ; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | FCK.GetClipboardHTML = function() |
---|
| 319 | { |
---|
| 320 | var oDiv = document.getElementById( '___FCKHiddenDiv' ) ; |
---|
| 321 | |
---|
| 322 | if ( !oDiv ) |
---|
| 323 | { |
---|
| 324 | oDiv = document.createElement( 'DIV' ) ; |
---|
| 325 | oDiv.id = '___FCKHiddenDiv' ; |
---|
| 326 | |
---|
| 327 | var oDivStyle = oDiv.style ; |
---|
| 328 | oDivStyle.position = 'absolute' ; |
---|
| 329 | oDivStyle.visibility = oDivStyle.overflow = 'hidden' ; |
---|
| 330 | oDivStyle.width = oDivStyle.height = 1 ; |
---|
| 331 | |
---|
| 332 | document.body.appendChild( oDiv ) ; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | oDiv.innerHTML = '' ; |
---|
| 336 | |
---|
| 337 | var oTextRange = document.body.createTextRange() ; |
---|
| 338 | oTextRange.moveToElementText( oDiv ) ; |
---|
| 339 | oTextRange.execCommand( 'Paste' ) ; |
---|
| 340 | |
---|
| 341 | var sData = oDiv.innerHTML ; |
---|
| 342 | oDiv.innerHTML = '' ; |
---|
| 343 | |
---|
| 344 | return sData ; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | FCK.AttachToOnSelectionChange = function( functionPointer ) |
---|
| 348 | { |
---|
| 349 | this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | FCK.CreateLink = function( url ) |
---|
| 353 | { |
---|
| 354 | // Remove any existing link in the selection. |
---|
| 355 | FCK.ExecuteNamedCommand( 'Unlink' ) ; |
---|
| 356 | |
---|
| 357 | if ( url.length > 0 ) |
---|
| 358 | { |
---|
| 359 | // Generate a temporary name for the link. |
---|
| 360 | var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ; |
---|
| 361 | |
---|
| 362 | // Use the internal "CreateLink" command to create the link. |
---|
| 363 | FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ; |
---|
| 364 | |
---|
| 365 | // Look for the just create link. |
---|
| 366 | var oLinks = this.EditorDocument.links ; |
---|
| 367 | |
---|
| 368 | for ( i = 0 ; i < oLinks.length ; i++ ) |
---|
| 369 | { |
---|
| 370 | var oLink = oLinks[i] ; |
---|
| 371 | |
---|
| 372 | if ( oLink.href == sTempUrl ) |
---|
| 373 | { |
---|
| 374 | var sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL). |
---|
| 375 | oLink.href = url ; |
---|
| 376 | oLink.innerHTML = sInnerHtml ; // Restore the innerHTML. |
---|
| 377 | return oLink ; |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | return null ; |
---|
| 383 | } |
---|