xhEditor的異步載入實(shí)現(xiàn)代碼
我將會(huì)使用xheditor作為新的在線編輯器,我希望它可以能通過(guò)一個(gè)php函數(shù)就能調(diào)用如
function editor($content,$name)
{
$editor=<<<EOT
<textarea id="$name" name="$name" rows="10" cols="60">$content</textarea>
EOT;
return $editor;
}
這樣做的好處有:
1,不用每次調(diào)用xheditor編輯器,都在前面寫一大
2,調(diào)用方便,模板上就放返回的html代碼的變量就可以了。
我使用的方法是用jquery里的get()方法異步xheditor的代碼,然后再用eval把代碼運(yùn)行了。 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;
}
以上代碼正確情況下,你是運(yùn)行不了。
因?yàn)閤heditor的0.9.8版在異步載入時(shí)會(huì)出現(xiàn)問(wèn)題。導(dǎo)致xheditor不能正常顯示。
原因:
由于jsURL是通過(guò)獲取頁(yè)面的來(lái)得到的。但我是采用異步加載的,所以我需要指定jsURL的地址。
補(bǔ)?。?BR>打開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};
其實(shí)就是增加了editorURL的默認(rèn)值
然后再找到
this.settings=$.extend({},defaults,options);
在其后面添加
jsURL= this.settings.editorURL||jsURL;
用于設(shè)置jsURL是使用默認(rèn)值還是用戶自定義的目錄
以后在調(diào)用xheditor時(shí)就多了一個(gè)參數(shù)
editorURL
編輯器所在的url路徑,該路徑必須帶有“/”,默認(rèn)值為null
在瀏覽器里打開根目錄的load_xheditor.html
文件打包
相關(guān)文章
eWebEditor 輯器按鈕失效 IE8下eWebEditor編輯器無(wú)法使用的解決方法
最近我把IE瀏覽器更新到了IE8.0,在用eWebEditor在線HTML文本編輯器的時(shí)候點(diǎn)擊eWebEditor上的所有編輯按鈕都沒用,只看到瀏覽器狀態(tài)欄左下角顯示網(wǎng)頁(yè)上有錯(cuò)誤,于是上網(wǎng)查了一下。終于找到解決的方法,測(cè)試后正常。2009-06-06autogrow 讓FCKeditor高度隨內(nèi)容增加的插件
讓FCKeditor高度隨內(nèi)容增加的插件,這個(gè)插件在默認(rèn)情況下可能運(yùn)行不正常,必須做一點(diǎn)修改才可以。2011-02-02配置fckeditor 實(shí)現(xiàn)圖片的上傳
配置fckeditor 實(shí)現(xiàn)圖片的上傳2009-11-11解決FCKEditor在IE10、IE11下的不兼容問(wèn)題
今天有編輯反映網(wǎng)站后臺(tái)的網(wǎng)頁(yè)編輯器無(wú)法顯示了,原來(lái)是編輯自己的電腦升級(jí)了ie到IE10或IE11版本,這里特總結(jié)下多種解決方法,需要的朋友可以參考下2014-10-10CKEditor中加入syntaxhighlighter代碼高亮插件
CKEditor是新一代的FCKeditor,是一個(gè)重新開發(fā)的版本。CKEditor是全球最優(yōu)秀的網(wǎng)頁(yè)在線文字編輯器之一,因其驚人的性能與可擴(kuò)展性而廣泛的被運(yùn)用于各大網(wǎng)站2014-12-12CKeditor與syntaxhighlight打造joomla代碼高亮
最近在用csdn和cnblogs發(fā)帖子和寫隨筆的時(shí)候,發(fā)現(xiàn)了好多的IT的網(wǎng)站或者和代碼有關(guān)系的一些論壇,博客之類,他們都有一個(gè)非常好的語(yǔ)法高亮!很強(qiáng)大!2010-07-07