1window.angular && (function(angular) {
2  'use strict';
3
4  angular.module('app.common.directives')
5      .directive('clickOutside', function($document) {
6        return {
7          restrict: 'A', scope: {clickOutside: '&'},
8              link: function(scope, el, attr) {
9                function clickEvent(e) {
10                  if (el !== e.target && !el[0].contains(e.target)) {
11                    scope.$apply(function() {
12                      scope.$eval(scope.clickOutside);
13                    });
14                  }
15                }
16                $document.bind('click', clickEvent);
17
18                scope.$on('$destroy', function() {
19                  $document.unbind('click', clickEvent);
20                });
21              }
22        }
23      });
24})(window.angular);