fckeditor 插件實例 制作步驟
更新時間:2009年06月19日 18:13:23 作者:
一:基于對話框的插件:一步一步創(chuàng)建基于對話框的fck插件。
以創(chuàng)建一個簡單的超級鏈接為例??梢詮囊呀?jīng)存在的placeholder插件的目錄作為基本的骨架。
1. 命名插件名稱為:"InsertLink". ,并建立同名的目錄,并且在InsertLink目錄下創(chuàng)建一個Lang的目錄,lang目錄下至少有一個文件en.js。該文件中至少要有按鈕和對話框標題的國際化信息,比如:
FCKLang.InsertLinkBtn = 'Insert/Edit Link' ; //按鈕的標題
FCKLang.InsertLinkDlgTitle = 'Link Properties' ; //對話框的標題
2:圖片,在InsertLink文件夾中添加圖片文件,最好將圖片文件命名為和插件名一樣的名稱。圖片的大小要求是20*21,并且是透明的。
3:javascript:
添加fckplugin.js文件到InsertLink目錄。
注冊相關命令:
注冊命令的方法是FCKCommands.RegisterCommand(命令名稱,對話框命令)
創(chuàng)建對話框命令的格式:new FCKDialogCommand( 命令名稱, 對話框標題,url路徑, 寬度,高度)
FCKCommands.RegisterCommand( 'InsertLink', new FCKDialogCommand( 'InsertLink', FCKLang.InsertLinkDlgTitle,
FCKPlugins.Items['InsertLink'].Path + 'fck_InsertLink.html', 340, 200 ) ) ;
// 創(chuàng)建工具欄按鈕 new FCKToolbarButton( 按鈕名稱, 按鈕標題 ) ;
var oInsertLinkItem = new FCKToolbarButton( 'InsertLink', FCKLang.InsertLinkBtn ) ;
oInsertLinkItem.IconPath = FCKPlugins.Items['InsertLink'].Path + 'InsertLink.gif' ;
FCKToolbarItems.RegisterItem( 'InsertLink', oInsertLinkItem ) ;
//創(chuàng)建用于所有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=utf-8">
<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按鈕發(fā)生的操作
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目錄下創(chuàng)建一個Lang的目錄,lang目錄下至少有一個文件en.js。該文件中至少要有按鈕和對話框標題的國際化信息,比如:
FCKLang.InsertLinkBtn = 'Insert/Edit Link' ; //按鈕的標題
FCKLang.InsertLinkDlgTitle = 'Link Properties' ; //對話框的標題
2:圖片,在InsertLink文件夾中添加圖片文件,最好將圖片文件命名為和插件名一樣的名稱。圖片的大小要求是20*21,并且是透明的。
3:javascript:
添加fckplugin.js文件到InsertLink目錄。
注冊相關命令:
注冊命令的方法是FCKCommands.RegisterCommand(命令名稱,對話框命令)
創(chuàng)建對話框命令的格式:new FCKDialogCommand( 命令名稱, 對話框標題,url路徑, 寬度,高度)
FCKCommands.RegisterCommand( 'InsertLink', new FCKDialogCommand( 'InsertLink', FCKLang.InsertLinkDlgTitle,
FCKPlugins.Items['InsertLink'].Path + 'fck_InsertLink.html', 340, 200 ) ) ;
// 創(chuàng)建工具欄按鈕 new FCKToolbarButton( 按鈕名稱, 按鈕標題 ) ;
var oInsertLinkItem = new FCKToolbarButton( 'InsertLink', FCKLang.InsertLinkBtn ) ;
oInsertLinkItem.IconPath = FCKPlugins.Items['InsertLink'].Path + 'InsertLink.gif' ;
FCKToolbarItems.RegisterItem( 'InsertLink', oInsertLinkItem ) ;
//創(chuàng)建用于所有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=utf-8">
<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按鈕發(fā)生的操作
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,解決上傳文件路徑問題
現(xiàn)在fckeditor已經(jīng)改名為ckeditor,上傳控件也分離為ckfinder,按照說明文檔的默認配置會出現(xiàn)上傳路徑不正確的情況,因為我們的網(wǎng)站可以通過定義默認網(wǎng)站、虛擬目錄、以及放在網(wǎng)站的子目錄下進行訪問2011-11-11eWebEditor 輯器按鈕失效 IE8下eWebEditor編輯器無法使用的解決方法
最近我把IE瀏覽器更新到了IE8.0,在用eWebEditor在線HTML文本編輯器的時候點擊eWebEditor上的所有編輯按鈕都沒用,只看到瀏覽器狀態(tài)欄左下角顯示網(wǎng)頁上有錯誤,于是上網(wǎng)查了一下。終于找到解決的方法,測試后正常。2009-06-06CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入圖片)
CKEditor 是著名的 HTML 編輯器,IBM、Oracle、Adobe 等都在用。CKEditor 創(chuàng)建于 2003 年,其前身為 FCKEditor,在 2009 年的時候把“F”去掉了,更名為 CKEditor。2010-03-03