Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1 | window.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); |