dialogs.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. $(function () {
  2. $('.js-sweetalert button').on('click', function () {
  3. var type = $(this).data('type');
  4. if (type === 'basic') {
  5. showBasicMessage();
  6. }
  7. else if (type === 'with-title') {
  8. showWithTitleMessage();
  9. }
  10. else if (type === 'success') {
  11. showSuccessMessage();
  12. }
  13. else if (type === 'confirm') {
  14. showConfirmMessage();
  15. }
  16. else if (type === 'cancel') {
  17. showCancelMessage();
  18. }
  19. else if (type === 'with-custom-icon') {
  20. showWithCustomIconMessage();
  21. }
  22. else if (type === 'html-message') {
  23. showHtmlMessage();
  24. }
  25. else if (type === 'autoclose-timer') {
  26. showAutoCloseTimerMessage();
  27. }
  28. else if (type === 'prompt') {
  29. showPromptMessage();
  30. }
  31. else if (type === 'ajax-loader') {
  32. showAjaxLoaderMessage();
  33. }
  34. });
  35. });
  36. //These codes takes from http://t4t5.github.io/sweetalert/
  37. function showBasicMessage() {
  38. swal("Here's a message!");
  39. }
  40. function showWithTitleMessage() {
  41. swal("Here's a message!", "It's pretty, isn't it?");
  42. }
  43. function showSuccessMessage() {
  44. swal("Good job!", "You clicked the button!", "success");
  45. }
  46. function showConfirmMessage() {
  47. swal({
  48. title: "Are you sure?",
  49. text: "You will not be able to recover this imaginary file!",
  50. type: "warning",
  51. showCancelButton: true,
  52. confirmButtonColor: "#DD6B55",
  53. confirmButtonText: "Yes, delete it!",
  54. closeOnConfirm: false
  55. }, function () {
  56. swal("Deleted!", "Your imaginary file has been deleted.", "success");
  57. });
  58. }
  59. function showCancelMessage() {
  60. swal({
  61. title: "Are you sure?",
  62. text: "You will not be able to recover this imaginary file!",
  63. type: "warning",
  64. showCancelButton: true,
  65. confirmButtonColor: "#DD6B55",
  66. confirmButtonText: "Yes, delete it!",
  67. cancelButtonText: "No, cancel plx!",
  68. closeOnConfirm: false,
  69. closeOnCancel: false
  70. }, function (isConfirm) {
  71. if (isConfirm) {
  72. swal("Deleted!", "Your imaginary file has been deleted.", "success");
  73. } else {
  74. swal("Cancelled", "Your imaginary file is safe :)", "error");
  75. }
  76. });
  77. }
  78. function showWithCustomIconMessage() {
  79. swal({
  80. title: "Sweet!",
  81. text: "Here's a custom image.",
  82. imageUrl: "../../images/thumbs-up.png"
  83. });
  84. }
  85. function showHtmlMessage() {
  86. swal({
  87. title: "HTML <small>Title</small>!",
  88. text: "A custom <span style=\"color: #CC0000\">html<span> message.",
  89. html: true
  90. });
  91. }
  92. function showAutoCloseTimerMessage() {
  93. swal({
  94. title: "Auto close alert!",
  95. text: "I will close in 2 seconds.",
  96. timer: 2000,
  97. showConfirmButton: false
  98. });
  99. }
  100. function showPromptMessage() {
  101. swal({
  102. title: "An input!",
  103. text: "Write something interesting:",
  104. type: "input",
  105. showCancelButton: true,
  106. closeOnConfirm: false,
  107. animation: "slide-from-top",
  108. inputPlaceholder: "Write something"
  109. }, function (inputValue) {
  110. if (inputValue === false) return false;
  111. if (inputValue === "") {
  112. swal.showInputError("You need to write something!"); return false
  113. }
  114. swal("Nice!", "You wrote: " + inputValue, "success");
  115. });
  116. }
  117. function showAjaxLoaderMessage() {
  118. swal({
  119. title: "Ajax request example",
  120. text: "Submit to run ajax request",
  121. type: "info",
  122. showCancelButton: true,
  123. closeOnConfirm: false,
  124. showLoaderOnConfirm: true,
  125. }, function () {
  126. setTimeout(function () {
  127. swal("Ajax request finished!");
  128. }, 2000);
  129. });
  130. }