一:外掛程式的目錄結構
外掛程式目錄的名稱必須和外掛程式的名稱一樣,而且目錄裡面必須包含一個fckplugin.js檔案。可選包含一個lang目錄用來實現介面的國際化。每一個檔案定義一種語言,檔案名稱不包含.js,用FCKConfig.Plugins.Add()註冊。如果實現的外掛程式命令沒有介面,也可以不需要支援任何語言。
比如:findreplace外掛程式的目錄結構如下:
/editor/plugins/findreplace/fckplugin.js
/editor/plugins/findreplace/lang/en.js
/editor/plugins/findreplace/lang/zh.js
在fckplugin.js檔案中定義你的外掛程式,同時也應該註冊改命令,以及建立一個工具列按鈕。
註冊代碼說明:
複製代碼 代碼如下://註冊命令,RegisterCommand(命令名,命令)
FCKCommands.RegisterCommand(
'My_Find',
new FCKDialogCommand(
FCKLang['DlgMyFindTitle'],
FCKLang['DlgMyFindTitle'],
FCKConfig.PluginsPath + 'findreplace/find.html', 340, 170));
FCKCommands.RegisterCommand('My_Replace',
new FCKDialogCommand(
FCKLang['DlgMyReplaceTitle'],
FCKLang['DlgMyReplaceTitle'],
FCKConfig.PluginsPath + 'findreplace/replace.html', 340, 200)) ;
//建立工具列按鈕,現建立,再註冊。
var oFindItem = new FCKToolbarButton('My_Find', FCKLang['DlgMyFindTitle']);
oFindItem.IconPath = FCKConfig.PluginsPath + 'findreplace/find.gif' ;
FCKToolbarItems.RegisterItem( 'My_Find', oFindItem ) ;
var oreplaceItem = new FCKToolbarButton( 'My_Replace', FCKLang['DlgMyReplaceTitle']);
oreplaceItem.IconPath = FCKConfig.PluginsPath + 'findreplace/replace.gif';
FCKToolbarItems.RegisterItem('My_Replace', oreplaceItem);
二:安裝外掛程式:
安裝前把解壓的包拷貝到editor/plugins目錄下,然後按下列步驟進行:
1、先確定按鈕在工具列的位置
最好在定製的設定檔中,新寫一個工具列來包含新的外掛程式。
定製設定檔:複製代碼 代碼如下:FCKConfig.ToolbarSets['PluginTest'] = [
['Source'],
['Placeholder'],
['My_Find', 'My_Replace'],
['Table','-',
'TableInsertRow', 'TableDeleteRows',
'TableInsertColumn', 'TableDeleteColumns',
'TableInsertCell', 'TableDeleteCells',
'TableMergeCells', 'TableSplitCell'
],
['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About']
] ;
2:添加外掛程式同樣,可以直接在定製檔案中添加外掛程式。可以直接把外掛程式放置到預設目錄下,或者在FCKConfig.Plugins.Add方法裡面的第三個參數指定外掛程式所在的位置。
//程式碼分析:
引用內容 複製代碼 代碼如下:FCKConfig.Plugins.Add( pluginName, availableLanguages, pathToPlugin )
pluginName: 外掛程式名稱或者外掛程式目錄名稱.
availableLanguages: 逗號分割的可用語言列表.
pathToPlugin: 絕對路徑,指外掛程式的所佔目錄,包括外掛程式本身一層目錄
在預設位置添加外掛程式
引用內容 複製代碼 代碼如下:FCKConfig.Plugins.Add( 'findreplace', 'en,it' ) ;
在其他位置添加外掛程式,在add方法傳遞外掛程式的絕對路徑。
引用內容 複製代碼 代碼如下:FCKConfig.PluginsPath = FCKConfig.BasePath.substr(0, FCKConfig.BasePath.length - 7) + '_samples/_plugins/' ;
var sOtherPluginPath = FCKConfig.BasePath.substr(0, FCKConfig.BasePath.length - 7) + 'editor/plugins/' ;
FCKConfig.Plugins.Add( 'placeholder', 'en,it', sOtherPluginPath ) ;
FCKConfig.Plugins.Add( 'tablecommands', null, sOtherPluginPath ) ;
http://www.jb51.net/article/18660.htm