notify.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $(function() {
  2. "use strict";
  3. $.addNotification = function(params) {
  4. var defaults = {
  5. 'type' : 'info',
  6. 'text' : '',
  7. }
  8. var options = $.extend({}, defaults, params || {});
  9. var elem = $('<div class="alert alert-'+options.type+'">'+options.text+'</div>')
  10. var messages = $('#messages')
  11. if (messages.length === 0) {
  12. messages = $('body').append('<div id="messages"></div>')
  13. }
  14. messages.append(elem)
  15. elem.notify()
  16. }
  17. $.fn.notify = function(params) {
  18. var defaults = {
  19. 'timeout' : 10000,
  20. 'clickable' : true,
  21. 'opacity': 1,
  22. 'opacity_hover': 0.7
  23. }
  24. var options = $.extend({}, defaults, params || {});
  25. if (options.clickable) {
  26. this.on('click', function(){$(this).slideUp()})
  27. }
  28. this.on('mouseover', function(){
  29. $(this).css({
  30. 'opacity':options.opacity_hover,
  31. 'cursor':'pointer'
  32. })
  33. })
  34. this.on('mouseleave', function(){
  35. $(this).css({
  36. 'opacity':options.opacity,
  37. 'cursor':'default'
  38. })
  39. })
  40. setTimeout(function(){
  41. $(this).fadeOut('fast')
  42. }.bind(this), options.timeout)
  43. }
  44. $('#messages').children().each(function() {
  45. $(this).notify()
  46. })
  47. });