notifyme.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Notifications
  2. (function($){
  3. 'use strict';
  4. // Define plugin name and parameters
  5. $.fn.notifyMe = function($position, $type, $title, $button, $more, $content, $id, $velocity, $json, $delay){
  6. // Remove recent notification for appear new
  7. var idStr = "#"+$id;
  8. $(idStr).remove();
  9. // Create the content of Alert
  10. var close = "<a class='notify-close'>x</a>";
  11. var header = "<section class='notify' data-position='"+ $position +"' data-notify='" + $type +"' id='" + $id+ "'>" + close + "<h3>" + $title + "</h3>";
  12. var content = "<div class='notify-content'>" + $content + "</div></section>";
  13. var notifyModel = header +$button+$more+ content;
  14. //$('body').prepend(notifyModel);
  15. $('body').append(notifyModel);
  16. //var notifyHeigth = $('.notify').outerHeight();
  17. var notifyHeigth = $(idStr).outerWidth()+"px";
  18. // Show Notification
  19. if($position == "right"){
  20. $(idStr).css('right', '-' + notifyHeigth);
  21. /*if($button==""){
  22. $(idStr).animate({
  23. right: '0px',
  24. top: '0'
  25. },$velocity);
  26. $(idStr).css('width', '1100px');
  27. }else{
  28. $(idStr).animate({
  29. right: '0px'
  30. },$velocity);
  31. }*/
  32. if(typeof $json !== 'undefined') {
  33. $(idStr).animate({
  34. right: $json.right,
  35. top: $json.top
  36. },$velocity);
  37. }else{
  38. $(idStr).animate({
  39. right: '0px'
  40. },$velocity);
  41. }
  42. // Close Notification automatically
  43. if(typeof $delay !== 'undefined') {
  44. setTimeout(function(){
  45. $('.notify').animate({
  46. right: '-' + notifyHeigth
  47. },$velocity);
  48. // Remove item when close
  49. setTimeout(function(){
  50. $(idStr).remove();
  51. },$velocity + 100);
  52. },$delay);
  53. }
  54. }
  55. else if($position == "left"){
  56. $(idStr).css('left', '-' + notifyHeigth);
  57. $(idStr).animate({
  58. left: '30%'
  59. },$velocity);
  60. // Close Notifications automatically
  61. if(typeof $delay !== 'undefined') {
  62. setTimeout(function(){
  63. $('.notify').animate({
  64. left: '-' + notifyHeigth
  65. },$velocity);
  66. // Remove item when close
  67. setTimeout(function(){
  68. $(idStr).remove();
  69. },$velocity + 100);
  70. },$delay);
  71. }
  72. }
  73. // Close Notification
  74. $('.notify-close').click(function(){
  75. // Move notification
  76. if($position == "bottom"){
  77. $(this).parent('.notify').animate({
  78. bottom: '-' + notifyHeigth
  79. },$velocity);
  80. }
  81. else if($position == "top"){
  82. $(this).parent('.notify').animate({
  83. top: '-' + notifyHeigth
  84. },$velocity);
  85. }
  86. else if($position == "right"){
  87. $(this).parent(idStr).animate({
  88. right: '-' + notifyHeigth
  89. },$velocity);
  90. }
  91. else if($position == "left"){
  92. $(this).parent(idStr).animate({
  93. left: '-' + notifyHeigth
  94. },$velocity);
  95. }
  96. // Remove item when close
  97. setTimeout(function(){
  98. $(idStr).remove();
  99. if($(".mask").length>0){
  100. $(".mask").attr("style",'left: 0px; top: 0px; width: 100%; overflow: hidden; position: absolute; z-index: 500000; background-color: rgb(255, 255, 255)');
  101. $(".mask").attr("class","");
  102. }
  103. },$velocity + 200);
  104. });
  105. }
  106. }(jQuery));