github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/directives/directives.events.js (about)

     1  var directives = directives || {};
     2  
     3  directives.events = angular.module('directives.events', []);
     4  
     5  directives.events.directive('mciBlur', function() {
     6    return function(scope, element, attrs) {
     7      $(element).on("blur", function() {
     8        // Timeout is necessary, because of a common use case where you want
     9        // an autocomplete to disappear when the input loses focus. Clicking on
    10        // an autocomplete element counts as losing focus, and then the click
    11        // doesn't register because the element is queued up to disappear.
    12        setTimeout(function() {
    13          scope.$eval(attrs.mciBlur);
    14          scope.$apply();
    15        }, 250);
    16      });
    17    };
    18  });
    19  
    20  directives.events.directive('mciFocus', function() {
    21    return function(scope, element, attrs) {
    22      $(element).on("focus", function() {
    23        scope.$eval(attrs.mciFocus);
    24        scope.$apply();
    25      });
    26    };
    27  });
    28  
    29  // Port of Angular 1.2.x ngMouseenter, ngMouseleave
    30  directives.events.directive('mciMouseenter', function($parse) {
    31    return function(scope, element, attrs) {
    32      $(element).on("mouseover", function() {
    33        scope.$eval(attrs.mciMouseenter);
    34        scope.$apply();
    35      });
    36    };
    37  });
    38  
    39  directives.events.directive('mciMouseleave', function($parse) {
    40    return function(scope, element, attrs) {
    41      $(element).on("mouseout", function() {
    42        scope.$eval(attrs.mciMouseleave);
    43        scope.$apply();
    44      });
    45    };
    46  });
    47  
    48  (function() {
    49    var keyUpHandlerGenerator = function(attr, keyCode) {
    50      return function(scope, element, attrs) {
    51        element.bind('keyup', function(evt) {
    52          if (evt.which === keyCode) {
    53            scope.$eval(attrs[attr]);
    54            scope.$apply();
    55          }
    56        });
    57      };
    58    };
    59  
    60    directives.events.directive('mciKeyReturn', function() {
    61      return keyUpHandlerGenerator('mciKeyReturn', 13);
    62    });
    63  })();