[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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_2_gecko.js 14 * This is the second 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 // GetNamedCommandState overload for Gecko. 23 FCK._BaseGetNamedCommandState = FCK.GetNamedCommandState ; 24 FCK.GetNamedCommandState = function( commandName ) 25 { 26 switch ( commandName ) 27 { 28 case 'Unlink' : 29 return FCKSelection.HasAncestorNode('A') ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ; 30 default : 31 return FCK._BaseGetNamedCommandState( commandName ) ; 32 } 33 } 34 35 // Named commands to be handled by this browsers specific implementation. 36 FCK.RedirectNamedCommands = 37 { 38 Print : true, 39 Paste : true, 40 Cut : true, 41 Copy : true 42 // START iCM MODIFICATIONS 43 // Include list functions so we can ensure content is wrapped 44 // with P tags if not using BRs on carriage return, etc 45 /* 46 InsertOrderedList : true, 47 InsertUnorderedList : true 48 */ 49 // END iCM MODIFICATIONS 50 } 51 52 // ExecuteNamedCommand overload for Gecko. 53 FCK.ExecuteRedirectedNamedCommand = function( commandName, commandParameter ) 54 { 55 switch ( commandName ) 56 { 57 case 'Print' : 58 FCK.EditorWindow.print() ; 59 break ; 60 case 'Paste' : 61 try { if ( FCK.Paste() ) FCK.ExecuteNamedCommand( 'Paste', null, true ) ; } 62 catch (e) { alert(FCKLang.PasteErrorPaste) ; } 63 break ; 64 case 'Cut' : 65 try { FCK.ExecuteNamedCommand( 'Cut', null, true ) ; } 66 catch (e) { alert(FCKLang.PasteErrorCut) ; } 67 break ; 68 case 'Copy' : 69 try { FCK.ExecuteNamedCommand( 'Copy', null, true ) ; } 70 catch (e) { alert(FCKLang.PasteErrorCopy) ; } 71 break ; 72 73 // START iCM MODIFICATIONS 74 /* 75 case 'InsertOrderedList' : 76 case 'InsertUnorderedList' : 77 78 if ( !FCKConfig.UseBROnCarriageReturn && FCK.EditorDocument.queryCommandState( commandName ) ) 79 { 80 // We're in a list item which is in the same type of list as the toolbar button clicked 81 // Therefore, move the selected list item out of the list as is done on an ENTER key within 82 // an empty list item. 83 var oSel = FCK.EditorWindow.getSelection() ; 84 var oSelNode = oSel.focusNode ; 85 var oLINode = FCKTools.GetElementAscensor( oSelNode, "LI" ) ; 86 FCK.ToggleListItem( oLINode, oSelNode ) ; 87 } 88 else 89 { 90 // Let the default handler do its stuff 91 FCK.Focus() ; 92 FCK.EditorDocument.execCommand( commandName, false, commandParameter ) ; 93 } 94 95 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 96 break ; 97 */ 98 // END iCM MODIFICATIONS 99 100 default : 101 FCK.ExecuteNamedCommand( commandName, commandParameter ) ; 102 } 103 } 104 105 FCK.AttachToOnSelectionChange = function( functionPointer ) 106 { 107 this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ; 108 } 109 110 FCK.Paste = function() 111 { 112 if ( FCKConfig.ForcePasteAsPlainText ) 113 { 114 FCK.PasteAsPlainText() ; 115 return false ; 116 } 117 /* For now, the AutoDetectPasteFromWord feature is IE only. 118 else if ( FCKConfig.AutoDetectPasteFromWord ) 119 { 120 var sHTML = FCK.GetClipboardHTML() ; 121 var re = /<\w[^>]* class="?MsoNormal"?/gi ; 122 if ( re.test( sHTML ) ) 123 { 124 if ( confirm( FCKLang["PasteWordConfirm"] ) ) 125 { 126 FCK.PasteFromWord() ; 127 return false ; 128 } 129 } 130 } 131 */ 132 else 133 return true ; 134 } 135 136 //** 137 // FCK.InsertHtml: Inserts HTML at the current cursor location. Deletes the 138 // selected content if any. 139 FCK.InsertHtml = function( html ) 140 { 141 html = FCKConfig.ProtectedSource.Protect( html ) ; 142 html = FCK.ProtectUrls( html ) ; 143 144 // Delete the actual selection. 145 var oSel = FCKSelection.Delete() ; 146 147 // Get the first available range. 148 var oRange = oSel.getRangeAt(0) ; 149 150 // Create a fragment with the input HTML. 151 var oFragment = oRange.createContextualFragment( html ) ; 152 153 // Get the last available node. 154 var oLastNode = oFragment.lastChild ; 155 156 // Insert the fragment in the range. 157 oRange.insertNode(oFragment) ; 158 159 // Set the cursor after the inserted fragment. 160 FCKSelection.SelectNode( oLastNode ) ; 161 FCKSelection.Collapse( false ) ; 162 163 this.Focus() ; 164 } 165 166 FCK.InsertElement = function( element ) 167 { 168 // Deletes the actual selection. 169 var oSel = FCKSelection.Delete() ; 170 171 // Gets the first available range. 172 var oRange = oSel.getRangeAt(0) ; 173 174 // Inserts the element in the range. 175 oRange.insertNode( element ) ; 176 177 // Set the cursor after the inserted fragment. 178 FCKSelection.SelectNode( element ) ; 179 FCKSelection.Collapse( false ) ; 180 181 this.Focus() ; 182 } 183 184 FCK.PasteAsPlainText = function() 185 { 186 // TODO: Implement the "Paste as Plain Text" code. 187 188 FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ; 189 190 /* 191 var sText = FCKTools.HTMLEncode( clipboardData.getData("Text") ) ; 192 sText = sText.replace( /\n/g, '<BR>' ) ; 193 this.InsertHtml( sText ) ; 194 */ 195 } 196 /* 197 FCK.PasteFromWord = function() 198 { 199 // TODO: Implement the "Paste as Plain Text" code. 200 201 FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteFromWord, 'dialog/fck_paste.html', 400, 330, 'Word' ) ; 202 203 // FCK.CleanAndPaste( FCK.GetClipboardHTML() ) ; 204 } 205 */ 206 FCK.GetClipboardHTML = function() 207 { 208 return '' ; 209 } 210 211 FCK.CreateLink = function( url ) 212 { 213 FCK.ExecuteNamedCommand( 'Unlink' ) ; 214 215 if ( url.length > 0 ) 216 { 217 // Generate a temporary name for the link. 218 var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ; 219 220 // Use the internal "CreateLink" command to create the link. 221 FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ; 222 223 // Retrieve the just created link using XPath. 224 var oLink = document.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, 9, null).singleNodeValue ; 225 226 if ( oLink ) 227 { 228 oLink.href = url ; 229 return oLink ; 230 } 231 } 232 } 233 234 // START iCM Modifications 235 /* 236 // Ensure that behaviour of the ENTER key or the list toolbar button works correctly for a list item. 237 // ENTER in empty list item at top of list should result in the empty list item being 238 // removed and selection being moved out of the list into a P tag above it. 239 // ENTER in empty list item at bottom of list should result in the empty list item being 240 // removed and selection being moved out of the list into a P tag below it. 241 // ENTER in empty list item in middle of the list should result in the list being split 242 // into two and the selection being moved into a P tag between the two resulting lists. 243 // Clicking the list toolbar button in a list item at top of list should result in the list item's contents being 244 // moved out of the list into a P tag above it. 245 // Clicking the list toolbar button in a list item at the bottom of list should result in the list item's contents being 246 // moved out of the list into a P tag below it. 247 // Clicking the list toolbar button in a list item in the middle of the list should result in the list being split 248 // into two and the list item's contents being moved into a P tag between the two resulting lists. 249 FCK.ToggleListItem = function( oLINode, oSelNode ) 250 { 251 var oListNode = FCKTools.GetElementAscensor( oLINode, "UL,OL" ) ; 252 var oRange = FCK.EditorDocument.createRange() ; 253 254 // Create a new block element 255 var oBlockNode = FCK.EditorDocument.createElement( "P" ) ; 256 oBlockNode.innerHTML = oLINode.innerHTML ; // Transfer any list item contents 257 if ( FCKTools.NodeIsEmpty( oBlockNode ) ) 258 oBlockNode.innerHTML = GECKO_BOGUS ; // Ensure it has some content, required for Gecko 259 if ( oLINode.className && oLINode.className != '' ) 260 oBlockNode.className = oLINode.className ; // Transfer across any class attribute 261 262 var oCursorNode = oBlockNode ; 263 264 // Then, perform list processing and locate the point at which the new P tag is to be inserted 265 if ( oListNode.childNodes[0] == oLINode ) 266 { 267 // First LI was empty so want to leave list and insert P above it 268 oListNode.removeChild( oLINode ); 269 // Need to insert a new P tag (or other suitable block element) just before the list 270 oRange.setStartBefore( oListNode ) ; 271 oRange.setEndBefore( oListNode ) ; 272 } 273 else if ( oListNode.childNodes[oListNode.childNodes.length-1] == oLINode ) 274 { 275 // Last LI was empty so want to leave list and insert new block element in the parent 276 oListNode.removeChild( oLINode ); 277 // Need to insert a new P tag (or other suitable block element) just after the list 278 oRange.setEndAfter( oListNode ) ; 279 oRange.setStartAfter( oListNode ) ; 280 } 281 else 282 { 283 // A middle LI was empty so want to break list into two and insert the new block/text node in between them 284 oListNode = FCKTools.SplitNode( oListNode, oSelNode, 0 ) ; 285 oListNode.removeChild( oListNode.childNodes[0] ) ; 286 oRange.setStartBefore( oListNode ) ; 287 oRange.setEndBefore( oListNode ) ; 288 } 289 290 // Insert new block/text node 291 oRange.insertNode( oBlockNode ) ; 292 293 // Ensure that we don't leave empty UL/OL tags behind 294 if ( oListNode.childNodes.length == 0 ) 295 oListNode.parentNode.removeChild( oListNode ) ; 296 297 // Reset cursor position to start of the new P tag's contents ready for typing 298 FCK.Selection.SetCursorPosition( oCursorNode ) ; 299 } 300 301 FCK.ListItemEnter = function( oLINode, oSelNode, nSelOffset ) 302 { 303 // Ensure that behaviour of ENTER key within an empty list element works correctly. 304 // ENTER in empty list item at top of list should result in the empty list item being 305 // removed and selection being moved out of the list into a P tag above it. 306 // ENTER in empty list item at bottom of list should result in the empty list item being 307 // removed and selection being moved out of the list into a P tag below it. 308 // ENTER in empty list item in middle of the list should result in the list being split 309 // into two and the selection being moved into a P tag between the two resulting lists. 310 if ( FCKTools.NodeIsEmpty( oLINode ) ) 311 { 312 FCK.ToggleListItem( oLINode, oSelNode ) ; 313 return false ; // Job done, perform no default handling 314 } 315 316 return true ; // If non-empty list item, let default handler do its stuff 317 } 318 319 FCK.ListItemBackSpace = function( oSelNode, nSelOffset ) 320 { 321 // Ensure that behaviour of BACKSPACE key within an empty list element works correctly. 322 // BACKSPACE in empty list item at top of list should result in the empty list item being 323 // removed and selection being moved out of the list into a P tag above it. 324 // Allow the default handler to do its stuff for backspace in other list elements. 325 var oListNode = oSelNode.parentNode ; 326 327 if ( FCKTools.NodeIsEmpty( oSelNode ) && ( oListNode.childNodes[0] == oSelNode ) ) 328 { 329 var oRange = FCK.EditorDocument.createRange() ; 330 331 // Create a new P element 332 var oBlockNode = FCK.EditorDocument.createElement( "P" ) ; 333 if ( FCKTools.NodeIsEmpty( oBlockNode ) ) 334 oBlockNode.innerHTML = GECKO_BOGUS ; // Ensure it has some content, required for Gecko 335 336 // First LI was empty so want to leave list and insert P above it 337 oListNode.removeChild( oSelNode ); 338 oRange.setStartBefore( oListNode ) ; 339 oRange.setEndBefore( oListNode ) ; 340 341 // Insert new P tag 342 oRange.insertNode( oBlockNode ) ; 343 344 // Ensure that we don't leave empty UL/OL tags behind 345 if ( oListNode.childNodes.length == 0 ) 346 oListNode.parentNode.removeChild( oListNode ) ; 347 348 // Reset cursor position to start of the new P tag's contents ready for typing 349 FCK.Selection.SetCursorPosition( oBlockNode ) ; 350 351 return false ; // Job done, perform no default handling 352 } 353 354 return true ; // Let default handler do its stuff if not backspacing in an empty first LI 355 } 356 357 FCK.Enter = function() 358 { 359 // Remove any selected content before we begin so we end up with a single selection point 360 FCK.Selection.Delete() ; 361 362 // Determine the current cursor (selection) point, the node it's within and the offset 363 // position of the cursor within that node 364 var oSel = FCK.EditorWindow.getSelection() ; 365 var nSelOffset = oSel.focusOffset; 366 var oSelNode = oSel.focusNode ; 367 368 // Guard against a null focus node. 369 if ( !oSelNode ) 370 return false ; 371 372 var oLINode = FCKTools.GetElementAscensor( oSelNode, "LI" ) ; 373 374 if ( oLINode ) // An LI element is selected 375 { 376 // Handle list items separately as need to handle termination of the list, etc 377 return FCK.ListItemEnter( oLINode, oSelNode, nSelOffset ) ; 378 } 379 else if ( oSelNode.nodeType == 3 ) // A TEXT node is selected 380 { 381 // Split it at the selection point and ensure both halves have a suitable enclosing block element 382 var oParentBlockNode = FCKTools.GetParentBlockNode( oSelNode ) ; 383 var oBlockNode2 = FCKTools.SplitNode( oParentBlockNode ? oParentBlockNode : FCK.EditorDocument.body, oSelNode, nSelOffset ) ; 384 385 FCK.Selection.SetCursorPosition( oBlockNode2 ); 386 387 return false ; 388 } 389 else // An ELEMENT node is selected 390 { 391 // Cater for ENTER being pressed after very last element in the editor e.g. pressing ENTER after table element at very end of the editor's content 392 if ( nSelOffset >= oSelNode.childNodes.length ) 393 { 394 var oBlockNode = FCK.EditorDocument.createElement( "P" ) ; 395 if ( FCKTools.NodeIsEmpty( oBlockNode ) ) 396 oBlockNode.innerHTML = GECKO_BOGUS ; // Ensure it has some content, required for Gecko 397 oSelNode.appendChild( oBlockNode ) ; 398 FCK.Selection.SetCursorPosition( oBlockNode ) ; 399 return false ; 400 } 401 402 var oBlockNode2 = FCKTools.SplitNode( oSelNode, oSelNode.childNodes[nSelOffset] ) ; 403 404 FCK.Selection.SetCursorPosition( oBlockNode2 ); 405 406 return false ; 407 } 408 409 return true ; 410 } 411 412 FCK.BackSpace = function() 413 { 414 var oSel = FCK.EditorWindow.getSelection() ; 415 var oSelNode = oSel.focusNode ; 416 var nSelOffset = oSel.focusOffset; 417 var oParentNode = null ; 418 419 // Guard against a null focus node. 420 if ( !oSelNode ) 421 return false ; 422 423 if ( oSelNode.nodeName.toUpperCase() == "LI" ) // An LI element is selected 424 { 425 // Handle list items separately as need to handle termination of the list, etc 426 return FCK.ListItemBackSpace( oSelNode, nSelOffset ) ; 427 } 428 else 429 { 430 // If we are anything other than a TEXT node, move to the child indicated by the selection offset 431 if ( oSelNode.nodeType != 3 ) 432 { 433 oSelNode = oSelNode.childNodes[nSelOffset] ; 434 nSelOffset = 0 ; 435 } 436 437 // If we are the first child and the previous sibling of the parent is an empty block element (containing nothing or just the filler element) 438 // want the backspace to completely remove the empty block element 439 if ( !oSelNode.previousSibling && nSelOffset <= 0 ) 440 { 441 oParentNode = oSelNode.parentNode ; 442 443 if ( oParentNode && oParentNode.previousSibling && FCKRegexLib.BlockElements.test( oParentNode.previousSibling.nodeName ) ) 444 { 445 if ( FCKTools.NodeIsEmpty( oParentNode.previousSibling ) ) 446 { 447 var oRange = FCK.EditorDocument.createRange() ; 448 oRange.selectNode ( oParentNode.previousSibling ); 449 oRange.deleteContents() ; 450 451 // Don't do any default processing 452 return false ; 453 } 454 } 455 } 456 } 457 return true ; // Let default processing do its stuff 458 } 459 */ 460 // END iCM Modifications 461
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |