Hello, I'm trying to make some "quote selected text" button to insert any selected text on the page to the FCKeditor.
My problem is that I want to keep the 'blockquote' button behavior. So one button must do the following things :
1) Insert any selected text on the page to the FCKeditor in [blockquote] tags
2) Quote selected text in the FCKeditor (as 'blockquote' button)
3) Unquote current line or selected text if it is a quote in FCKeditor (as 'blockquote' button)
I have already done that. But my problem is that my button is not firing (FCK_TRISTATE_ON) when cursor is in the [blockquote] tag in the FCKeditor.
Here is my code. I took the plugin 'InsertHtml' by Paul Moers (http://www.saulmade.nl/FCKeditor/FCKPlugins.php) as a base.
GetState function is just a copypaste from '/_source/commandclasses/fckblockquotecommand.js' but it seems not working (?)
/* * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * File Name: fckplugin.js * Plugin to add some preset HTML * * File Authors: * Paul Moers (http://www.saulmade.nl/FCKeditor/FCKPlugins.php) */ // insertHtmlObject constructor var insertHtmlToolbarCommand = function() { } // register the command FCKCommands.RegisterCommand('insertHtml', new insertHtmlToolbarCommand()); // create the toolbar button var insertHtmlButton = new FCKToolbarButton('insertHtml', FCKConfig.insertHtml_buttonTooltip || FCKLang.inserHTML_buttonTooltip); insertHtmlButton.IconPath = FCKPlugins.Items['insertHtml'].Path + 'images/toolbarIcon_default.gif'; // or pick any other in folder 'images' FCKToolbarItems.RegisterItem('insertHtml', insertHtmlButton); // manage the plugins' button behavior /* insertHtmlToolbarCommand.prototype.GetState = function() { return FCK_TRISTATE_OFF; } */ insertHtmlToolbarCommand.prototype.GetState = function() { // Disabled if not WYSIWYG. if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG || ! FCK.EditorWindow ) return FCK_TRISTATE_DISABLED ; var path = new FCKElementPath( FCKSelection.GetBoundaryParentElement( true ) ) ; var firstBlock = path.Block || path.BlockLimit ; if ( !firstBlock || firstBlock.nodeName.toLowerCase() == 'body' ) return FCK_TRISTATE_OFF ; // See if the first block has a blockquote parent. for ( var i = 0 ; i < path.Elements.length ; i++ ) { if ( path.Elements[i].nodeName.IEquals( 'blockquote' ) ) return FCK_TRISTATE_ON ; } return FCK_TRISTATE_OFF ; } // insertHtml's button click function insertHtmlToolbarCommand.prototype.Execute = function() { if (FCKConfig.insertHtml_showDialog) { var dialog = new FCKDialogCommand('insertHtml', FCKLang.insertHtml_dialogTitle, FCKPlugins.Items['insertHtml'].Path + 'insertHtml.html', 200, 100); dialog.Execute(); } else { var txt = getSelectedText(); if(txt == ''){ //var selection = (FCK.EditorWindow.getSelection ? FCK.EditorWindow.getSelection() : FCK.EditorDocument.selection); //txt = getSelectionHTML(selection, FCK); FCK.Commands.GetCommand('Blockquote').Execute(); } if(txt != ''){ FCK.InsertHtml('<blockquote><div>'+txt+'</div></blockquote>'); } FCK.EditorWindow.parent.FCKUndo.SaveUndoStep(); } } // get selection text from anywhere on the page function getSelectedText(){ var containerWindow = FCK.EditorWindow.parent.parent; var containerDocument = containerWindow.document; var txt = '{default value}'; if (containerWindow.getSelection){ txt = containerWindow.getSelection(); } else if (containerDocument.getSelection) { txt = containerDocument.getSelection(); } else if (containerDocument.selection) { txt = containerDocument.selection.createRange().text; } return txt; } // get HTML from selection function getSelectionHTML(selection, editorInstance) { var range = (editorInstance.EditorWindow.parent.FCKBrowserInfo.IsIE ? selection.createRange() : selection.getRangeAt(selection.rangeCount - 1).cloneRange()); if (editorInstance.EditorWindow.parent.FCKBrowserInfo.IsIE) { return range.htmlText; } else { var clonedSelection = range.cloneContents(); var div = document.createElement('div'); div.appendChild(clonedSelection); return div.innerHTML; } }
Re: some problem with a TRISTATE
I think 6th parameter 'contextSensitive' of a FCKToolbarButton(...) must be set to 'true'
So the code that works