-/*\r
- * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
- *\r
- * == BEGIN LICENSE ==\r
- *\r
- * Licensed under the terms of any of the following licenses at your\r
- * choice:\r
- *\r
- * - GNU General Public License Version 2 or later (the "GPL")\r
- * http://www.gnu.org/licenses/gpl.html\r
- *\r
- * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
- * http://www.gnu.org/licenses/lgpl.html\r
- *\r
- * - Mozilla Public License Version 1.1 or later (the "MPL")\r
- * http://www.mozilla.org/MPL/MPL-1.1.html\r
- *\r
- * == END LICENSE ==\r
- *\r
- * Definition of other commands that are not available internaly in the\r
- * browser (see FCKNamedCommand).\r
- */\r
-\r
-// ### General Dialog Box Commands.\r
-var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam, customValue )\r
-{\r
- this.Name = name ;\r
- this.Title = title ;\r
- this.Url = url ;\r
- this.Width = width ;\r
- this.Height = height ;\r
- this.CustomValue = customValue ;\r
-\r
- this.GetStateFunction = getStateFunction ;\r
- this.GetStateParam = getStateParam ;\r
-\r
- this.Resizable = false ;\r
-}\r
-\r
-FCKDialogCommand.prototype.Execute = function()\r
-{\r
- FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, this.CustomValue, null, this.Resizable ) ;\r
-}\r
-\r
-FCKDialogCommand.prototype.GetState = function()\r
-{\r
- if ( this.GetStateFunction )\r
- return this.GetStateFunction( this.GetStateParam ) ;\r
- else\r
- return FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;\r
-}\r
-\r
-// Generic Undefined command (usually used when a command is under development).\r
-var FCKUndefinedCommand = function()\r
-{\r
- this.Name = 'Undefined' ;\r
-}\r
-\r
-FCKUndefinedCommand.prototype.Execute = function()\r
-{\r
- alert( FCKLang.NotImplemented ) ;\r
-}\r
-\r
-FCKUndefinedCommand.prototype.GetState = function()\r
-{\r
- return FCK_TRISTATE_OFF ;\r
-}\r
-\r
-\r
-// ### FormatBlock\r
-var FCKFormatBlockCommand = function()\r
-{}\r
-\r
-FCKFormatBlockCommand.prototype =\r
-{\r
- Name : 'FormatBlock',\r
-\r
- Execute : FCKStyleCommand.prototype.Execute,\r
-\r
- GetState : function()\r
- {\r
- return FCK.EditorDocument ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;\r
- }\r
-};\r
-\r
-// ### FontName\r
-\r
-var FCKFontNameCommand = function()\r
-{}\r
-\r
-FCKFontNameCommand.prototype =\r
-{\r
- Name : 'FontName',\r
- Execute : FCKStyleCommand.prototype.Execute,\r
- GetState : FCKFormatBlockCommand.prototype.GetState\r
-};\r
-\r
-// ### FontSize\r
-var FCKFontSizeCommand = function()\r
-{}\r
-\r
-FCKFontSizeCommand.prototype =\r
-{\r
- Name : 'FontSize',\r
- Execute : FCKStyleCommand.prototype.Execute,\r
- GetState : FCKFormatBlockCommand.prototype.GetState\r
-};\r
-\r
-// ### Preview\r
-var FCKPreviewCommand = function()\r
-{\r
- this.Name = 'Preview' ;\r
-}\r
-\r
-FCKPreviewCommand.prototype.Execute = function()\r
-{\r
- FCK.Preview() ;\r
-}\r
-\r
-FCKPreviewCommand.prototype.GetState = function()\r
-{\r
- return FCK_TRISTATE_OFF ;\r
-}\r
-\r
-// ### Save\r
-var FCKSaveCommand = function()\r
-{\r
- this.Name = 'Save' ;\r
-}\r
-\r
-FCKSaveCommand.prototype.Execute = function()\r
-{\r
- // Get the linked field form.\r
- var oForm = FCK.GetParentForm() ;\r
-\r
- if ( typeof( oForm.onsubmit ) == 'function' )\r
- {\r
- var bRet = oForm.onsubmit() ;\r
- if ( bRet != null && bRet === false )\r
- return ;\r
- }\r
-\r
- // Submit the form.\r
- // If there's a button named "submit" then the form.submit() function is masked and\r
- // can't be called in Mozilla, so we call the click() method of that button.\r
- if ( typeof( oForm.submit ) == 'function' )\r
- oForm.submit() ;\r
- else\r
- oForm.submit.click() ;\r
-}\r
-\r
-FCKSaveCommand.prototype.GetState = function()\r
-{\r
- return FCK_TRISTATE_OFF ;\r
-}\r
-\r
-// ### NewPage\r
-var FCKNewPageCommand = function()\r
-{\r
- this.Name = 'NewPage' ;\r
-}\r
-\r
-FCKNewPageCommand.prototype.Execute = function()\r
-{\r
- FCKUndo.SaveUndoStep() ;\r
- FCK.SetData( '' ) ;\r
- FCKUndo.Typing = true ;\r
- FCK.Focus() ;\r
-}\r
-\r
-FCKNewPageCommand.prototype.GetState = function()\r
-{\r
- return FCK_TRISTATE_OFF ;\r
-}\r
-\r
-// ### Source button\r
-var FCKSourceCommand = function()\r
-{\r
- this.Name = 'Source' ;\r
-}\r
-\r
-FCKSourceCommand.prototype.Execute = function()\r
-{\r
- if ( FCKConfig.SourcePopup ) // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.\r
- {\r
- var iWidth = FCKConfig.ScreenWidth * 0.65 ;\r
- var iHeight = FCKConfig.ScreenHeight * 0.65 ;\r
- FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, null, true ) ;\r
- }\r
- else\r
- FCK.SwitchEditMode() ;\r
-}\r
-\r
-FCKSourceCommand.prototype.GetState = function()\r
-{\r
- return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;\r
-}\r
-\r
-// ### Undo\r
-var FCKUndoCommand = function()\r
-{\r
- this.Name = 'Undo' ;\r
-}\r
-\r
-FCKUndoCommand.prototype.Execute = function()\r
-{\r
- FCKUndo.Undo() ;\r
-}\r
-\r
-FCKUndoCommand.prototype.GetState = function()\r
-{\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;\r
-}\r
-\r
-// ### Redo\r
-var FCKRedoCommand = function()\r
-{\r
- this.Name = 'Redo' ;\r
-}\r
-\r
-FCKRedoCommand.prototype.Execute = function()\r
-{\r
- FCKUndo.Redo() ;\r
-}\r
-\r
-FCKRedoCommand.prototype.GetState = function()\r
-{\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;\r
-}\r
-\r
-// ### Page Break\r
-var FCKPageBreakCommand = function()\r
-{\r
- this.Name = 'PageBreak' ;\r
-}\r
-\r
-FCKPageBreakCommand.prototype.Execute = function()\r
-{\r
- // Take an undo snapshot before changing the document\r
- FCKUndo.SaveUndoStep() ;\r
-\r
-// var e = FCK.EditorDocument.createElement( 'CENTER' ) ;\r
-// e.style.pageBreakAfter = 'always' ;\r
-\r
- // Tidy was removing the empty CENTER tags, so the following solution has\r
- // been found. It also validates correctly as XHTML 1.0 Strict.\r
- var e = FCK.EditorDocument.createElement( 'DIV' ) ;\r
- e.style.pageBreakAfter = 'always' ;\r
- e.innerHTML = '<span style="DISPLAY:none"> </span>' ;\r
-\r
- var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;\r
- var oRange = new FCKDomRange( FCK.EditorWindow ) ;\r
- oRange.MoveToSelection() ;\r
- var oSplitInfo = oRange.SplitBlock() ;\r
- oRange.InsertNode( oFakeImage ) ;\r
-\r
- FCK.Events.FireEvent( 'OnSelectionChange' ) ;\r
-}\r
-\r
-FCKPageBreakCommand.prototype.GetState = function()\r
-{\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return 0 ; // FCK_TRISTATE_OFF\r
-}\r
-\r
-// FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)\r
-var FCKUnlinkCommand = function()\r
-{\r
- this.Name = 'Unlink' ;\r
-}\r
-\r
-FCKUnlinkCommand.prototype.Execute = function()\r
-{\r
- // Take an undo snapshot before changing the document\r
- FCKUndo.SaveUndoStep() ;\r
-\r
- if ( FCKBrowserInfo.IsGeckoLike )\r
- {\r
- var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;\r
- // The unlink command can generate a span in Firefox, so let's do it our way. See #430\r
- if ( oLink )\r
- FCKTools.RemoveOuterTags( oLink ) ;\r
-\r
- return ;\r
- }\r
-\r
- FCK.ExecuteNamedCommand( this.Name ) ;\r
-}\r
-\r
-FCKUnlinkCommand.prototype.GetState = function()\r
-{\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- var state = FCK.GetNamedCommandState( this.Name ) ;\r
-\r
- // Check that it isn't an anchor\r
- if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
- {\r
- var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;\r
- var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;\r
- if ( bIsAnchor )\r
- state = FCK_TRISTATE_DISABLED ;\r
- }\r
-\r
- return state ;\r
-}\r
-\r
-var FCKVisitLinkCommand = function()\r
-{\r
- this.Name = 'VisitLink';\r
-}\r
-FCKVisitLinkCommand.prototype =\r
-{\r
- GetState : function()\r
- {\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- var state = FCK.GetNamedCommandState( 'Unlink' ) ;\r
-\r
- if ( state == FCK_TRISTATE_OFF )\r
- {\r
- var el = FCKSelection.MoveToAncestorNode( 'A' ) ;\r
- if ( !el.href )\r
- state = FCK_TRISTATE_DISABLED ;\r
- }\r
-\r
- return state ;\r
- },\r
-\r
- Execute : function()\r
- {\r
- var el = FCKSelection.MoveToAncestorNode( 'A' ) ;\r
- var url = el.getAttribute( '_fcksavedurl' ) || el.getAttribute( 'href', 2 ) ;\r
-\r
- // Check if it's a full URL.\r
- // If not full URL, we'll need to apply the BaseHref setting.\r
- if ( ! /:\/\//.test( url ) )\r
- {\r
- var baseHref = FCKConfig.BaseHref ;\r
- var parentWindow = FCK.GetInstanceObject( 'parent' ) ;\r
- if ( !baseHref )\r
- {\r
- baseHref = parentWindow.document.location.href ;\r
- baseHref = baseHref.substring( 0, baseHref.lastIndexOf( '/' ) + 1 ) ;\r
- }\r
-\r
- if ( /^\//.test( url ) )\r
- {\r
- try\r
- {\r
- baseHref = baseHref.match( /^.*:\/\/+[^\/]+/ )[0] ;\r
- }\r
- catch ( e )\r
- {\r
- baseHref = parentWindow.document.location.protocol + '://' + parentWindow.parent.document.location.host ;\r
- }\r
- }\r
-\r
- url = baseHref + url ;\r
- }\r
-\r
- if ( !window.open( url, '_blank' ) )\r
- alert( FCKLang.VisitLinkBlocked ) ;\r
- }\r
-} ;\r
-\r
-// FCKSelectAllCommand\r
-var FCKSelectAllCommand = function()\r
-{\r
- this.Name = 'SelectAll' ;\r
-}\r
-\r
-FCKSelectAllCommand.prototype.Execute = function()\r
-{\r
- if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
- {\r
- FCK.ExecuteNamedCommand( 'SelectAll' ) ;\r
- }\r
- else\r
- {\r
- // Select the contents of the textarea\r
- var textarea = FCK.EditingArea.Textarea ;\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- textarea.createTextRange().execCommand( 'SelectAll' ) ;\r
- }\r
- else\r
- {\r
- textarea.selectionStart = 0 ;\r
- textarea.selectionEnd = textarea.value.length ;\r
- }\r
- textarea.focus() ;\r
- }\r
-}\r
-\r
-FCKSelectAllCommand.prototype.GetState = function()\r
-{\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return FCK_TRISTATE_OFF ;\r
-}\r
-\r
-// FCKPasteCommand\r
-var FCKPasteCommand = function()\r
-{\r
- this.Name = 'Paste' ;\r
-}\r
-\r
-FCKPasteCommand.prototype =\r
-{\r
- Execute : function()\r
- {\r
- if ( FCKBrowserInfo.IsIE )\r
- FCK.Paste() ;\r
- else\r
- FCK.ExecuteNamedCommand( 'Paste' ) ;\r
- },\r
-\r
- GetState : function()\r
- {\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return FCK.GetNamedCommandState( 'Paste' ) ;\r
- }\r
-} ;\r
-\r
-// FCKRuleCommand\r
-var FCKRuleCommand = function()\r
-{\r
- this.Name = 'Rule' ;\r
-}\r
-\r
-FCKRuleCommand.prototype =\r
-{\r
- Execute : function()\r
- {\r
- FCKUndo.SaveUndoStep() ;\r
- FCK.InsertElement( 'hr' ) ;\r
- },\r
-\r
- GetState : function()\r
- {\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return FCK.GetNamedCommandState( 'InsertHorizontalRule' ) ;\r
- }\r
-} ;\r
-\r
-// FCKCutCopyCommand\r
-var FCKCutCopyCommand = function( isCut )\r
-{\r
- this.Name = isCut ? 'Cut' : 'Copy' ;\r
-}\r
-\r
-FCKCutCopyCommand.prototype =\r
-{\r
- Execute : function()\r
- {\r
- var enabled = false ;\r
-\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- // The following seems to be the only reliable way to detect that\r
- // cut/copy is enabled in IE. It will fire the oncut/oncopy event\r
- // only if the security settings enabled the command to execute.\r
-\r
- var onEvent = function()\r
- {\r
- enabled = true ;\r
- } ;\r
-\r
- var eventName = 'on' + this.Name.toLowerCase() ;\r
-\r
- FCK.EditorDocument.body.attachEvent( eventName, onEvent ) ;\r
- FCK.ExecuteNamedCommand( this.Name ) ;\r
- FCK.EditorDocument.body.detachEvent( eventName, onEvent ) ;\r
- }\r
- else\r
- {\r
- try\r
- {\r
- // Other browsers throw an error if the command is disabled.\r
- FCK.ExecuteNamedCommand( this.Name ) ;\r
- enabled = true ;\r
- }\r
- catch(e){}\r
- }\r
-\r
- if ( !enabled )\r
- alert( FCKLang[ 'PasteError' + this.Name ] ) ;\r
- },\r
-\r
- GetState : function()\r
- {\r
- // Strangely, the Cut command happens to have the correct states for\r
- // both Copy and Cut in all browsers.\r
- return FCK.EditMode != FCK_EDITMODE_WYSIWYG ?\r
- FCK_TRISTATE_DISABLED :\r
- FCK.GetNamedCommandState( 'Cut' ) ;\r
- }\r
-};\r
-\r
-var FCKAnchorDeleteCommand = function()\r
-{\r
- this.Name = 'AnchorDelete' ;\r
-}\r
-\r
-FCKAnchorDeleteCommand.prototype =\r
-{\r
- Execute : function()\r
- {\r
- if (FCK.Selection.GetType() == 'Control')\r
- {\r
- FCK.Selection.Delete();\r
- }\r
- else\r
- {\r
- var oFakeImage = FCK.Selection.GetSelectedElement() ;\r
- if ( oFakeImage )\r
- {\r
- if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckanchor') )\r
- oAnchor = FCK.GetRealElement( oFakeImage ) ;\r
- else\r
- oFakeImage = null ;\r
- }\r
-\r
- //Search for a real anchor\r
- if ( !oFakeImage )\r
- {\r
- oAnchor = FCK.Selection.MoveToAncestorNode( 'A' ) ;\r
- if ( oAnchor )\r
- FCK.Selection.SelectNode( oAnchor ) ;\r
- }\r
-\r
- // If it's also a link, then just remove the name and exit\r
- if ( oAnchor.href.length != 0 )\r
- {\r
- oAnchor.removeAttribute( 'name' ) ;\r
- // Remove temporary class for IE\r
- if ( FCKBrowserInfo.IsIE )\r
- oAnchor.className = oAnchor.className.replace( FCKRegexLib.FCK_Class, '' ) ;\r
- return ;\r
- }\r
-\r
- // We need to remove the anchor\r
- // If we got a fake image, then just remove it and we're done\r
- if ( oFakeImage )\r
- {\r
- oFakeImage.parentNode.removeChild( oFakeImage ) ;\r
- return ;\r
- }\r
- // Empty anchor, so just remove it\r
- if ( oAnchor.innerHTML.length == 0 )\r
- {\r
- oAnchor.parentNode.removeChild( oAnchor ) ;\r
- return ;\r
- }\r
- // Anchor with content, leave the content\r
- FCKTools.RemoveOuterTags( oAnchor ) ;\r
- }\r
- if ( FCKBrowserInfo.IsGecko )\r
- FCK.Selection.Collapse( true ) ;\r
- },\r
-\r
- GetState : function()\r
- {\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
- return FCK.GetNamedCommandState( 'Unlink') ;\r
- }\r
-};\r
-\r
-var FCKDeleteDivCommand = function()\r
-{\r
-}\r
-FCKDeleteDivCommand.prototype =\r
-{\r
- GetState : function()\r
- {\r
- if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
- return FCK_TRISTATE_DISABLED ;\r
-\r
- var node = FCKSelection.GetParentElement() ;\r
- var path = new FCKElementPath( node ) ;\r
- return path.BlockLimit && path.BlockLimit.nodeName.IEquals( 'div' ) ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;\r
- },\r
-\r
- Execute : function()\r
- {\r
- // Create an undo snapshot before doing anything.\r
- FCKUndo.SaveUndoStep() ;\r
-\r
- // Find out the nodes to delete.\r
- var nodes = FCKDomTools.GetSelectedDivContainers() ;\r
-\r
- // Remember the current selection position.\r
- var range = new FCKDomRange( FCK.EditorWindow ) ;\r
- range.MoveToSelection() ;\r
- var bookmark = range.CreateBookmark() ;\r
-\r
- // Delete the container DIV node.\r
- for ( var i = 0 ; i < nodes.length ; i++)\r
- FCKDomTools.RemoveNode( nodes[i], true ) ;\r
-\r
- // Restore selection.\r
- range.MoveToBookmark( bookmark ) ;\r
- range.Select() ;\r
- }\r
-} ;\r
-\r
-// FCKRuleCommand\r
-var FCKNbsp = function()\r
-{\r
- this.Name = 'Non Breaking Space' ;\r
-}\r
-\r
-FCKNbsp.prototype =\r
-{\r
- Execute : function()\r
- {\r
- FCK.InsertHtml( ' ' ) ;\r
- },\r
-\r
- GetState : function()\r
- {\r
- return ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_DISABLED : FCK_TRISTATE_OFF ) ;\r
- }\r
-} ;\r