fckeditor 的配置与使用

一、配置fckconfig.js文件:

......

//缺省语言:

FCKConfig.AutoDetectLanguage = false ;
FCKConfig.DefaultLanguage  = 'zh-cn' ;

//字体设置:

FCKConfig.FontNames  = '宋体/宋体;黑体/黑体;仿宋/仿宋;楷体/楷体;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

//以换行代替分段:

FCKConfig.EnterMode = 'br' ;

//打开上传文件功能:

//浏览上传:
FCKConfig.LinkBrowser = true ;
FCKConfig.ImageBrowser = true ;
FCKConfig.FlashBrowser = true ;
快速上传:
FCKConfig.LinkUpload = true ;
FCKConfig.ImageUpload = true ;
FCKConfig.FlashUpload = true ;

//上传所使用的语言

var _FileBrowserLanguage = 'php' ;

var _QuickUploadLanguage = 'php' ;

......

二、上传配置(php):config.php

//打开上传功能

$Config['Enabled'] = true ;

//设置文件存放路径:

 $Config['UserFilesPath'] = '/userfiles/'.date('Y/m/') ;

//修改各类文件上传及浏览路径(file,image,flash...):

//浏览路径

$Config['FileTypesPath']['File']  = $Config['UserFilesPath'] . 'file/' ;

//上传路径

$Config['QuickUploadPath']['File']  = $Config['UserFilesPath'] . 'file/' ;

......

三、修改php目录下的commands.php、util.php文件:

//commands.php:修改 move_uploaded_file( $oFile['tmp_name'], $sFilePath )为

move_uploaded_file( $oFile['tmp_name'], iconv("utf-8","gbk",$sFilePath) ) ; 

//util.php:修改 return ( utf8_encode( htmlspecialchars( $value ) ) )为

return iconv("GBK", "UTF-8", htmlspecialchars( $value ));

四、 fckeditor的API操作

1、向编辑器插入文本:

function InsertHTML() {  // Get the editor instance that we want to interact with.  var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 // Check the active editing mode.  if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )  

{   // Insert the desired HTML.   

   oEditor.InsertHtml( '- This is some <a href="/Test1.html">sample<\/a> HTML -' ) ;  

}

 else  

 alert( 'You must be on WYSIWYG mode!' ) ;

2、取得编辑器内容(XHTML): 

function GetContents() {  

// Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 // Get the editor contents in XHTML.

 alert( oEditor.GetXHTML( true ) ) ;  // "true" means you want it formatted.

}

3、取得编辑器内容(innerHTML):

function GetInnerHTML() {  

// Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 alert( oEditor.EditorDocument.body.innerHTML ) ;

}

4、设置编辑器内容:

function SetContents() {  

// Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 // Set the editor contents (replace the actual one).  

oEditor.SetData( 'This is the <b>new content<\/b> I want in the editor.' ) ;

}

5、取得编辑器内容长度:

function GetLength() {  

// This functions shows that you can interact directly with the editor area  

// DOM. In this way you have the freedom to do anything you want with it.

 // Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 // Get the Editor Area DOM (Document object).  

var oDOM = oEditor.EditorDocument ;

 var iLength ;

 // The are two diffent ways to get the text (without HTML markups).  

// It is browser specific.

 if ( document.all )  // If Internet Explorer.  

{   iLength = oDOM.body.innerText.length ;  }  

else     // If Gecko.  

{   var r = oDOM.createRange() ;   

r.selectNodeContents( oDOM.body ) ;   

iLength = r.toString().length ;  }

 alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;

}

6、执行编辑命令:

function ExecuteCommand( commandName ) {

 // Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 // Execute the command.  

oEditor.Commands.GetCommand( commandName ).Execute() ;

}

7、检查编辑器内容是否已变化:

//内容是否变化

function CheckIsDirty() {  

// Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;  

alert( oEditor.IsDirty() ) ;

}

//重置变化标志

function ResetIsDirty() {  

// Get the editor instance that we want to interact with.  

var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;

 oEditor.ResetIsDirty() ;  

alert( 'The "IsDirty" status has been reset' ) ;

}

转载于:https://www.cnblogs.com/wxb-km/archive/2012/08/29/2661453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值