2
0

alert.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. angular.module('bravoUiAlert', [])
  2. .directive('bravoAlert', function () {
  3. return {
  4. restrict: "A",
  5. transclude: true,
  6. template: '<div ng-transclude></div>',
  7. scope: {
  8. alert_show: '=alertShow',
  9. on_close: '&bravoAlertClose',
  10. on_closed: '&bravoAlertClosed'
  11. },
  12. compile: function (elem, attr) {
  13. var manual = attr['alertShow'];
  14. return function (scope, elem, attr) {
  15. elem.on('click', function(event) {
  16. var obj = angular.element(event.target);
  17. if (obj.attr('data-dismiss')) {
  18. scope.on_destory();
  19. }
  20. });
  21. scope.on_destory = function () {
  22. if (!manual) {
  23. scope.on_close();
  24. elem.addClass('ng-hide');
  25. scope.on_closed();
  26. } else {
  27. scope.on_close();
  28. scope.alert_show = false;
  29. scope.$apply();
  30. }
  31. };
  32. scope.$watch('alert_show', function (nv, ov) {
  33. if (nv != ov) {
  34. if (!nv) {
  35. elem.addClass('ng-hide');
  36. scope.on_closed();
  37. } else {
  38. elem.removeClass('ng-hide');
  39. }
  40. }
  41. });
  42. }
  43. }
  44. }
  45. });