blob: ffe146440771cecbc34323b69ce66893748a1ff6 [file] [log] [blame]
Ryan Arnell84e7a932018-12-13 10:50:17 -06001window.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);