Angularjs編寫KindEditor,UEidtor指令

來源:互聯網
上載者:User

標籤:

  目前angularJS非常火熱,本人也在項目中逐漸使用該技術,在angularJS中,指令可以說是當中非常重要的一部分,這裡分享一些自己編寫的指令:

  註:本人項目中用了oclazyload進行部分JS檔案載入

  1、KindEditor

  

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: ‘100%‘,                            height: ‘400px‘,                            resizeType: 1,                            uploadJson: ‘/Upload/Upload_Ajax.ashx‘,                            formatUploadUrl: false,                            allowFileManager: true,                            afterChange: function () {                                ctrl.$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:

  

angular.module("AdminApp").directive(‘uiUeditor‘, ["uiLoad", "$compile", function (uiLoad, $compile) {    return {        restrict: ‘EA‘,        require: ‘?ngModel‘,        link: function (scope, element, attrs, ctrl) {            uiLoad.load([‘../Areas/AdminManage/Content/Vendor/jquery/ueditor/ueditor.config.js‘,                   ‘../Areas/AdminManage/Content/Vendor/jquery/ueditor/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:

  

angular.module(‘AdminApp‘).directive(‘uiDatatable‘, [‘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); //清空資料            $scope.dataTable.fnDraw(); //重新載入資料        }        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": ‘正在載入...‘,                        "lengthMenu": "每頁顯示 _MENU_ 條記錄數",                        "zeroRecords": ‘<div style="text-align:center;font-size:12px">沒有找到相關資料</div>‘,                        "info": "當前顯示第 _PAGE_ 頁 共 _PAGES_ 頁",                        "infoEmpty": "空",                        "infoFiltered": "搜尋到 _MAX_ 條記錄",                        "search": "搜尋",                        "paginate": {                            "first": "首頁",                            "previous": "上一頁",                            "next": "下一頁",                            "last": "末頁"                        }                    }                    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‘);                });            });        })    }}]);

 

Angularjs編寫KindEditor,UEidtor指令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.