blob: aca09ca44ea7e8df815ebe21268668b7c31c2dcf [file] [log] [blame]
Iftekharul Islamcd789502017-04-19 14:37:55 -05001window.angular && (function (angular) {
2 'use strict';
3
4 angular
5 .module('app.common.directives')
6 .directive('toggleFlag', function ($document) {
7 return {
8 restrict: 'A',
9 link: function (scope, element, attrs) {
10
11 function elementClick(e) {
12 e.stopPropagation();
13 }
14
15 function documentClick(e) {
16 scope[attrs.toggleFlag] = false;
17 scope.$apply();
18 }
19
20 element.on('click', elementClick);
21 $document.on('click', documentClick);
22
23 // remove event handlers when directive is destroyed
24 scope.$on('$destroy', function () {
25 element.off('click', elementClick);
26 $document.off('click', documentClick);
27 });
28 }
29 };
30 });
31})(window.angular);