/wp-content/themes/twentyeleven/js/growl.js

https://github.com/atifsaleem/APSN · JavaScript · 94 lines · 67 code · 19 blank · 8 comment · 8 complexity · 4c97edda17fece0810778d43ca8f0514 MD5 · raw file

  1. (function($){
  2. //GROWL OBJECT
  3. //--------------------------------------------------------------------
  4. $.Growl = {
  5. _growlContainer: null,
  6. _statsCount: 0,
  7. show: function(message, options){
  8. var settings = $.extend({
  9. "id": ("gs"+$.Growl._statsCount++),
  10. "icon": false,
  11. "title": false,
  12. "message": message,
  13. "cls": "",
  14. "speed": 500,
  15. "timeout": 3000
  16. },options);
  17. $("#"+settings.id).remove();
  18. //append status
  19. this._getContainer().prepend(
  20. '<div id="'+settings.id+'" class="growlstatus '+settings.cls+'" style="display:none;"><div class="growlstatusclose"></div>'+settings.message+'</div>'
  21. );
  22. var status = $("#"+settings.id);
  23. //bind close button
  24. status.find(".growlstatusclose").bind('click',function(){
  25. $.Growl.close(settings.id,true,settings.speed);
  26. });
  27. //show title
  28. if(settings.title!==false){
  29. status.prepend('<div class="growltitle">'+settings.title+'</div>');
  30. }
  31. //show icon
  32. if(settings.icon!==false){
  33. status.addClass("growlwithicon").addClass("growlicon_"+settings.icon);
  34. }
  35. status
  36. //do not hide on hover
  37. .hover(
  38. function(){
  39. status.addClass("growlhover");
  40. },
  41. function(){
  42. status.removeClass("growlhover");
  43. if(settings.timeout!==false){
  44. window.setTimeout(function(){$.Growl.close(settings.id);}, settings.timeout);
  45. }
  46. }
  47. )
  48. //show status+handle timeout
  49. .fadeIn(settings.speed,function(){
  50. if(settings.timeout!==false){
  51. window.setTimeout(function(){$.Growl.close(settings.id);}, settings.timeout);
  52. }
  53. });
  54. return settings.id;
  55. },
  56. close: function(id,force,speed){
  57. if(arguments.length==0){
  58. $(".growlstatus",this._getContainer()).hide().remove();
  59. }else{
  60. var status = $("#"+id);
  61. if(!status.hasClass("growlhover") || force){
  62. status.animate({opacity:"0.0"}, speed).slideUp(function(){
  63. status.remove();
  64. })
  65. }
  66. }
  67. },
  68. _getContainer: function(){
  69. if(!this._growlContainer) {
  70. this._growlContainer = $('<div id="growlcontainer"></div>').appendTo("body");
  71. }
  72. return this._growlContainer;
  73. }
  74. };
  75. })(jQuery);