jquery.tooltip.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * EasyUI for jQuery 1.6.10
  3. *
  4. * Copyright (c) 2009-2018 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(_2){
  12. $(_2).addClass("tooltip-f");
  13. };
  14. function _3(_4){
  15. var _5=$.data(_4,"tooltip").options;
  16. $(_4).unbind(".tooltip").bind(_5.showEvent+".tooltip",function(e){
  17. $(_4).tooltip("show",e);
  18. }).bind(_5.hideEvent+".tooltip",function(e){
  19. $(_4).tooltip("hide",e);
  20. }).bind("mousemove.tooltip",function(e){
  21. if(_5.trackMouse){
  22. _5.trackMouseX=e.pageX;
  23. _5.trackMouseY=e.pageY;
  24. $(_4).tooltip("reposition");
  25. }
  26. });
  27. };
  28. function _6(_7){
  29. var _8=$.data(_7,"tooltip");
  30. if(_8.showTimer){
  31. clearTimeout(_8.showTimer);
  32. _8.showTimer=null;
  33. }
  34. if(_8.hideTimer){
  35. clearTimeout(_8.hideTimer);
  36. _8.hideTimer=null;
  37. }
  38. };
  39. function _9(_a){
  40. var _b=$.data(_a,"tooltip");
  41. if(!_b||!_b.tip){
  42. return;
  43. }
  44. var _c=_b.options;
  45. var _d=_b.tip;
  46. var _e={left:-100000,top:-100000};
  47. if($(_a).is(":visible")){
  48. _e=_f(_c.position);
  49. if(_c.position=="top"&&_e.top<0){
  50. _e=_f("bottom");
  51. }else{
  52. if((_c.position=="bottom")&&(_e.top+_d._outerHeight()>$(window)._outerHeight()+$(document).scrollTop())){
  53. _e=_f("top");
  54. }
  55. }
  56. if(_e.left<0){
  57. if(_c.position=="left"){
  58. _e=_f("right");
  59. }else{
  60. $(_a).tooltip("arrow").css("left",_d._outerWidth()/2+_e.left);
  61. _e.left=0;
  62. }
  63. }else{
  64. if(_e.left+_d._outerWidth()>$(window)._outerWidth()+$(document)._scrollLeft()){
  65. if(_c.position=="right"){
  66. _e=_f("left");
  67. }else{
  68. var _10=_e.left;
  69. _e.left=$(window)._outerWidth()+$(document)._scrollLeft()-_d._outerWidth();
  70. $(_a).tooltip("arrow").css("left",_d._outerWidth()/2-(_e.left-_10));
  71. }
  72. }
  73. }
  74. }
  75. _d.css({left:_e.left,top:_e.top,zIndex:(_c.zIndex!=undefined?_c.zIndex:($.fn.window?$.fn.window.defaults.zIndex++:""))});
  76. _c.onPosition.call(_a,_e.left,_e.top);
  77. function _f(_11){
  78. _c.position=_11||"bottom";
  79. _d.removeClass("tooltip-top tooltip-bottom tooltip-left tooltip-right").addClass("tooltip-"+_c.position);
  80. var _12,top;
  81. var _13=$.isFunction(_c.deltaX)?_c.deltaX.call(_a,_c.position):_c.deltaX;
  82. var _14=$.isFunction(_c.deltaY)?_c.deltaY.call(_a,_c.position):_c.deltaY;
  83. if(_c.trackMouse){
  84. t=$();
  85. _12=_c.trackMouseX+_13;
  86. top=_c.trackMouseY+_14;
  87. }else{
  88. var t=$(_a);
  89. _12=t.offset().left+_13;
  90. top=t.offset().top+_14;
  91. }
  92. switch(_c.position){
  93. case "right":
  94. _12+=t._outerWidth()+12+(_c.trackMouse?12:0);
  95. if(_c.valign=="middle"){
  96. top-=(_d._outerHeight()-t._outerHeight())/2;
  97. }
  98. break;
  99. case "left":
  100. _12-=_d._outerWidth()+12+(_c.trackMouse?12:0);
  101. if(_c.valign=="middle"){
  102. top-=(_d._outerHeight()-t._outerHeight())/2;
  103. }
  104. break;
  105. case "top":
  106. _12-=(_d._outerWidth()-t._outerWidth())/2;
  107. top-=_d._outerHeight()+12+(_c.trackMouse?12:0);
  108. break;
  109. case "bottom":
  110. _12-=(_d._outerWidth()-t._outerWidth())/2;
  111. top+=t._outerHeight()+12+(_c.trackMouse?12:0);
  112. break;
  113. }
  114. return {left:_12,top:top};
  115. };
  116. };
  117. function _15(_16,e){
  118. var _17=$.data(_16,"tooltip");
  119. var _18=_17.options;
  120. var tip=_17.tip;
  121. if(!tip){
  122. tip=$("<div tabindex=\"-1\" class=\"tooltip\">"+"<div class=\"tooltip-content\"></div>"+"<div class=\"tooltip-arrow-outer\"></div>"+"<div class=\"tooltip-arrow\"></div>"+"</div>").appendTo("body");
  123. _17.tip=tip;
  124. _19(_16);
  125. }
  126. _6(_16);
  127. _17.showTimer=setTimeout(function(){
  128. $(_16).tooltip("reposition");
  129. tip.show();
  130. _18.onShow.call(_16,e);
  131. var _1a=tip.children(".tooltip-arrow-outer");
  132. var _1b=tip.children(".tooltip-arrow");
  133. var bc="border-"+_18.position+"-color";
  134. _1a.add(_1b).css({borderTopColor:"",borderBottomColor:"",borderLeftColor:"",borderRightColor:""});
  135. _1a.css(bc,tip.css(bc));
  136. _1b.css(bc,tip.css("backgroundColor"));
  137. },_18.showDelay);
  138. };
  139. function _1c(_1d,e){
  140. var _1e=$.data(_1d,"tooltip");
  141. if(_1e&&_1e.tip){
  142. _6(_1d);
  143. _1e.hideTimer=setTimeout(function(){
  144. _1e.tip.hide();
  145. _1e.options.onHide.call(_1d,e);
  146. },_1e.options.hideDelay);
  147. }
  148. };
  149. function _19(_1f,_20){
  150. var _21=$.data(_1f,"tooltip");
  151. var _22=_21.options;
  152. if(_20){
  153. _22.content=_20;
  154. }
  155. if(!_21.tip){
  156. return;
  157. }
  158. var cc=typeof _22.content=="function"?_22.content.call(_1f):_22.content;
  159. _21.tip.children(".tooltip-content").html(cc);
  160. _22.onUpdate.call(_1f,cc);
  161. };
  162. function _23(_24){
  163. var _25=$.data(_24,"tooltip");
  164. if(_25){
  165. _6(_24);
  166. var _26=_25.options;
  167. if(_25.tip){
  168. _25.tip.remove();
  169. }
  170. if(_26._title){
  171. $(_24).attr("title",_26._title);
  172. }
  173. $.removeData(_24,"tooltip");
  174. $(_24).unbind(".tooltip").removeClass("tooltip-f");
  175. _26.onDestroy.call(_24);
  176. }
  177. };
  178. $.fn.tooltip=function(_27,_28){
  179. if(typeof _27=="string"){
  180. return $.fn.tooltip.methods[_27](this,_28);
  181. }
  182. _27=_27||{};
  183. return this.each(function(){
  184. var _29=$.data(this,"tooltip");
  185. if(_29){
  186. $.extend(_29.options,_27);
  187. }else{
  188. $.data(this,"tooltip",{options:$.extend({},$.fn.tooltip.defaults,$.fn.tooltip.parseOptions(this),_27)});
  189. _1(this);
  190. }
  191. _3(this);
  192. _19(this);
  193. });
  194. };
  195. $.fn.tooltip.methods={options:function(jq){
  196. return $.data(jq[0],"tooltip").options;
  197. },tip:function(jq){
  198. return $.data(jq[0],"tooltip").tip;
  199. },arrow:function(jq){
  200. return jq.tooltip("tip").children(".tooltip-arrow-outer,.tooltip-arrow");
  201. },show:function(jq,e){
  202. return jq.each(function(){
  203. _15(this,e);
  204. });
  205. },hide:function(jq,e){
  206. return jq.each(function(){
  207. _1c(this,e);
  208. });
  209. },update:function(jq,_2a){
  210. return jq.each(function(){
  211. _19(this,_2a);
  212. });
  213. },reposition:function(jq){
  214. return jq.each(function(){
  215. _9(this);
  216. });
  217. },destroy:function(jq){
  218. return jq.each(function(){
  219. _23(this);
  220. });
  221. }};
  222. $.fn.tooltip.parseOptions=function(_2b){
  223. var t=$(_2b);
  224. var _2c=$.extend({},$.parser.parseOptions(_2b,["position","showEvent","hideEvent","content",{trackMouse:"boolean",deltaX:"number",deltaY:"number",showDelay:"number",hideDelay:"number"}]),{_title:t.attr("title")});
  225. t.attr("title","");
  226. if(!_2c.content){
  227. _2c.content=_2c._title;
  228. }
  229. return _2c;
  230. };
  231. $.fn.tooltip.defaults={position:"bottom",valign:"middle",content:null,trackMouse:false,deltaX:0,deltaY:0,showEvent:"mouseenter",hideEvent:"mouseleave",showDelay:200,hideDelay:100,onShow:function(e){
  232. },onHide:function(e){
  233. },onUpdate:function(_2d){
  234. },onPosition:function(_2e,top){
  235. },onDestroy:function(){
  236. }};
  237. })(jQuery);