当前位置: 首页 > 图文教程 > 网络编程 > 网页编辑器 > xhEditor的异步载入实现代码

网页编辑器
fckeditor在php中的用法(添加于修改写成了函数)
关于CKeditor的非主流个性应用的设置
dedecms5.5 最新版ckeditor编辑器整合教程
javascript 网页编辑框及拖拽图片的问题
asp.net FCKeditor 2.6.3 配置说明
轻松实现 CKfinder进驻CKEditor3.0
将CKfinder 整合进 CKEditor3.0的方法
ASp.net下fckeditor配置图片上传最简单的方法
ckeditor 简单配置方法
asp.net CKEditor和CKFinder的应用
FCKEDITOR 的高级功能和常见问题的解决方法
CuteEditor 编辑器的字体样式无法控制的解决方法
fckeditor 修改记录添加行距功能插件
SyntaxHighlighter 语法高亮插件的使用教程

网页编辑器 中的 xhEditor的异步载入实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 60 ::
收藏到网摘: n/a

xhEditor的异步载入实现代码,需要的朋友可以参考下。

我将会使用xheditor作为新的在线编辑器,我希望它可以能通过一个php函数就能调用如

复制代码 代码如下:

function editor($content,$name)
{
$editor=<<<EOT
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
return $editor;
}

这样做的好处有:
1,不用每次调用xheditor编辑器,都在前面写一大
2,调用方便,模板上就放返回的html代码的变量就可以了。

我使用的方法是用jquery里的get()方法异步xheditor的代码,然后再用eval把代码运行了。
如下:

复制代码 代码如下:

function editor($content,$name)
{
$editor=<<<EOT
$(document).ready(
function(){
if(!$.isFunction($.xheditor))
{
$.get(
'../xheditor.js',
function(data){
eval(data);
}
);
}
$('#{$name}').xheditor(true);
}
);
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
return $editor;
}

以上代码正确情况下,你是运行不了。
因为xheditor的0.9.8版在异步载入时会出现问题。导致xheditor不能正常显示。
原因:
由于jsURL是通过获取页面的来得到的。但我是采用异步加载的,所以我需要指定jsURL的地址。

补丁:
打开xheditor.js找到以下代码

复制代码 代码如下:

var defaults={skin:"default",tools:"full",internalScript:false,inlineScript:false,internalStyle:false,inlineStyle:true,showBlocktag:false,forcePtag:true,keepValue:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"avi",modalWidth:350,modalHeight:220,modalTitle:true};


改为
复制代码 代码如下:

var defaults={skin:"default",tools:"full",internalScript:false,inlineScript:false,internalStyle:false,inlineStyle:true,showBlocktag:false,forcePtag:true,keepValue:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"avi",modalWidth:350,modalHeight:220,modalTitle:true,editorURL:null};

其实就是增加了editorURL的默认值
然后再找到

复制代码 代码如下:

this.settings=$.extend({},defaults,options);

在其后面添加
复制代码 代码如下:

jsURL= this.settings.editorURL||jsURL;

用于设置jsURL是使用默认值还是用户自定义的目录