jquery.messager.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. * jQuery EasyUI 1.5.2
  3. *
  4. * Copyright (c) 2009-2017 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(){
  12. $(document).unbind(".messager").bind("keydown.messager",function(e){
  13. if(e.keyCode==27){
  14. $("body").children("div.messager-window").children("div.messager-body").each(function(){
  15. $(this).dialog("close");
  16. });
  17. }else{
  18. if(e.keyCode==9){
  19. var _2=$("body").children("div.messager-window");
  20. if(!_2.length){
  21. return;
  22. }
  23. var _3=_2.find(".messager-input,.messager-button .l-btn");
  24. for(var i=0;i<_3.length;i++){
  25. if($(_3[i]).is(":focus")){
  26. $(_3[i>=_3.length-1?0:i+1]).focus();
  27. return false;
  28. }
  29. }
  30. }else{
  31. if(e.keyCode==13){
  32. var _4=$(e.target).closest("input.messager-input");
  33. if(_4.length){
  34. var _5=_4.closest(".messager-body");
  35. _6(_5,_4.val());
  36. }
  37. }
  38. }
  39. }
  40. });
  41. };
  42. function _7(){
  43. $(document).unbind(".messager");
  44. };
  45. function _8(_9){
  46. var _a=$.extend({},$.messager.defaults,{modal:false,shadow:false,draggable:false,resizable:false,closed:true,style:{left:"",top:"",right:0,zIndex:$.fn.window.defaults.zIndex++,bottom:-document.body.scrollTop-document.documentElement.scrollTop},title:"",width:250,height:100,minHeight:0,showType:"slide",showSpeed:600,content:_9.msg,timeout:4000},_9);
  47. var _b=$("<div class=\"messager-body\"></div>").appendTo("body");
  48. _b.dialog($.extend({},_a,{noheader:(_a.title?false:true),openAnimation:(_a.showType),closeAnimation:(_a.showType=="show"?"hide":_a.showType),openDuration:_a.showSpeed,closeDuration:_a.showSpeed,onOpen:function(){
  49. _b.dialog("dialog").hover(function(){
  50. if(_a.timer){
  51. clearTimeout(_a.timer);
  52. }
  53. },function(){
  54. _c();
  55. });
  56. _c();
  57. function _c(){
  58. if(_a.timeout>0){
  59. _a.timer=setTimeout(function(){
  60. if(_b.length&&_b.data("dialog")){
  61. _b.dialog("close");
  62. }
  63. },_a.timeout);
  64. }
  65. };
  66. if(_9.onOpen){
  67. _9.onOpen.call(this);
  68. }else{
  69. _a.onOpen.call(this);
  70. }
  71. },onClose:function(){
  72. if(_a.timer){
  73. clearTimeout(_a.timer);
  74. }
  75. if(_9.onClose){
  76. _9.onClose.call(this);
  77. }else{
  78. _a.onClose.call(this);
  79. }
  80. _b.dialog("destroy");
  81. }}));
  82. _b.dialog("dialog").css(_a.style);
  83. _b.dialog("open");
  84. return _b;
  85. };
  86. function _d(_e){
  87. _1();
  88. var _f=$("<div class=\"messager-body\"></div>").appendTo("body");
  89. _f.dialog($.extend({},_e,{noheader:(_e.title?false:true),onClose:function(){
  90. _7();
  91. if(_e.onClose){
  92. _e.onClose.call(this);
  93. }
  94. setTimeout(function(){
  95. _f.dialog("destroy");
  96. },100);
  97. }}));
  98. var win=_f.dialog("dialog").addClass("messager-window");
  99. win.find(".dialog-button").addClass("messager-button").find("a:first").focus();
  100. return _f;
  101. };
  102. function _6(dlg,_10){
  103. dlg.dialog("close");
  104. dlg.dialog("options").fn(_10);
  105. };
  106. $.messager={show:function(_11){
  107. return _8(_11);
  108. },alert:function(_12,msg,_13,fn){
  109. var _14=typeof _12=="object"?_12:{title:_12,msg:msg,icon:_13,fn:fn};
  110. var cls=_14.icon?"messager-icon messager-"+_14.icon:"";
  111. _14=$.extend({},$.messager.defaults,{content:"<div class=\""+cls+"\"></div>"+"<div>"+_14.msg+"</div>"+"<div style=\"clear:both;\"/>"},_14);
  112. if(!_14.buttons){
  113. _14.buttons=[{text:_14.ok,onClick:function(){
  114. _6(dlg);
  115. }}];
  116. }
  117. var dlg=_d(_14);
  118. return dlg;
  119. },confirm:function(_15,msg,fn){
  120. var _16=typeof _15=="object"?_15:{title:_15,msg:msg,fn:fn};
  121. _16=$.extend({},$.messager.defaults,{content:"<div class=\"messager-icon messager-question\"></div>"+"<div>"+_16.msg+"</div>"+"<div style=\"clear:both;\"/>"},_16);
  122. if(!_16.buttons){
  123. _16.buttons=[{text:_16.ok,onClick:function(){
  124. _6(dlg,true);
  125. }},{text:_16.cancel,onClick:function(){
  126. _6(dlg,false);
  127. }}];
  128. }
  129. var dlg=_d(_16);
  130. return dlg;
  131. },prompt:function(_17,msg,fn){
  132. var _18=typeof _17=="object"?_17:{title:_17,msg:msg,fn:fn};
  133. _18=$.extend({},$.messager.defaults,{content:"<div class=\"messager-icon messager-question\"></div>"+"<div>"+_18.msg+"</div>"+"<br/>"+"<div style=\"clear:both;\"/>"+"<div><input class=\"messager-input\" type=\"text\"/></div>"},_18);
  134. if(!_18.buttons){
  135. _18.buttons=[{text:_18.ok,onClick:function(){
  136. _6(dlg,dlg.find(".messager-input").val());
  137. }},{text:_18.cancel,onClick:function(){
  138. _6(dlg);
  139. }}];
  140. }
  141. var dlg=_d(_18);
  142. dlg.find(".messager-input").focus();
  143. return dlg;
  144. },progress:function(_19){
  145. var _1a={bar:function(){
  146. return $("body>div.messager-window").find("div.messager-p-bar");
  147. },close:function(){
  148. var dlg=$("body>div.messager-window>div.messager-body:has(div.messager-progress)");
  149. if(dlg.length){
  150. dlg.dialog("close");
  151. }
  152. }};
  153. if(typeof _19=="string"){
  154. var _1b=_1a[_19];
  155. return _1b();
  156. }
  157. _19=_19||{};
  158. var _1c=$.extend({},{title:"",minHeight:0,content:undefined,msg:"",text:undefined,interval:300},_19);
  159. var dlg=_d($.extend({},$.messager.defaults,{content:"<div class=\"messager-progress\"><div class=\"messager-p-msg\">"+_1c.msg+"</div><div class=\"messager-p-bar\"></div></div>",closable:false,doSize:false},_1c,{onClose:function(){
  160. if(this.timer){
  161. clearInterval(this.timer);
  162. }
  163. if(_19.onClose){
  164. _19.onClose.call(this);
  165. }else{
  166. $.messager.defaults.onClose.call(this);
  167. }
  168. }}));
  169. var bar=dlg.find("div.messager-p-bar");
  170. bar.progressbar({text:_1c.text});
  171. dlg.dialog("resize");
  172. if(_1c.interval){
  173. dlg[0].timer=setInterval(function(){
  174. var v=bar.progressbar("getValue");
  175. v+=10;
  176. if(v>100){
  177. v=0;
  178. }
  179. bar.progressbar("setValue",v);
  180. },_1c.interval);
  181. }
  182. return dlg;
  183. }};
  184. $.messager.defaults=$.extend({},$.fn.dialog.defaults,{ok:"Ok",cancel:"Cancel",width:300,height:"auto",minHeight:150,modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,fn:function(){
  185. }});
  186. })(jQuery);