message1.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. (function(){
  2. var ua=navigator.userAgent.toLowerCase();
  3. var is=(ua.match(/\b(chrome|opera|safari|msie|firefox)\b/) || ['','mozilla'])[1];
  4. var r='(?:'+is+'|version)[\\/: ]([\\d.]+)';
  5. var v=(ua.match(new RegExp(r)) ||[])[1];
  6. jQuery.browser.is=is;
  7. jQuery.browser.ver=v;
  8. jQuery.browser[is]=true;
  9. })();
  10. (function (jQuery){
  11. /*
  12. * jQuery Plugin - Messager
  13. * $Date: 2011-08-12
  14. * $Vesion: 1.0
  15. * www.jspal.com
  16. */
  17. this.version = '@1.4';
  18. this.layer = {'width' : 300, 'height': 200};
  19. this.title = '信息提示';
  20. this.time = 4000;
  21. this.anims = {'type' : 'slide', 'speed' : 600};
  22. this.timer1 = null;
  23. this.inits = function(title, text){
  24. if($("#message").is("div")){ return; }
  25. $(document.body).prepend('<div id="message" style="border:#b9c9ef 1px solid;z-index:100;width:'+this.layer.width+'px;height:'+this.layer.height+'px;position:absolute; display:none;background:#cfdef4; bottom:0; right:0; overflow:hidden;"><div style="border:1px solid #fff;border-bottom:none;width:100%;height:25px;font-size:12px;overflow:hidden;color:#1f336b;"><span id="message_close" style="float:right;padding:5px 0 5px 0;width:16px;line-height:auto;color:red;font-size:12px;font-weight:bold;text-align:center;cursor:pointer;overflow:hidden;">×</span><div style="padding:5px 0 5px 5px;width:100px;line-height:18px;text-align:left;overflow:hidden;">'+title+'</div><div style="clear:both;"></div></div> <div style="padding-bottom:5px;border:1px solid #fff;border-top:none;width:100%;height:auto;font-size:12px;"><div id="message_content" style="margin:0 5px 0 5px;border:#b9c9ef 1px solid;padding:10px 0 10px 5px;font-size:12px;width:'+(this.layer.width-17)+'px;height:'+(this.layer.height-50)+'px;color:#1f336b;text-align:left;overflow:hidden;">'+text+'</div></div></div>');
  26. $("#message_close").click(function(){
  27. setTimeout('this.close()', 1);
  28. });
  29. $("#message").hover(function(){
  30. clearTimeout(timer1);
  31. timer1 = null;
  32. },function(){
  33. timer1 = setTimeout('this.close()', time);
  34. });
  35. };
  36. this.show = function(title, text, time){
  37. if($("#message").is("div")){ return; }
  38. if(title==0 || !title)title = this.title;
  39. this.inits(title, text);
  40. if(time>=0)this.time = time;
  41. switch(this.anims.type){
  42. case 'slide':$("#message").slideDown(this.anims.speed);break;
  43. case 'fade':$("#message").fadeIn(this.anims.speed);break;
  44. case 'show':$("#message").show(this.anims.speed);break;
  45. default:$("#message").slideDown(this.anims.speed);break;
  46. }
  47. if($.browser.is=='chrome'){
  48. setTimeout(function(){
  49. $("#message").remove();
  50. this.inits(title, text);
  51. $("#message").css("display","block");
  52. },this.anims.speed-(this.anims.speed/5));
  53. }
  54. //$("#message").slideDown('slow');
  55. this.rmmessage(this.time);
  56. };
  57. this.lays = function(width, height){
  58. if($("#message").is("div")){ return; }
  59. if(width!=0 && width)this.layer.width = width;
  60. if(height!=0 && height)this.layer.height = height;
  61. };
  62. this.anim = function(type,speed){
  63. if($("#message").is("div")){ return; }
  64. if(type!=0 && type)this.anims.type = type;
  65. if(speed!=0 && speed){
  66. switch(speed){
  67. case 'slow' : ;break;
  68. case 'fast' : this.anims.speed = 200; break;
  69. case 'normal' : this.anims.speed = 400; break;
  70. default:
  71. this.anims.speed = speed;
  72. }
  73. }
  74. };
  75. this.rmmessage = function(time){
  76. if(time>0){
  77. timer1 = setTimeout('this.close()', time);
  78. //setTimeout('$("#message").remove()', time+1000);
  79. }
  80. };
  81. this.close = function(){
  82. switch(this.anims.type){
  83. case 'slide':$("#message").slideUp(this.anims.speed);break;
  84. case 'fade':$("#message").fadeOut(this.anims.speed);break;
  85. case 'show':$("#message").hide(this.anims.speed);break;
  86. default:$("#message").slideUp(this.anims.speed);break;
  87. };
  88. setTimeout('$("#message").remove();', this.anims.speed);
  89. this.original();
  90. };
  91. this.original = function(){
  92. this.layer = {'width' : 300, 'height': 200};
  93. this.title = '';
  94. this.time = 4000;
  95. this.anims = {'type' : 'slide', 'speed' : 600};
  96. };
  97. jQuery.messager = this;
  98. return jQuery;
  99. })(jQuery);