message.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**//*
  2. * 消息构造
  3. */
  4. function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action){
  5. this.id = id;
  6. this.title = title;
  7. this.caption= caption;
  8. this.message= message;
  9. this.target = target;
  10. this.action = action;
  11. this.width = width?width:200;
  12. this.height = height?height:120;
  13. this.timeout= 150;
  14. this.speed = 20;
  15. this.step = 1;
  16. this.right = screen.width -1;
  17. this.bottom = screen.height;
  18. this.left = this.right - this.width;
  19. this.top = this.bottom - this.height;
  20. this.timer = 0;
  21. this.pause = false;
  22. this.close = false;
  23. this.autoHide = true;
  24. }
  25. /**//*
  26. * 隐藏消息方法
  27. */
  28. CLASS_MSN_MESSAGE.prototype.hide = function(){
  29. if(this.onunload()){
  30. //var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
  31. var me = this;
  32. if(this.timer>0){
  33. window.clearInterval(me.timer);
  34. }
  35. var fun = function(){
  36. if(me.pause==false||me.close){
  37. var x = me.left;
  38. var y = 0;
  39. var width = me.width;
  40. var height = 0;
  41. if(me.offset>0){
  42. height = me.offset;
  43. }
  44. y = me.bottom - height;
  45. if(y>=me.bottom){
  46. window.clearInterval(me.timer);
  47. me.Pop.hide();
  48. } else {
  49. me.offset = me.offset - me.step;
  50. }
  51. me.Pop.show(x,y,width,height);
  52. }
  53. };
  54. this.timer = window.setInterval(fun,this.speed) ;
  55. }
  56. } ;
  57. /**//*
  58. * 消息卸载事件,可以重写
  59. */
  60. CLASS_MSN_MESSAGE.prototype.onunload = function() {
  61. return true;
  62. };
  63. /**//*
  64. * 消息命令事件,要实现自己的连接,请重写它
  65. *
  66. */
  67. CLASS_MSN_MESSAGE.prototype.oncommand = function(){
  68. //this.close = true;
  69. this.hide();
  70. window.open("http://www.usoftchina.com");
  71. };
  72. /**//*
  73. * 消息显示方法
  74. */
  75. CLASS_MSN_MESSAGE.prototype.show = function(){
  76. var oPopup = window.createPopup(); //IE5.5+
  77. this.Pop = oPopup;
  78. var w = this.width;
  79. var h = this.height;
  80. var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>";
  81. str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>";
  82. str += "<TR >" ;
  83. str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>" ;
  84. str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>";
  85. str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>" ;
  86. str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>";
  87. str += "</TR>" ;
  88. str += "<TR>" ;
  89. str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">" ;
  90. str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 8px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 8px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>" + this.title + "<BR><BR>";
  91. str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=false id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A> - <A href='../index.html' hidefocus=false id='ommand'><FONT color=#ff0000>http://www.usoftchina.com</FONT></A></DIV>";
  92. str += "</DIV>" ;
  93. str += "</TD>" ;
  94. str += "</TR>" ;
  95. str += "</TABLE>" ;
  96. str += "</DIV>" ;
  97. oPopup.document.body.innerHTML = str;
  98. this.offset = 0;
  99. var me = this;
  100. oPopup.document.body.onmouseover = function(){me.pause=true;};
  101. oPopup.document.body.onmouseout = function(){me.pause=false;};
  102. var fun = function(){
  103. var x = me.left;
  104. var y = 0;
  105. var width = me.width;
  106. var height = me.height;
  107. if(me.offset>me.height){
  108. height = me.height;
  109. } else {
  110. height = me.offset;
  111. }
  112. y = me.bottom - me.offset;
  113. if(y<=me.top){
  114. me.timeout--;
  115. if(me.timeout==0){
  116. window.clearInterval(me.timer);
  117. if(me.autoHide){
  118. me.hide();
  119. }
  120. }
  121. } else {
  122. me.offset = me.offset + me.step;
  123. }
  124. me.Pop.show(x,y,width,height);
  125. };
  126. this.timer = window.setInterval(fun,this.speed);
  127. var btClose = oPopup.document.getElementById("btSysClose");
  128. btClose.onclick = function(){
  129. me.close = true;
  130. me.hide();
  131. };
  132. var btCommand = oPopup.document.getElementById("btCommand");
  133. btCommand.onclick = function(){
  134. me.oncommand();
  135. };
  136. var ommand = oPopup.document.getElementById("ommand");
  137. ommand.onclick = function(){
  138. //this.close = true;
  139. me.hide();
  140. window.open(ommand.href);
  141. };
  142. };
  143. /**//*
  144. ** 设置速度方法
  145. **/
  146. CLASS_MSN_MESSAGE.prototype.speed = function(s){
  147. var t = 20;
  148. try {
  149. t = praseInt(s);
  150. } catch(e){}
  151. this.speed = t;
  152. };
  153. /**//*
  154. ** 设置步长方法
  155. **/
  156. CLASS_MSN_MESSAGE.prototype.step = function(s){
  157. var t = 1;
  158. try {
  159. t = praseInt(s);
  160. } catch(e){}
  161. this.step = t;
  162. };
  163. CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){
  164. try {
  165. this.left = left !=null?left:this.right-this.width;
  166. this.right = right !=null?right:this.left +this.width;
  167. this.bottom = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
  168. this.top = top !=null?top:this.bottom - this.height;
  169. } catch(e){}
  170. };
  171. var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"新消息:","有新的采购单哦","点击查看");
  172. MSG1.rect(null,null,null,screen.height-50);
  173. MSG1.speed = 10;
  174. MSG1.step = 5;
  175. //alert(MSG1.top);
  176. MSG1.show();
  177. //同时两个有闪烁,只能用层代替了,不过层不跨框架
  178. //var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");
  179. // MSG2.rect(100,null,null,screen.height);
  180. // MSG2.show();
  181. //-->