You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

100 regels
2.1 KiB

  1. (function()
  2. {
  3. $.simplyToast = function(message, type, options)
  4. {
  5. options = $.extend(true, {}, $.simplyToast.defaultOptions, options);
  6. var html = '<div class="simply-toast alert alert-' + (type ? type : options.type) + ' ' + (options.customClass ? options.customClass : '') +'">';
  7. if(options.allowDismiss)
  8. html += '<span class="close" data-dismiss="alert">&times;</span>';
  9. html += message;
  10. html += '</div>';
  11. var offsetSum = options.offset.amount;
  12. $('.simply-toast').each(function()
  13. {
  14. return offsetSum = Math.max(offsetSum, parseInt($(this).css(options.offset.from)) + this.offsetHeight + options.spacing);
  15. });
  16. var css =
  17. {
  18. 'position': (options.appendTo === 'body' ? 'fixed' : 'absolute'),
  19. 'margin': 0,
  20. 'z-index': '9999',
  21. 'display': 'none',
  22. 'min-width': options.minWidth,
  23. 'max-width': options.maxWidth
  24. };
  25. css[options.offset.from] = offsetSum + 'px';
  26. var $alert = $(html).css(css)
  27. .appendTo(options.appendTo);
  28. switch (options.align)
  29. {
  30. case "center":
  31. $alert.css(
  32. {
  33. "left": "50%",
  34. "margin-left": "-" + ($alert.outerWidth() / 2) + "px"
  35. });
  36. break;
  37. case "left":
  38. $alert.css("left", "20px");
  39. break;
  40. default:
  41. $alert.css("right", "20px");
  42. }
  43. if($alert.fadeIn) $alert.fadeIn();
  44. else $alert.css({display: 'block', opacity: 1});
  45. function removeAlert()
  46. {
  47. $.simplyToast.remove($alert);
  48. }
  49. if(options.delay > 0)
  50. {
  51. setTimeout(removeAlert, options.delay);
  52. }
  53. $alert.find("[data-dismiss=\"alert\"]").removeAttr('data-dismiss').click(removeAlert);
  54. return $alert;
  55. };
  56. $.simplyToast.remove = function($alert)
  57. {
  58. if($alert.fadeOut)
  59. {
  60. return $alert.fadeOut(function()
  61. {
  62. return $alert.remove();
  63. });
  64. }
  65. else
  66. {
  67. return $alert.remove();
  68. }
  69. };
  70. $.simplyToast.defaultOptions = {
  71. appendTo: "body",
  72. customClass: false,
  73. type: "info",
  74. offset:
  75. {
  76. from: "top",
  77. amount: 20
  78. },
  79. align: "right",
  80. minWidth: 250,
  81. maxWidth: 450,
  82. delay: 4000,
  83. allowDismiss: true,
  84. spacing: 10
  85. };
  86. })();