我有一个使用 FCKEditor 的网站。我想制作一个非常简单的插件:当用户选择文本然后点击 MyPluginIcon 时,编辑器会在具有特定类的 span 标记中包围文本。
所以它就像粗体或斜体按钮,但用于:
<span class="blah">EtcEtc</span>
我远不是一个JS高手,所以一直在找一个插件来copy。我查看了 FCK wiki,但我发现的所有插件都非常复杂(文件浏览器等)。你知道一个 super 简单的 FCK 插件吗?
谢谢!
最佳答案
回答我自己的问题!希望将来如果有人发现它会有所帮助。
我使用了这里的基本文件: http://www.iondev.lu/fckeditor/netnoi.txt
我找到并用我自己的名字替换了“netnoi”,并取消注释图标行以制作一个图标 (16x16)。
以及如何从这里安装它的说明: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins
一定要检查插件目录是否正确——在 drupal 中,插件文件夹不同于默认的 FCK 安装。
编辑:显然 netnoi.txt 已经丢失。这是我使用的:
/***
* Create blank command
*/
var FCKPixelCaps_command = function()
{
}
/***
* Add Execute prototype
*/
FCKPixelCaps_command.prototype.Execute = function()
{
// get whatever is selected in the FCKeditor window
var selection = FCK.EditorDocument.getSelection();
// if there is a selection, add tags around it
if(selection.length > 0)
{
FCK.InsertHtml('<span class="caps">' + selection + '</span>');
} else {
// for debugging reasons, I added this alert so I see if nothing is selected
alert('nothing selected');
}
}
/***
* Add GetState prototype
* - This is one of the lines I can't explain
*/
FCKPixelCaps_command.prototype.GetState = function()
{
return;
}
// register the command so it can be use by a button later
FCKCommands.RegisterCommand( 'PixelCaps_command' , new FCKPixelCaps_command() ) ;
/***
* Create the toolbar button.
*/
// create a button with the label "Netnoi" that calls the netnoi_command
var oPixelCaps = new FCKToolbarButton( 'PixelCaps_command', 'Pixels & Pulp Caps' ) ;
oPixelCaps.IconPath = FCKConfig.PluginsPath + 'PixelCaps/caps.gif' ;
// register the item so it can added to a toolbar
FCKToolbarItems.RegisterItem( 'PixelCaps', oPixelCaps ) ;
关于javascript - FCKEditor - 如何制作一个简单的插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/654472/