blob: 9c342b0fc976731957c80a86cfebd59a0d3c4d8e [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) {
Gunnar Millseedefd32018-02-28 17:02:34 -060010
Iftekharul Islamcd789502017-04-19 14:37:55 -050011 function elementClick(e) {
12 e.stopPropagation();
13 }
Gunnar Millseedefd32018-02-28 17:02:34 -060014
Iftekharul Islamcd789502017-04-19 14:37:55 -050015 function documentClick(e) {
16 scope[attrs.toggleFlag] = false;
17 scope.$apply();
18 }
Gunnar Millseedefd32018-02-28 17:02:34 -060019
Iftekharul Islamcd789502017-04-19 14:37:55 -050020 element.on('click', elementClick);
21 $document.on('click', documentClick);
Gunnar Millseedefd32018-02-28 17:02:34 -060022
Iftekharul Islamcd789502017-04-19 14:37:55 -050023 // 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);