var ti_common;
(function (ti_common) {
    var ClickElsewhere = (function () {
        function ClickElsewhere($window, $parse, $timeout) {
            var _this = this;
            this.$window = $window;
            this.$parse = $parse;
            this.$timeout = $timeout;
            this.restrict = 'A';
            this.link = function (scope, element, attrs) {
                var clickOutHandler = _this.$parse(attrs.ticClickElsewhere);
                angular.element(_this.$window).on('click', function (event) {
                    if (!element[0].contains(event.target)) {
                        clickOutHandler(scope, { $event: event });
                        scope.$apply();
                    }
                });
            };
        }
        ClickElsewhere.Factory = function () {
            var directive = function ($window, $parse, $timeout) {
                return new ClickElsewhere($window, $parse, $timeout);
            };
            directive.$inject = ['$window', '$parse', '$timeout'];
            return directive;
        };
        return ClickElsewhere;
    }());
    ;
    angular.module('ti_common').directive('ticClickElsewhere', ClickElsewhere.Factory());
})(ti_common || (ti_common = {}));
