xhEditor 의 비동기 불 러 오기 실현 코드

새로운 온라인 편집기 로 xheditor 를 사용 할 것 입 니 다.phop 함 수 를 통 해 호출 할 수 있 기 를 바 랍 니 다.

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};
사실은 editor URL 의 기본 값 을 추가 한 다음 에 찾 습 니 다

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

在其后面添加

jsURL= this.settings.editorURL||jsURL;
jsURL 이 기본 값 을 사용 하 는 지 사용자 정의 디 렉 터 리 를 사용 하 는 지 설정 합 니 다.
이후 xheditor 를 호출 할 때 인자 가 하나 더 생 겼 습 니 다
editorURL
url , “/”, null
브 라 우 저 에서 루트 디 렉 터 리 를 여 는 loadxheditor.html 파일 패키지

좋은 웹페이지 즐겨찾기