ANGULARJS integrated Baidu Ueditor Editor tutorial

Source: Internet
Author: User

We first create a addscript function to dynamically load the JS script.


/**
* Dynamic load JS file file
* @param URL
* @param callback
*/
function Addscript (url,callback) {
var elt = document.createelement ("script");
elt.src = URL;
ELT.ANYSC = true;
if (elt.onload==null) {
Elt.onload = function () {
typeof callback== ' function ' &&callback ();
}
}else{
Elt.onreadystatechange = function () {
if (elt.readystate== "Loaded" | | | | elt.readystate== "complete") {
typeof callback== ' function ' &&callback ();
}
}
}
document.getElementsByTagName ("Body") [0].appendchild (ELT);
}

and write Angularjs instructions.

Directivesapp.directive (' Ueditor ',
function () {
return{
Restrict: ' EA ',
Require: ' Ngmodel ',
Scope: {
Height: ' @? '
},
Link:function (scope, element, attr, ctrl) {
var _self = this,
_initcontent,
Editor
Editorready = False,
BaseURL = "/assets/vendor/jquery_plugin/ueditor/1.4.3/"; Write your UE path

var Fexue = {
Initeditor:function () {
var _self = this;
if (typeof UE!= ' undefined ') {
Editor = new UE.ui.Editor ({
Initialcontent: _initcontent,
Toolbars: [
[' Source ', ' undo ', ' Redo ', ' bold ', ' Italic ', ' Removeformat ', ' formatmatch ', ' autotypeset ', ' blockquote ',
' Pasteplain ', ' | ', ' ForeColor ', ' BackColor ', ' insertorderedlist ', ' insertunorderedlist '
],
InitialFrameHeight:scope.height | | 120,
Autoheightenabled:false,
Wordcount:false,
Elementpathenabled:false
});


Editor.render (Element[0]);
Editor.ready (function () {
Editorready = true;
_self.setcontent (_initcontent);

Editor.addlistener (' Contentchange ', function () {
Scope. $apply (function () {
Ctrl. $setViewValue (Editor.getcontent ());
});
});
});
} else {

Addscript (BaseURL + ' ueditor.config.js ');
Addscript (BaseURL + ' ueditor.all.min.js ', function () {
_self.initeditor ();
})
}
},
Setcontent:function (content) {
if (editor && Editorready) {
Editor.setcontent (content);
}
}
};

/**
* When model changes are worth the time assigned.
*/
Ctrl. $render = function () {
_initcontent = Ctrl. $isEmpty (CTRL. $viewValue)? ': Ctrl. $viewValue;
Fexue.setcontent (_initcontent);
};

Fexue.initeditor ();
}
}
}
)


Well, the UE's encapsulation is complete.

Regarding the UE width cannot 100% the question, I wrote in the CSS in my project as follows:


* * Repair the width of Baidu 100% problem/

#edui1 {width:100%!important; margin-bottom:10px;} /* This ID is the editor ID * *
#edui1_iframeholder {width:100%!important}/* This ID is the editor editable region ID * *

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.