fckeditor 插件实例 制作步骤
更新时间:2009年06月19日 18:13:23 作者:
一:基于对话框的插件:一步一步创建基于对话框的fck插件。
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
以创建一个简单的超级链接为例。可以从已经存在的placeholder插件的目录作为基本的骨架。
1. 命名插件名称为:"InsertLink". ,并建立同名的目录,并且在InsertLink目录下创建一个Lang的目录,lang目录下至少有一个文件en.js。该文件中至少要有按钮和对话框标题的国际化信息,比如:
FCKLang.InsertLinkBtn = 'Insert/Edit Link' ; //按钮的标题
FCKLang.InsertLinkDlgTitle = 'Link Properties' ; //对话框的标题
2:图片,在InsertLink文件夹中添加图片文件,最好将图片文件命名为和插件名一样的名称。图片的大小要求是20*21,并且是透明的。
3:javascript:
添加fckplugin.js文件到InsertLink目录。
注册相关命令:
注册命令的方法是FCKCommands.RegisterCommand(命令名称,对话框命令)
创建对话框命令的格式:new FCKDialogCommand( 命令名称, 对话框标题,url路径, 宽度,高度)
FCKCommands.RegisterCommand( 'InsertLink', new FCKDialogCommand( 'InsertLink', FCKLang.InsertLinkDlgTitle,
FCKPlugins.Items['InsertLink'].Path + 'fck_InsertLink.html', 340, 200 ) ) ;
// 创建工具栏按钮 new FCKToolbarButton( 按钮名称, 按钮标题 ) ;
var oInsertLinkItem = new FCKToolbarButton( 'InsertLink', FCKLang.InsertLinkBtn ) ;
oInsertLinkItem.IconPath = FCKPlugins.Items['InsertLink'].Path + 'InsertLink.gif' ;
FCKToolbarItems.RegisterItem( 'InsertLink', oInsertLinkItem ) ;
//创建用于所有InsertLink操作的对象
var FCKInsertLink = new Object() ;
//在当前的选择上插入一个超级链接
// 这个添加的方法将在弹出窗口点击ok按钮时被调用。
// 该方法将会接收从对话框中传来的值。
FCKInsertLink.Add = function( linkname, caption )
{
if(linkname.substr(0,4) != "http" && linkname.substr(0,4) != "HTTP")
linkname = "http://"+linkname ;
FCK.InsertHtml("<a href='"+linkname+"'>"+caption+"</a>") ;
}
4:html
在InsertLink目录下添加请求的文件。
请求文件的模板代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Link Properties</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta content="noindex, nofollow" name="robots">
<script language="javascript">
var oEditor = window.parent.InnerDialogLoaded() ;
var FCK = oEditor.FCK ;
var FCKLang = oEditor.FCKLang ;
var FCKInsertLink = oEditor.FCKInsertLink ;
window.onload = function ()
{
LoadSelected() ; //see function below
window.parent.SetOkButton( true ) ;
}
//从编辑器中得到当前的被选择的元素,有以下两种方法:
//1. 可用于image等元素的选择。
//var eSelected = oEditor.FCKSelection.GetSelectedElement() ;
//2. 由于有内部文本的元素
var eSelected = FCK.Selection.MoveToAncestorNode( 'A' )
if ( eSelected )
FCK.Selection.MoveToNode( eSelected ) ;
//如果超级练级被选择,那么显示超级链接的属性
function LoadSelected()
{
if ( !eSelected )
return ;
txthref.value = eSelected.href ;
txtCaption.value = eSelected.innerText ;
//适合于第一种选择操作的代码:
// if ( eSelected.tagName == 'IMG' ) {
// -- code for setting dialog values -- }
// else
// eSelected == null ; //this will replace the current selection if not the right type
}
//点击ok按钮发生的操作
function Ok()
{
if ( document.getElementById('txthref').value.length > 0 )
FCKInsertLink.Add( txthref.value, txtCaption.value ) ;
return true ;
}
</script>
</head>
<body scroll="no" style="OVERFLOW: hidden">
<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td>
<table cellSpacing="0" cellPadding="0" align="center" border="0">
<tr>
<td>
Type the URL for the link<br>
<input id="txthref" type="text"><br>
Type the caption for the link<br>
<input id="txtCaption" type="text">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<!-- End Code -->
5:编辑fckconfig.js文件,并加入下列代码,注册插件。
FCKConfig.Plugins.Add( 'InsertLink', 'en' ) ;
//在工具栏集合中定义命令名称。
FCKConfig.ToolbarSets["Default"] = [ , ['InsertLink']
1. 命名插件名称为:"InsertLink". ,并建立同名的目录,并且在InsertLink目录下创建一个Lang的目录,lang目录下至少有一个文件en.js。该文件中至少要有按钮和对话框标题的国际化信息,比如:
FCKLang.InsertLinkBtn = 'Insert/Edit Link' ; //按钮的标题
FCKLang.InsertLinkDlgTitle = 'Link Properties' ; //对话框的标题
2:图片,在InsertLink文件夹中添加图片文件,最好将图片文件命名为和插件名一样的名称。图片的大小要求是20*21,并且是透明的。
3:javascript:
添加fckplugin.js文件到InsertLink目录。
注册相关命令:
注册命令的方法是FCKCommands.RegisterCommand(命令名称,对话框命令)
创建对话框命令的格式:new FCKDialogCommand( 命令名称, 对话框标题,url路径, 宽度,高度)
FCKCommands.RegisterCommand( 'InsertLink', new FCKDialogCommand( 'InsertLink', FCKLang.InsertLinkDlgTitle,
FCKPlugins.Items['InsertLink'].Path + 'fck_InsertLink.html', 340, 200 ) ) ;
// 创建工具栏按钮 new FCKToolbarButton( 按钮名称, 按钮标题 ) ;
var oInsertLinkItem = new FCKToolbarButton( 'InsertLink', FCKLang.InsertLinkBtn ) ;
oInsertLinkItem.IconPath = FCKPlugins.Items['InsertLink'].Path + 'InsertLink.gif' ;
FCKToolbarItems.RegisterItem( 'InsertLink', oInsertLinkItem ) ;
//创建用于所有InsertLink操作的对象
var FCKInsertLink = new Object() ;
//在当前的选择上插入一个超级链接
// 这个添加的方法将在弹出窗口点击ok按钮时被调用。
// 该方法将会接收从对话框中传来的值。
FCKInsertLink.Add = function( linkname, caption )
{
if(linkname.substr(0,4) != "http" && linkname.substr(0,4) != "HTTP")
linkname = "http://"+linkname ;
FCK.InsertHtml("<a href='"+linkname+"'>"+caption+"</a>") ;
}
4:html
在InsertLink目录下添加请求的文件。
请求文件的模板代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Link Properties</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta content="noindex, nofollow" name="robots">
<script language="javascript">
var oEditor = window.parent.InnerDialogLoaded() ;
var FCK = oEditor.FCK ;
var FCKLang = oEditor.FCKLang ;
var FCKInsertLink = oEditor.FCKInsertLink ;
window.onload = function ()
{
LoadSelected() ; //see function below
window.parent.SetOkButton( true ) ;
}
//从编辑器中得到当前的被选择的元素,有以下两种方法:
//1. 可用于image等元素的选择。
//var eSelected = oEditor.FCKSelection.GetSelectedElement() ;
//2. 由于有内部文本的元素
var eSelected = FCK.Selection.MoveToAncestorNode( 'A' )
if ( eSelected )
FCK.Selection.MoveToNode( eSelected ) ;
//如果超级练级被选择,那么显示超级链接的属性
function LoadSelected()
{
if ( !eSelected )
return ;
txthref.value = eSelected.href ;
txtCaption.value = eSelected.innerText ;
//适合于第一种选择操作的代码:
// if ( eSelected.tagName == 'IMG' ) {
// -- code for setting dialog values -- }
// else
// eSelected == null ; //this will replace the current selection if not the right type
}
//点击ok按钮发生的操作
function Ok()
{
if ( document.getElementById('txthref').value.length > 0 )
FCKInsertLink.Add( txthref.value, txtCaption.value ) ;
return true ;
}
</script>
</head>
<body scroll="no" style="OVERFLOW: hidden">
<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td>
<table cellSpacing="0" cellPadding="0" align="center" border="0">
<tr>
<td>
Type the URL for the link<br>
<input id="txthref" type="text"><br>
Type the caption for the link<br>
<input id="txtCaption" type="text">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<!-- End Code -->
5:编辑fckconfig.js文件,并加入下列代码,注册插件。
FCKConfig.Plugins.Add( 'InsertLink', 'en' ) ;
//在工具栏集合中定义命令名称。
FCKConfig.ToolbarSets["Default"] = [ , ['InsertLink']
相关文章
整合ckeditor+ckfinder,解决上传文件路径问题
现在fckeditor已经改名为ckeditor,上传控件也分离为ckfinder,按照说明文档的默认配置会出现上传路径不正确的情况,因为我们的网站可以通过定义默认网站、虚拟目录、以及放在网站的子目录下进行访问2011-11-11eWebEditor 辑器按钮失效 IE8下eWebEditor编辑器无法使用的解决方法
最近我把IE浏览器更新到了IE8.0,在用eWebEditor在线HTML文本编辑器的时候点击eWebEditor上的所有编辑按钮都没用,只看到浏览器状态栏左下角显示网页上有错误,于是上网查了一下。终于找到解决的方法,测试后正常。2009-06-06CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入图片)
CKEditor 是著名的 HTML 编辑器,IBM、Oracle、Adobe 等都在用。CKEditor 创建于 2003 年,其前身为 FCKEditor,在 2009 年的时候把“F”去掉了,更名为 CKEditor。2010-03-03
最新评论