Asp. NET Integrated Baidu editor Ueditor_ practical Skills

Source: Internet
Author: User
Tags gettext

0.ueditor Introduction

Ueditor is developed by Baidu Web front-end Research and Development Department of the WYSIWYG Open source Rich text editor, with lightweight, customizable, excellent user experience and so on. Open source based on the BSD protocol, all source code can be freely modified and used within the scope of the agreement.

Ueditor Official website: http://ueditor.baidu.com/website/index.html

Ueditor Official document Address: http://fex.baidu.com/ueditor/

1. Import the Ueditor package into the project

Unpack the development packages downloaded from the official web and include them in the project

(Note: The latest code needs to be based on. NETFramework4 above)

After extracting the contents of the file below:

Index.html is a sample file that can be deleted, Ueditor.config.js is a set of rich-text editors, do not recommend changes, can be referenced in the page settings, if all pages need to be set can be written in a JS file, dialogs is in the text box to click the button to use some pop-up box effect, Lang folder is the language-related settings, At present only in Chinese and English, themes folder is some style, Third-party folder is some Third-party plug-ins, there are code highlighting, screenshots and so on

I created a new ueditorhelper.js file in my project, defined some Ueditor common methods in the file, and some settings for Ueditor

In the net directory, we only retain controller.ashx and Config.json, while copying the code in App_Code into the project's App_Code. Add a reference to the Json.NET assembly in the bin directory, Config.json file defines settings, some requirements for uploading files, and paths to upload to the server, and you can see in Web.config files that the project framework should be at least 4.0

2. Add a JS reference to the page, refer to the page

Add Zh-cn.js file is to set the language to prevent automatic recognition of language errors resulting in language adaptation errors, Ueditorhelper.js file is a number of common methods and editor settings of the package, view the index.html source code, in which there is a section of JS code

Some methods are used in the custom ueditorhelper.js file, and the first line of code is modified to make the Ueditor Rich Text editor settings

3. Page initialization

Add the following code where you want the rich text editor to be added:

<script type= "Text/plain" ></script>

4. When editing content, the page is loaded (Ajax loading content)

Because the rich text editor just generates a piece of HTML code, we need to use AJAX dynamic loading content, compared to CKEditor, this is a more troublesome place, using CKEditor can directly use packaged server-side controls, Of course, you can use AJAX to dynamically load content without using server-side controls.

First in the page load to get the news ID, and then the AJAX query, query news encapsulated in a handler, to this handler to launch an AJAX request, request parameters for the news ID, get the news, get the news, the content set to the Ueditor

Instantiating the editor//It is recommended that you use the factory method Geteditor to create and reference an editor instance, and if you reference the editor under a closure, call Ue.geteditor (' editor ') directly to get the relevant instance var UE = Ue.geteditor ('
Editor ', {autoheightenabled:false});
  function Isfocus (e) {alert (Ue.geteditor (' Editor '). Isfocus ());
  UE.dom.domUtils.preventDefault (e)} function Setblur (e) {ue.geteditor (' editor '). blur ();
  UE.dom.domUtils.preventDefault (e)} function inserthtml () {var value = prompt (' Insert HTML code ', '); Ue.geteditor (' editor '). ExecCommand (' inserthtml ', Value)} function Createeditor () {ue.geteditor (' Editor ');} function Getallhtml () {return ue.geteditor (' editor '). getallhtml (), function getcontent () {return ue.geteditor (' editor '). Get
Content (); function Getplaintxt () {return ue.geteditor (' editor '). Getplaintxt ();} function SetContent (isappendto) {Ue.getedit  
or (' editor '). SetContent (', isappendto '); function GetText () {//When you click on the button the edit area has lost focus, if you use GetText will not get the content, so select back, then get content var range = ue.geteditor (' editor '). Sele
  Ction.getrange ();
  Range.Select (); Return UE.Geteditor (' editor '). Selection.gettext (); function Getcontenttxt () {return ue.geteditor (' editor '). Getcontenttxt ();} function Hascontent () {return Ue.getedi
Tor (' editor '). Hascontents ();
function SetFocus () {ue.geteditor (' editor '). focus ();} function Deleteeditor () {ue.geteditor (' editor '). Destroy (); function Getlocaldata () {Alert (Ue.geteditor (' Editor '). ExecCommand ("Getlocaldata"));} function Clearlocaldata () {U
  E.geteditor (' editor '). ExecCommand ("Clearlocaldata");

 Alert ("Empty draft box")}

The above is the entire contents of this article, I hope you can enjoy.

Related Article

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.