Angularjs: write KindEditor, UEidtor, jQuery directive _ AngularJS

Source: Internet
Author: User
Those who have used AngularJS should be most interested in its commands. Currently, only AngularJS supports custom commands, and AngularJS is the only framework that provides reusable Web applications. Currently, angularJS is very popular and I am gradually using this technology in projects. In angularJS, commands can be said to be a very important part. here I will share some self-compiled commands:

Note: I used oclazyload in my project to load some JS files.

1. KindEditor

The code is as follows:


Angular. module ('adminapp'). directive ('uikindeditor ', ['uiload', function (uiLoad ){
Return {
Restrict: 'EA ',
Require :'? Ngmodel ',
Link: function (scope, element, attrs, ctrl ){
UiLoad. load ('../Areas/AdminManage/Content/Vendor/jquery/kindeditor/kindeditor-all.js'). then (function (){
Var _ initContent, editor;
Var fexUE = {
InitEditor: function (){
Editor = KindEditor. create (element [0], {
Width: '200 ',
Height: '400p ',
ResizeType: 1,
UploadJson: '/Upload/upload_ajax.ashx ',
FormatUploadUrl: false,
AllowFileManager: true,
AfterChange: function (){
Ctrl.20.setviewvalue(this.html ());
}
});
},
SetContent: function (content ){
If (editor ){
Editor.html (content );
}
}
}
If (! Ctrl ){
Return;
}
_ InitContent = ctrl. $ viewValue;
Ctrl. $ render = function (){
_ InitContent = ctrl. $ isEmpty (ctrl. $ viewValue )? '': Ctrl. $ viewValue;
FexUE. setContent (_ initContent );
};
FexUE. initEditor ();
});
}
}
}]);

2. UEditor:

The code is as follows:


Angular. module ("AdminApp"). directive ('uieditor', ["uiLoad", "$ compile", function (uiLoad, $ compile ){
Return {
Restrict: 'EA ',
Require :'? Ngmodel ',
Link: function (scope, element, attrs, ctrl ){
UiLoad. load (['../Areas/AdminManage/Content/Vendor/jquery/ueditor. config. js ',
'../Areas/AdminManage/Content/Vendor/jquery/ueditor. all. js']). then (function (){
Var _ self = this,
_ InitContent,
Editor,
EditorReady = false
Var fexUE = {
InitEditor: function (){
Var _ self = this;
If (typeof UE! = 'Undefined '){
Editor = new UE. ui. Editor ({
InitialContent: _ initContent,
AutoHeightEnabled: false,
AutoFloatEnabled: false
});
Editor. render (element [0]);
Editor. ready (function (){
EditorReady = true;
_ Self. setContent (_ initContent );
Editor. addListener ('contentchange', function (){
Scope. $ apply (function (){
Ctrl. $ setViewValue (editor. getContent ());
});
});
});
}
},
SetContent: function (content ){
If (editor & editorReady ){
Editor. setContent (content );
}
}
};
If (! Ctrl ){
Return;
}
_ InitContent = ctrl. $ viewValue;
Ctrl. $ render = function (){
_ InitContent = ctrl. $ isEmpty (ctrl. $ viewValue )? '': Ctrl. $ viewValue;
FexUE. setContent (_ initContent );
};
FexUE. initEditor ();
});
}
};
}]);

3. jquery. Datatable:

The code is as follows:


Angular. module ('adminapp'). directive ('uiable able', ['uiload', '$ compile', function (uiLoad, $ compile ){
Return function ($ scope, $ element, attrs ){
$ Scope. getChooseData = function (){
Var listID = "";
Var chooseData = $ element. find ("input [name = IsChoose]: checkbox: checked ");
If (chooseData. length> 0 ){
For (var I = 0; I <chooseData. length; I ++ ){
ListID + = chooseData [I]. value + ",";
}
}
Return listID. substring (0, listID. length-1 );
}
$ Scope. refreshTable = function (){
$ Scope. dataTable. fnClearTable (0); // clear data
$ Scope. dataTable. fnDraw (); // reload data
}
UiLoad. load (['../Areas/AdminManage/Content/Vendor/jquery/datatables/jquery. dataTables. min. js ',
'../Areas/AdminManage/Content/Vendor/jquery/datatables/dataTables. bootstrap. js ',
'../Areas/AdminManage/Content/Vendor/jquery/datatables/dataTables.bootstrap.css']). then (function (){
Var options = {};
If ($ scope. dtOptions ){
Angular. extend (options, $ scope. dtOptions );
}
Options ["processing"] = false;
Options ["info"] = false;
Options ["serverSide"] = true;
Options ["language"] = {
"Processing": 'Loading ...',
"LengthMenu": "Number of _ MENU _ records displayed on each page ",
"ZeroRecords ":'

No relevant data found

',
"Info": "PAGE _ PAGES displayed currently ",
"InfoEmpty": "null ",
"InfoFiltered": "_ MAX _ records found ",
"Search": "search ",
"Paginate ":{
"First": "homepage ",
"Previous": "previous Page ",
"Next": "next page ",
"Last": "last Page"
}
}
Options ["fnRowCallback"] = function (nRow, aData, iDisplayIndex, iDisplayIndexFull ){
$ Compile (nRow) ($ scope );
}
$ Scope. dataTable = $ element. dataTable (options );
});
$ Element. find ("thead th"). each (function (){
$ (This). on ("click", "input: checkbox", function (){
Var that = this;
$ (This). closest ('table'). find ('tr> td: first-child input: checkbox'). each (function (){
This. checked = that. checked;
$ (This). closest ('tr'). toggleClass ('selected ');
});
});
})
}
}]);

The above three are my AngularJS commands, which I hope will be helpful to my friends,

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.