184e7a936SRyan Arnellwindow.angular && (function(angular) { 284e7a936SRyan Arnell 'use strict'; 384e7a936SRyan Arnell 4*4733a11bSbeccabroek angular.module('app.common.directives').directive('clickOutside', [ 5*4733a11bSbeccabroek '$document', 6*4733a11bSbeccabroek function($document) { 784e7a936SRyan Arnell return { 884e7a936SRyan Arnell restrict: 'A', scope: {clickOutside: '&'}, 984e7a936SRyan Arnell link: function(scope, el, attr) { 1084e7a936SRyan Arnell function clickEvent(e) { 1184e7a936SRyan Arnell if (el !== e.target && !el[0].contains(e.target)) { 1284e7a936SRyan Arnell scope.$apply(function() { 1384e7a936SRyan Arnell scope.$eval(scope.clickOutside); 1484e7a936SRyan Arnell }); 1584e7a936SRyan Arnell } 1684e7a936SRyan Arnell } 1784e7a936SRyan Arnell $document.bind('click', clickEvent); 1884e7a936SRyan Arnell 1984e7a936SRyan Arnell scope.$on('$destroy', function() { 2084e7a936SRyan Arnell $document.unbind('click', clickEvent); 2184e7a936SRyan Arnell }); 2284e7a936SRyan Arnell } 2384e7a936SRyan Arnell } 24*4733a11bSbeccabroek } 25*4733a11bSbeccabroek ]); 2684e7a936SRyan Arnell})(window.angular);