summaryrefslogtreecommitdiffstats
path: root/app/common/directives/click-outside.js
blob: ffe146440771cecbc34323b69ce66893748a1ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives')
      .directive('clickOutside', function($document) {
        return {
          restrict: 'A', scope: {clickOutside: '&'},
              link: function(scope, el, attr) {
                function clickEvent(e) {
                  if (el !== e.target && !el[0].contains(e.target)) {
                    scope.$apply(function() {
                      scope.$eval(scope.clickOutside);
                    });
                  }
                }
                $document.bind('click', clickEvent);

                scope.$on('$destroy', function() {
                  $document.unbind('click', clickEvent);
                });
              }
        }
      });
})(window.angular);
OpenPOWER on IntegriCloud