index.js 1.3 KB
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
(function() {
    'use strict';

    /**
     * 监听dom结构变化
     * @param {string} bindId 绑定监听id
     * @param {function} watchDomCommonDirective 绑定方法
     */
    angular.module('eolinker.directive')
        .directive('watchDomCommonDirective', [function() {
            return {
                restrict: 'A',
                scope: {
                    bindId: '@',
                    watchDomCommonDirective: '&'
                },
                link: function($scope,elem,attrs,ngModel) {
                    var data = {
                        elem: document.getElementById($scope.bindId),
                        fun: {
                            init: null
                        }
                    }

                    /**
                     * @description dom节点变化监听函数
                     */
                    data.fun.DOMSubtreeModified = function() {
                        $scope.watchDomCommonDirective({input:data.elem.innerText});
                    }

                    /**
                     * 自启动初始化功能函数
                     */
                    data.fun.init = (function() {
                        angular.element(data.elem).bind('DOMSubtreeModified', data.fun.DOMSubtreeModified);
                    })()
                }
            };
        }]);

})();