blob: 35248ee05c04fb4ea0e3c3bdd67bbf8ef1ed959b [file] [log] [blame]
Ryan Arnell84e7a932018-12-13 10:50:17 -06001window.angular && (function(angular) {
2 'use strict';
3
beccabroek4733a112019-04-10 14:08:49 -05004 angular.module('app.common.directives').directive('clickOutside', [
5 '$document',
6 function($document) {
7 return {
8 restrict: 'A', scope: {clickOutside: '&'},
9 link: function(scope, el, attr) {
10 function clickEvent(e) {
11 if (el !== e.target && !el[0].contains(e.target)) {
12 scope.$apply(function() {
13 scope.$eval(scope.clickOutside);
14 });
Ryan Arnell84e7a932018-12-13 10:50:17 -060015 }
Ryan Arnell84e7a932018-12-13 10:50:17 -060016 }
beccabroek4733a112019-04-10 14:08:49 -050017 $document.bind('click', clickEvent);
18
19 scope.$on('$destroy', function() {
20 $document.unbind('click', clickEvent);
21 });
22 }
23 }
24 }
25 ]);
Ryan Arnell84e7a932018-12-13 10:50:17 -060026})(window.angular);