最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Angularjs編寫KindEditor,UEidtor,jQuery指令

 更新時間:2015年01月28日 08:57:10   投稿:hebedich  
使用過 AngularJS 的朋友應該最感興趣的是它的指令?,F(xiàn)今市場上的前端框架也只有AngularJS 擁有自定義指令的功能,并且AngularJS 是目前唯一提供Web應用可復用能力的框架。

  目前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); //清空數(shù)據(jù)
            $scope.dataTable.fnDraw(); //重新加載數(shù)據(jù)
        }
        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_ 條記錄數(shù)",
                        "zeroRecords": '<div style="text-align:center;font-size:12px">沒有找到相關數(shù)據(jù)</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');
                });
            });
        })
    }
}]);

以上3則就是本人編寫的AngularJS指令,這里拋磚引玉下,希望對小伙伴們能有所幫助,

相關文章

最新評論

中山市| 巢湖市| 常熟市| 措美县| 武宁县| 天峨县| 女性| 灌阳县| 扶风县| 商南县| 青阳县| 保康县| 广汉市| 和田县| 易门县| 大城县| 班玛县| 崇礼县| 贵阳市| 隆安县| 沂水县| 东阿县| 南京市| 绍兴县| 榆树市| 合川市| 尉氏县| 刚察县| 阿鲁科尔沁旗| 宁晋县| 会理县| 武义县| 南宫市| 洪江市| 通化市| 新密市| 台东市| 德化县| 民乐县| 新丰县| 连平县|