Xheditor Asynchronous Load Implementation Code _ Web page Editor

Source: Internet
Author: User
Tags rar

I'm going to use Xheditor as the new online editor, and I hope it can be used in a PHP function to call

Copy Code code as follows:

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

The benefits of doing so are:
1, do not have to call the Xheditor editor every time, in front of write a big
2, the invocation is convenient, the template on the return of the HTML code on the variable can be.

The method I used was to asynchronously xheditor the code with the Get () method in jquery and then run the code with eval.
As follows:

Copy Code code as follows:

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= "cols=" > $content </textarea>
EOT;
return $editor;
}

The code above is correct, you can't run it.
The problem occurs because Xheditor version 0.9.8 is loaded asynchronously. Causes Xheditor to not display properly.
Reason:
Because the jsurl is obtained by getting the page. But I'm using asynchronous loading, so I need to specify the Jsurl address.

Patch:
Open Xheditor.js Find the following code

Copy Code code as follows:

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};


To
Copy Code code as follows:

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};

is actually adding the default value of Editorurl.
and find it again.

Copy Code code as follows:

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

After which you add
Copy Code code as follows:

Jsurl= this.settings.editorurl| | Jsurl;

Used to set whether the Jsurl is using a default or user-defined directory

Later, when you call Xheditor, you have one more argument.

Copy Code code as follows:

Editorurl
The URL path of the editor, which must have "/" and the default value is NULL

Open the root directory load_xheditor.html in the browser
File Packaging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.