angular-clickout.js 745 B

12345678910111213141516171819202122232425
  1. /*! Angular clickout v1.0.2 | © 2014 Greg Bergé | License MIT */
  2. (function (window, angular, undefined) { 'use strict';
  3. /**
  4. * Click out directive.
  5. * Execute an angular expression when we click out of the current element.
  6. */
  7. angular.module('clickOut', [])
  8. .directive('clickOut', ['$window', '$parse', function ($window, $parse) {
  9. return {
  10. restrict: 'A',
  11. link: function (scope, element, attrs) {
  12. var clickOutHandler = $parse(attrs.clickOut);
  13. angular.element($window).on('click', function (event) {
  14. if (element[0].contains(event.target)) return;
  15. clickOutHandler(scope, {$event: event});
  16. scope.$apply();
  17. });
  18. }
  19. };
  20. }]);
  21. }(window, window.angular));