Code for asynchronous loading of xheditor

Source: Internet
Author: User

I will use xheditor as the new online editor. I hope it can be called through a PHP function, as shown in

CopyCodeThe Code is as follows: function Editor ($ content, $ name)
{
$ Editor = <EOT
<Textarea id = "$ name" name = "$ name" rows = "10" Cols = "60"> $ content </textarea>
EOT;
Return $ editor;
}

The benefits of doing so are:
1. You do not need to call the xheditor every time.
2. Easy to call. You can put the returned HTML code variables on the template.

I used the get () method in jquery to asynchronously code xheditor, and then run the Code with eval.
As follows:Copy codeThe Code is 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 = "10" Cols = "60"> $ content </textarea>
EOT;
Return $ editor;
}

If the above Code is correct, you cannot run it.
Because the 0.9.8 version of xheditor may encounter problems during asynchronous loading. As a result, xheditor cannot be properly displayed.
Cause:
Jsurl is obtained by obtaining the page. However, I use asynchronous loading, so I need to specify the jsurl address.

Patch:
Open xheditor. js and find the following code:Copy codeThe Code is 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 };

ChangeCopy codeThe Code is 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 };

In fact, the default value of editorurl is added.
Then findCopy codeThe Code is as follows: This. settings = $. Extend ({}, defaults, options );

AddCopy codeThe Code is as follows: jsurl = This. settings. editorurl | jsurl;

Used to set whether jsurl uses the default value or a user-defined directory

A parameter will be added when xheditor is called later.Copy codeThe Code is as follows: editorurl
The URL path of the editor. The path must contain "/". 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.