SweetAlert.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. @fileOverview
  3. @toc
  4. */
  5. 'use strict';
  6. angular.module('oitozero.ngSweetAlert', [])
  7. .factory('SweetAlert', [ '$timeout', '$window', function ( $timeout, $window ) {
  8. var swal = $window.swal;
  9. //public methods
  10. var self = {
  11. swal: function ( arg1, arg2, arg3 ) {
  12. $timeout(function(){
  13. if( typeof(arg2) === 'function' ) {
  14. swal( arg1, function(isConfirm){
  15. $timeout( function(){
  16. arg2(isConfirm);
  17. });
  18. }, arg3 );
  19. } else {
  20. swal( arg1, arg2, arg3 );
  21. }
  22. }, 200);
  23. },
  24. adv: function( object ) {
  25. $timeout(function() {
  26. swal( object );
  27. }, 200);
  28. },
  29. timed: function( title, message, type, time ) {
  30. $timeout(function() {
  31. swal( {
  32. title: title,
  33. text: message,
  34. type: type,
  35. timer: time
  36. } );
  37. }, 200);
  38. },
  39. success: function(title, message) {
  40. $timeout(function(){
  41. swal( title, message, 'success' );
  42. }, 200);
  43. },
  44. error: function(title, message) {
  45. $timeout(function(){
  46. swal( title, message, 'error' );
  47. }, 200);
  48. },
  49. warning: function(title, message) {
  50. $timeout(function(){
  51. swal( title, message, 'warning' );
  52. }, 200);
  53. },
  54. info: function(title, message) {
  55. $timeout(function(){
  56. swal( title, message, 'info' );
  57. }, 200);
  58. }
  59. };
  60. return self;
  61. }]);