在彈出窗口上訪問編輯器:
1、如何在編輯器中插入文本:
前置約定:
插件名:insertvariables
插件位置:editor/plugins/insertvariables/
//創建自己的命令,不采用FCKDialogCommand的目的是FCKDialogCommand使用的是fck的缺省布局。
var InsertVariableCommand=function(){
};
InsertVariableCommand.prototype.Execute=function(){
}
//讓按鈕不能點擊。
InsertVariableCommand.GetState=function() {
??????? return FCK_TRISTATE_OFF; }
//打開彈出窗口
InsertVariableCommand.Execute=function() {
??????? window.open('insertVariable.do', 'insertVariable', 'width=500,height=400,scrollbars=no,scrolling=no,location=no,toolbar=no');
}
//注冊命令:
FCKCommands.RegisterCommand('Insert_Variables', InsertVariableCommand );
//注冊按鈕
var oInsertVariables = new FCKToolbarButton('Insert_Variables', 'insert variable');
oInsertVariables.IconPath = FCKConfig.PluginsPath + 'insertvariables/variable.gif';
FCKToolbarItems.RegisterItem( 'Insert_Variables', oInsertVariables );
//插入變量的請求頁面:insertVariable.do
<html><head> etc...
<script language="javascript">
<!--
var variable = null;
var FCK = window.opener.FCK;
function ok() {
if(variable != null) {
FCK.Focus();
????????????????????????//只在ie中有效
var B = FCK.EditorDocument.selection.createRange();
B.text = variable;
}
window.close();
}
//-->
</script>
</head>
<body>
etc..
<a href="#" onClick="variable='this is a test'; ok();">insert text</a>
</body>
</html>
//在fckconfig.js文件中加入以下字段
FCKConfig.Plugins.Add( 'insertvariables' ) ;
FCKConfig.ToolbarSets["myToolbar"] = [
['Bold','Italic','Underline'],['Insert_Variables']
] ;
2、關聯上下文菜單選項:
將插件的command注冊到上下文菜單中:
FCK.ContextMenu.RegisterListener( {
AddItems : function( menu, tag, tagName )
{
// 符合條件顯示:if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) )
if ( tagName == 'SPAN' && tag._fckplaceholder )
{
// 顯示分隔符
menu.AddSeparator() ;
// 需要注冊命令名,標題,以及圖片路徑。
???menu.AddItem( 'placeholder', FCKLang.PlaceholderDlgTitle, oPlaceholderItem.IconPath ) ;
}
}}
);
posted on 2007-04-10 20:21
不做浮躁的人 閱讀(1197)
評論(0) 編輯 收藏