[1575] | 1 | /*
|
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
| 3 | * Copyright (C) 2003-2009 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 | * Definition of other commands that are not available internaly in the
|
---|
| 22 | * browser (see FCKNamedCommand).
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | // ### General Dialog Box Commands.
|
---|
| 26 | var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam, customValue )
|
---|
| 27 | {
|
---|
| 28 | this.Name = name ;
|
---|
| 29 | this.Title = title ;
|
---|
| 30 | this.Url = url ;
|
---|
| 31 | this.Width = width ;
|
---|
| 32 | this.Height = height ;
|
---|
| 33 | this.CustomValue = customValue ;
|
---|
| 34 |
|
---|
| 35 | this.GetStateFunction = getStateFunction ;
|
---|
| 36 | this.GetStateParam = getStateParam ;
|
---|
| 37 |
|
---|
| 38 | this.Resizable = false ;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | FCKDialogCommand.prototype.Execute = function()
|
---|
| 42 | {
|
---|
| 43 | FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, this.CustomValue, this.Resizable ) ;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | FCKDialogCommand.prototype.GetState = function()
|
---|
| 47 | {
|
---|
| 48 | if ( this.GetStateFunction )
|
---|
| 49 | return this.GetStateFunction( this.GetStateParam ) ;
|
---|
| 50 | else
|
---|
| 51 | return FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // Generic Undefined command (usually used when a command is under development).
|
---|
| 55 | var FCKUndefinedCommand = function()
|
---|
| 56 | {
|
---|
| 57 | this.Name = 'Undefined' ;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | FCKUndefinedCommand.prototype.Execute = function()
|
---|
| 61 | {
|
---|
| 62 | alert( FCKLang.NotImplemented ) ;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | FCKUndefinedCommand.prototype.GetState = function()
|
---|
| 66 | {
|
---|
| 67 | return FCK_TRISTATE_OFF ;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | // ### FormatBlock
|
---|
| 72 | var FCKFormatBlockCommand = function()
|
---|
| 73 | {}
|
---|
| 74 |
|
---|
| 75 | FCKFormatBlockCommand.prototype =
|
---|
| 76 | {
|
---|
| 77 | Name : 'FormatBlock',
|
---|
| 78 |
|
---|
| 79 | Execute : FCKStyleCommand.prototype.Execute,
|
---|
| 80 |
|
---|
| 81 | GetState : function()
|
---|
| 82 | {
|
---|
| 83 | return FCK.EditorDocument ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
|
---|
| 84 | }
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | // ### FontName
|
---|
| 88 |
|
---|
| 89 | var FCKFontNameCommand = function()
|
---|
| 90 | {}
|
---|
| 91 |
|
---|
| 92 | FCKFontNameCommand.prototype =
|
---|
| 93 | {
|
---|
| 94 | Name : 'FontName',
|
---|
| 95 | Execute : FCKStyleCommand.prototype.Execute,
|
---|
| 96 | GetState : FCKFormatBlockCommand.prototype.GetState
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | // ### FontSize
|
---|
| 100 | var FCKFontSizeCommand = function()
|
---|
| 101 | {}
|
---|
| 102 |
|
---|
| 103 | FCKFontSizeCommand.prototype =
|
---|
| 104 | {
|
---|
| 105 | Name : 'FontSize',
|
---|
| 106 | Execute : FCKStyleCommand.prototype.Execute,
|
---|
| 107 | GetState : FCKFormatBlockCommand.prototype.GetState
|
---|
| 108 | };
|
---|
| 109 |
|
---|
| 110 | // ### Preview
|
---|
| 111 | var FCKPreviewCommand = function()
|
---|
| 112 | {
|
---|
| 113 | this.Name = 'Preview' ;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | FCKPreviewCommand.prototype.Execute = function()
|
---|
| 117 | {
|
---|
| 118 | FCK.Preview() ;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | FCKPreviewCommand.prototype.GetState = function()
|
---|
| 122 | {
|
---|
| 123 | return FCK_TRISTATE_OFF ;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | // ### Save
|
---|
| 127 | var FCKSaveCommand = function()
|
---|
| 128 | {
|
---|
| 129 | this.Name = 'Save' ;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | FCKSaveCommand.prototype.Execute = function()
|
---|
| 133 | {
|
---|
| 134 | // Get the linked field form.
|
---|
| 135 | var oForm = FCK.GetParentForm() ;
|
---|
| 136 |
|
---|
| 137 | if ( typeof( oForm.onsubmit ) == 'function' )
|
---|
| 138 | {
|
---|
| 139 | var bRet = oForm.onsubmit() ;
|
---|
| 140 | if ( bRet != null && bRet === false )
|
---|
| 141 | return ;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | // Submit the form.
|
---|
| 145 | // If there's a button named "submit" then the form.submit() function is masked and
|
---|
| 146 | // can't be called in Mozilla, so we call the click() method of that button.
|
---|
| 147 | if ( typeof( oForm.submit ) == 'function' )
|
---|
| 148 | oForm.submit() ;
|
---|
| 149 | else
|
---|
| 150 | oForm.submit.click() ;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | FCKSaveCommand.prototype.GetState = function()
|
---|
| 154 | {
|
---|
| 155 | return FCK_TRISTATE_OFF ;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | // ### NewPage
|
---|
| 159 | var FCKNewPageCommand = function()
|
---|
| 160 | {
|
---|
| 161 | this.Name = 'NewPage' ;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | FCKNewPageCommand.prototype.Execute = function()
|
---|
| 165 | {
|
---|
| 166 | FCKUndo.SaveUndoStep() ;
|
---|
| 167 | FCK.SetData( '' ) ;
|
---|
| 168 | FCKUndo.Typing = true ;
|
---|
| 169 | FCK.Focus() ;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | FCKNewPageCommand.prototype.GetState = function()
|
---|
| 173 | {
|
---|
| 174 | return FCK_TRISTATE_OFF ;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | // ### Source button
|
---|
| 178 | var FCKSourceCommand = function()
|
---|
| 179 | {
|
---|
| 180 | this.Name = 'Source' ;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | FCKSourceCommand.prototype.Execute = function()
|
---|
| 184 | {
|
---|
| 185 | if ( FCKConfig.SourcePopup ) // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.
|
---|
| 186 | {
|
---|
| 187 | var iWidth = FCKConfig.ScreenWidth * 0.65 ;
|
---|
| 188 | var iHeight = FCKConfig.ScreenHeight * 0.65 ;
|
---|
| 189 | FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, true ) ;
|
---|
| 190 | }
|
---|
| 191 | else
|
---|
| 192 | FCK.SwitchEditMode() ;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | FCKSourceCommand.prototype.GetState = function()
|
---|
| 196 | {
|
---|
| 197 | return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | // ### Undo
|
---|
| 201 | var FCKUndoCommand = function()
|
---|
| 202 | {
|
---|
| 203 | this.Name = 'Undo' ;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | FCKUndoCommand.prototype.Execute = function()
|
---|
| 207 | {
|
---|
| 208 | FCKUndo.Undo() ;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | FCKUndoCommand.prototype.GetState = function()
|
---|
| 212 | {
|
---|
| 213 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 214 | return FCK_TRISTATE_DISABLED ;
|
---|
| 215 | return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | // ### Redo
|
---|
| 219 | var FCKRedoCommand = function()
|
---|
| 220 | {
|
---|
| 221 | this.Name = 'Redo' ;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | FCKRedoCommand.prototype.Execute = function()
|
---|
| 225 | {
|
---|
| 226 | FCKUndo.Redo() ;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | FCKRedoCommand.prototype.GetState = function()
|
---|
| 230 | {
|
---|
| 231 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 232 | return FCK_TRISTATE_DISABLED ;
|
---|
| 233 | return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | // ### Page Break
|
---|
| 237 | var FCKPageBreakCommand = function()
|
---|
| 238 | {
|
---|
| 239 | this.Name = 'PageBreak' ;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | FCKPageBreakCommand.prototype.Execute = function()
|
---|
| 243 | {
|
---|
| 244 | // Take an undo snapshot before changing the document
|
---|
| 245 | FCKUndo.SaveUndoStep() ;
|
---|
| 246 |
|
---|
| 247 | // var e = FCK.EditorDocument.createElement( 'CENTER' ) ;
|
---|
| 248 | // e.style.pageBreakAfter = 'always' ;
|
---|
| 249 |
|
---|
| 250 | // Tidy was removing the empty CENTER tags, so the following solution has
|
---|
| 251 | // been found. It also validates correctly as XHTML 1.0 Strict.
|
---|
| 252 | var e = FCK.EditorDocument.createElement( 'DIV' ) ;
|
---|
| 253 | e.style.pageBreakAfter = 'always' ;
|
---|
| 254 | e.innerHTML = '<span style="DISPLAY:none"> </span>' ;
|
---|
| 255 |
|
---|
| 256 | var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;
|
---|
| 257 | var oRange = new FCKDomRange( FCK.EditorWindow ) ;
|
---|
| 258 | oRange.MoveToSelection() ;
|
---|
| 259 | var oSplitInfo = oRange.SplitBlock() ;
|
---|
| 260 | oRange.InsertNode( oFakeImage ) ;
|
---|
| 261 |
|
---|
| 262 | FCK.Events.FireEvent( 'OnSelectionChange' ) ;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | FCKPageBreakCommand.prototype.GetState = function()
|
---|
| 266 | {
|
---|
| 267 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 268 | return FCK_TRISTATE_DISABLED ;
|
---|
| 269 | return 0 ; // FCK_TRISTATE_OFF
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | // FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)
|
---|
| 273 | var FCKUnlinkCommand = function()
|
---|
| 274 | {
|
---|
| 275 | this.Name = 'Unlink' ;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | FCKUnlinkCommand.prototype.Execute = function()
|
---|
| 279 | {
|
---|
| 280 | // Take an undo snapshot before changing the document
|
---|
| 281 | FCKUndo.SaveUndoStep() ;
|
---|
| 282 |
|
---|
| 283 | if ( FCKBrowserInfo.IsGeckoLike )
|
---|
| 284 | {
|
---|
| 285 | var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
|
---|
| 286 | // The unlink command can generate a span in Firefox, so let's do it our way. See #430
|
---|
| 287 | if ( oLink )
|
---|
| 288 | FCKTools.RemoveOuterTags( oLink ) ;
|
---|
| 289 |
|
---|
| 290 | return ;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | FCK.ExecuteNamedCommand( this.Name ) ;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | FCKUnlinkCommand.prototype.GetState = function()
|
---|
| 297 | {
|
---|
| 298 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 299 | return FCK_TRISTATE_DISABLED ;
|
---|
| 300 | var state = FCK.GetNamedCommandState( this.Name ) ;
|
---|
| 301 |
|
---|
| 302 | // Check that it isn't an anchor
|
---|
| 303 | if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG )
|
---|
| 304 | {
|
---|
| 305 | var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
|
---|
| 306 | var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
|
---|
| 307 | if ( bIsAnchor )
|
---|
| 308 | state = FCK_TRISTATE_DISABLED ;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | return state ;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | var FCKVisitLinkCommand = function()
|
---|
| 315 | {
|
---|
| 316 | this.Name = 'VisitLink';
|
---|
| 317 | }
|
---|
| 318 | FCKVisitLinkCommand.prototype =
|
---|
| 319 | {
|
---|
| 320 | GetState : function()
|
---|
| 321 | {
|
---|
| 322 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 323 | return FCK_TRISTATE_DISABLED ;
|
---|
| 324 | var state = FCK.GetNamedCommandState( 'Unlink' ) ;
|
---|
| 325 |
|
---|
| 326 | if ( state == FCK_TRISTATE_OFF )
|
---|
| 327 | {
|
---|
| 328 | var el = FCKSelection.MoveToAncestorNode( 'A' ) ;
|
---|
| 329 | if ( !el.href )
|
---|
| 330 | state = FCK_TRISTATE_DISABLED ;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | return state ;
|
---|
| 334 | },
|
---|
| 335 |
|
---|
| 336 | Execute : function()
|
---|
| 337 | {
|
---|
| 338 | var el = FCKSelection.MoveToAncestorNode( 'A' ) ;
|
---|
| 339 | var url = el.getAttribute( '_fcksavedurl' ) || el.getAttribute( 'href', 2 ) ;
|
---|
| 340 |
|
---|
| 341 | // Check if it's a full URL.
|
---|
| 342 | // If not full URL, we'll need to apply the BaseHref setting.
|
---|
| 343 | if ( ! /:\/\//.test( url ) )
|
---|
| 344 | {
|
---|
| 345 | var baseHref = FCKConfig.BaseHref ;
|
---|
| 346 | var parentWindow = FCK.GetInstanceObject( 'parent' ) ;
|
---|
| 347 | if ( !baseHref )
|
---|
| 348 | {
|
---|
| 349 | baseHref = parentWindow.document.location.href ;
|
---|
| 350 | baseHref = baseHref.substring( 0, baseHref.lastIndexOf( '/' ) + 1 ) ;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | if ( /^\//.test( url ) )
|
---|
| 354 | {
|
---|
| 355 | try
|
---|
| 356 | {
|
---|
| 357 | baseHref = baseHref.match( /^.*:\/\/+[^\/]+/ )[0] ;
|
---|
| 358 | }
|
---|
| 359 | catch ( e )
|
---|
| 360 | {
|
---|
| 361 | baseHref = parentWindow.document.location.protocol + '://' + parentWindow.parent.document.location.host ;
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | url = baseHref + url ;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | if ( !window.open( url, '_blank' ) )
|
---|
| 369 | alert( FCKLang.VisitLinkBlocked ) ;
|
---|
| 370 | }
|
---|
| 371 | } ;
|
---|
| 372 |
|
---|
| 373 | // FCKSelectAllCommand
|
---|
| 374 | var FCKSelectAllCommand = function()
|
---|
| 375 | {
|
---|
| 376 | this.Name = 'SelectAll' ;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | FCKSelectAllCommand.prototype.Execute = function()
|
---|
| 380 | {
|
---|
| 381 | if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
|
---|
| 382 | {
|
---|
| 383 | FCK.ExecuteNamedCommand( 'SelectAll' ) ;
|
---|
| 384 | }
|
---|
| 385 | else
|
---|
| 386 | {
|
---|
| 387 | // Select the contents of the textarea
|
---|
| 388 | var textarea = FCK.EditingArea.Textarea ;
|
---|
| 389 | if ( FCKBrowserInfo.IsIE )
|
---|
| 390 | {
|
---|
| 391 | textarea.createTextRange().execCommand( 'SelectAll' ) ;
|
---|
| 392 | }
|
---|
| 393 | else
|
---|
| 394 | {
|
---|
| 395 | textarea.selectionStart = 0 ;
|
---|
| 396 | textarea.selectionEnd = textarea.value.length ;
|
---|
| 397 | }
|
---|
| 398 | textarea.focus() ;
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | FCKSelectAllCommand.prototype.GetState = function()
|
---|
| 403 | {
|
---|
| 404 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 405 | return FCK_TRISTATE_DISABLED ;
|
---|
| 406 | return FCK_TRISTATE_OFF ;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | // FCKPasteCommand
|
---|
| 410 | var FCKPasteCommand = function()
|
---|
| 411 | {
|
---|
| 412 | this.Name = 'Paste' ;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | FCKPasteCommand.prototype =
|
---|
| 416 | {
|
---|
| 417 | Execute : function()
|
---|
| 418 | {
|
---|
| 419 | if ( FCKBrowserInfo.IsIE )
|
---|
| 420 | FCK.Paste() ;
|
---|
| 421 | else
|
---|
| 422 | FCK.ExecuteNamedCommand( 'Paste' ) ;
|
---|
| 423 | },
|
---|
| 424 |
|
---|
| 425 | GetState : function()
|
---|
| 426 | {
|
---|
| 427 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 428 | return FCK_TRISTATE_DISABLED ;
|
---|
| 429 | return FCK.GetNamedCommandState( 'Paste' ) ;
|
---|
| 430 | }
|
---|
| 431 | } ;
|
---|
| 432 |
|
---|
| 433 | // FCKRuleCommand
|
---|
| 434 | var FCKRuleCommand = function()
|
---|
| 435 | {
|
---|
| 436 | this.Name = 'Rule' ;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | FCKRuleCommand.prototype =
|
---|
| 440 | {
|
---|
| 441 | Execute : function()
|
---|
| 442 | {
|
---|
| 443 | FCKUndo.SaveUndoStep() ;
|
---|
| 444 | FCK.InsertElement( 'hr' ) ;
|
---|
| 445 | },
|
---|
| 446 |
|
---|
| 447 | GetState : function()
|
---|
| 448 | {
|
---|
| 449 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 450 | return FCK_TRISTATE_DISABLED ;
|
---|
| 451 | return FCK.GetNamedCommandState( 'InsertHorizontalRule' ) ;
|
---|
| 452 | }
|
---|
| 453 | } ;
|
---|
| 454 |
|
---|
| 455 | // FCKCutCopyCommand
|
---|
| 456 | var FCKCutCopyCommand = function( isCut )
|
---|
| 457 | {
|
---|
| 458 | this.Name = isCut ? 'Cut' : 'Copy' ;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | FCKCutCopyCommand.prototype =
|
---|
| 462 | {
|
---|
| 463 | Execute : function()
|
---|
| 464 | {
|
---|
| 465 | var enabled = false ;
|
---|
| 466 |
|
---|
| 467 | if ( FCKBrowserInfo.IsIE )
|
---|
| 468 | {
|
---|
| 469 | // The following seems to be the only reliable way to detect that
|
---|
| 470 | // cut/copy is enabled in IE. It will fire the oncut/oncopy event
|
---|
| 471 | // only if the security settings enabled the command to execute.
|
---|
| 472 |
|
---|
| 473 | var onEvent = function()
|
---|
| 474 | {
|
---|
| 475 | enabled = true ;
|
---|
| 476 | } ;
|
---|
| 477 |
|
---|
| 478 | var eventName = 'on' + this.Name.toLowerCase() ;
|
---|
| 479 |
|
---|
| 480 | FCK.EditorDocument.body.attachEvent( eventName, onEvent ) ;
|
---|
| 481 | FCK.ExecuteNamedCommand( this.Name ) ;
|
---|
| 482 | FCK.EditorDocument.body.detachEvent( eventName, onEvent ) ;
|
---|
| 483 | }
|
---|
| 484 | else
|
---|
| 485 | {
|
---|
| 486 | try
|
---|
| 487 | {
|
---|
| 488 | // Other browsers throw an error if the command is disabled.
|
---|
| 489 | FCK.ExecuteNamedCommand( this.Name ) ;
|
---|
| 490 | enabled = true ;
|
---|
| 491 | }
|
---|
| 492 | catch(e){}
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | if ( !enabled )
|
---|
| 496 | alert( FCKLang[ 'PasteError' + this.Name ] ) ;
|
---|
| 497 | },
|
---|
| 498 |
|
---|
| 499 | GetState : function()
|
---|
| 500 | {
|
---|
| 501 | // Strangely, the Cut command happens to have the correct states for
|
---|
| 502 | // both Copy and Cut in all browsers.
|
---|
| 503 | return FCK.EditMode != FCK_EDITMODE_WYSIWYG ?
|
---|
| 504 | FCK_TRISTATE_DISABLED :
|
---|
| 505 | FCK.GetNamedCommandState( 'Cut' ) ;
|
---|
| 506 | }
|
---|
| 507 | };
|
---|
| 508 |
|
---|
| 509 | var FCKAnchorDeleteCommand = function()
|
---|
| 510 | {
|
---|
| 511 | this.Name = 'AnchorDelete' ;
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | FCKAnchorDeleteCommand.prototype =
|
---|
| 515 | {
|
---|
| 516 | Execute : function()
|
---|
| 517 | {
|
---|
| 518 | if (FCK.Selection.GetType() == 'Control')
|
---|
| 519 | {
|
---|
| 520 | FCK.Selection.Delete();
|
---|
| 521 | }
|
---|
| 522 | else
|
---|
| 523 | {
|
---|
| 524 | var oFakeImage = FCK.Selection.GetSelectedElement() ;
|
---|
| 525 | if ( oFakeImage )
|
---|
| 526 | {
|
---|
| 527 | if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') )
|
---|
| 528 | oAnchor = FCK.GetRealElement( oFakeImage ) ;
|
---|
| 529 | else
|
---|
| 530 | oFakeImage = null ;
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | //Search for a real anchor
|
---|
| 534 | if ( !oFakeImage )
|
---|
| 535 | {
|
---|
| 536 | oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ;
|
---|
| 537 | if ( oAnchor )
|
---|
| 538 | FCK.Selection.SelectNode( oAnchor ) ;
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // If it's also a link, then just remove the name and exit
|
---|
| 542 | if ( oAnchor.href.length != 0 )
|
---|
| 543 | {
|
---|
| 544 | oAnchor.removeAttribute( 'name' ) ;
|
---|
| 545 | // Remove temporary class for IE
|
---|
| 546 | if ( FCKBrowserInfo.IsIE )
|
---|
| 547 | oAnchor.className = oAnchor.className.replace( FCKRegexLib.FCK_Class, '' ) ;
|
---|
| 548 | return ;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | // We need to remove the anchor
|
---|
| 552 | // If we got a fake image, then just remove it and we're done
|
---|
| 553 | if ( oFakeImage )
|
---|
| 554 | {
|
---|
| 555 | oFakeImage.parentNode.removeChild( oFakeImage ) ;
|
---|
| 556 | return ;
|
---|
| 557 | }
|
---|
| 558 | // Empty anchor, so just remove it
|
---|
| 559 | if ( oAnchor.innerHTML.length == 0 )
|
---|
| 560 | {
|
---|
| 561 | oAnchor.parentNode.removeChild( oAnchor ) ;
|
---|
| 562 | return ;
|
---|
| 563 | }
|
---|
| 564 | // Anchor with content, leave the content
|
---|
| 565 | FCKTools.RemoveOuterTags( oAnchor ) ;
|
---|
| 566 | }
|
---|
| 567 | if ( FCKBrowserInfo.IsGecko )
|
---|
| 568 | FCK.Selection.Collapse( true ) ;
|
---|
| 569 | },
|
---|
| 570 |
|
---|
| 571 | GetState : function()
|
---|
| 572 | {
|
---|
| 573 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 574 | return FCK_TRISTATE_DISABLED ;
|
---|
| 575 | return FCK.GetNamedCommandState( 'Unlink') ;
|
---|
| 576 | }
|
---|
| 577 | };
|
---|
| 578 |
|
---|
| 579 | var FCKDeleteDivCommand = function()
|
---|
| 580 | {
|
---|
| 581 | }
|
---|
| 582 | FCKDeleteDivCommand.prototype =
|
---|
| 583 | {
|
---|
| 584 | GetState : function()
|
---|
| 585 | {
|
---|
| 586 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
| 587 | return FCK_TRISTATE_DISABLED ;
|
---|
| 588 |
|
---|
| 589 | var node = FCKSelection.GetParentElement() ;
|
---|
| 590 | var path = new FCKElementPath( node ) ;
|
---|
| 591 | return path.BlockLimit && path.BlockLimit.nodeName.IEquals( 'div' ) ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
|
---|
| 592 | },
|
---|
| 593 |
|
---|
| 594 | Execute : function()
|
---|
| 595 | {
|
---|
| 596 | // Create an undo snapshot before doing anything.
|
---|
| 597 | FCKUndo.SaveUndoStep() ;
|
---|
| 598 |
|
---|
| 599 | // Find out the nodes to delete.
|
---|
| 600 | var nodes = FCKDomTools.GetSelectedDivContainers() ;
|
---|
| 601 |
|
---|
| 602 | // Remember the current selection position.
|
---|
| 603 | var range = new FCKDomRange( FCK.EditorWindow ) ;
|
---|
| 604 | range.MoveToSelection() ;
|
---|
| 605 | var bookmark = range.CreateBookmark() ;
|
---|
| 606 |
|
---|
| 607 | // Delete the container DIV node.
|
---|
| 608 | for ( var i = 0 ; i < nodes.length ; i++)
|
---|
| 609 | FCKDomTools.RemoveNode( nodes[i], true ) ;
|
---|
| 610 |
|
---|
| 611 | // Restore selection.
|
---|
| 612 | range.MoveToBookmark( bookmark ) ;
|
---|
| 613 | range.Select() ;
|
---|
| 614 | }
|
---|
| 615 | } ;
|
---|
| 616 |
|
---|
| 617 | // FCKRuleCommand
|
---|
| 618 | var FCKNbsp = function()
|
---|
| 619 | {
|
---|
| 620 | this.Name = 'Non Breaking Space' ;
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | FCKNbsp.prototype =
|
---|
| 624 | {
|
---|
| 625 | Execute : function()
|
---|
| 626 | {
|
---|
| 627 | FCK.InsertHtml( ' ' ) ;
|
---|
| 628 | },
|
---|
| 629 |
|
---|
| 630 | GetState : function()
|
---|
| 631 | {
|
---|
| 632 | return ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_DISABLED : FCK_TRISTATE_OFF ) ;
|
---|
| 633 | }
|
---|
| 634 | } ;
|
---|