summaryrefslogtreecommitdiffstats
path: root/app/common/directives/toggle-flag.js
blob: 008097c3ff5c14da7547819582f3f063f4e0afce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives')
      .directive('toggleFlag', function($document) {
        return {
          restrict: 'A',
          link: function(scope, element, attrs) {
            function elementClick(e) {
              e.stopPropagation();
            }

            function documentClick(e) {
              scope[attrs.toggleFlag] = false;
              scope.$apply();
            }

            element.on('click', elementClick);
            $document.on('click', documentClick);

            // remove event handlers when directive is destroyed
            scope.$on('$destroy', function() {
              element.off('click', elementClick);
              $document.off('click', documentClick);
            });
          }
        };
      });
})(window.angular);
OpenPOWER on IntegriCloud