我將會使用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是使用默認值還是用戶自定義的目錄
以后在調用xheditor時就多了一個參數
editorURL
編輯器所在的url路徑,該路徑必須帶有“/”,默認值為null
在瀏覽器里打開根目錄的load_xheditor.html
文件打包
新聞熱點
疑難解答