jquery.tooltip.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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(_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. top-=(_d._outerHeight()-t._outerHeight())/2;
  96. break;
  97. case "left":
  98. _12-=_d._outerWidth()+12+(_c.trackMouse?12:0);
  99. top-=(_d._outerHeight()-t._outerHeight())/2;
  100. break;
  101. case "top":
  102. _12-=(_d._outerWidth()-t._outerWidth())/2;
  103. top-=_d._outerHeight()+12+(_c.trackMouse?12:0);
  104. break;
  105. case "bottom":
  106. _12-=(_d._outerWidth()-t._outerWidth())/2;
  107. top+=t._outerHeight()+12+(_c.trackMouse?12:0);
  108. break;
  109. }
  110. return {left:_12,top:top};
  111. };
  112. };
  113. function _15(_16,e){
  114. var _17=$.data(_16,"tooltip");
  115. var _18=_17.options;
  116. var tip=_17.tip;
  117. if(!tip){
  118. 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");
  119. _17.tip=tip;
  120. _19(_16);
  121. }
  122. _6(_16);
  123. _17.showTimer=setTimeout(function(){
  124. $(_16).tooltip("reposition");
  125. tip.show();
  126. _18.onShow.call(_16,e);
  127. var _1a=tip.children(".tooltip-arrow-outer");
  128. var _1b=tip.children(".tooltip-arrow");
  129. var bc="border-"+_18.position+"-color";
  130. _1a.add(_1b).css({borderTopColor:"",borderBottomColor:"",borderLeftColor:"",borderRightColor:""});
  131. _1a.css(bc,tip.css(bc));
  132. _1b.css(bc,tip.css("backgroundColor"));
  133. },_18.showDelay);
  134. };
  135. function _1c(_1d,e){
  136. var _1e=$.data(_1d,"tooltip");
  137. if(_1e&&_1e.tip){
  138. _6(_1d);
  139. _1e.hideTimer=setTimeout(function(){
  140. _1e.tip.hide();
  141. _1e.options.onHide.call(_1d,e);
  142. },_1e.options.hideDelay);
  143. }
  144. };
  145. function _19(_1f,_20){
  146. var _21=$.data(_1f,"tooltip");
  147. var _22=_21.options;
  148. if(_20){
  149. _22.content=_20;
  150. }
  151. if(!_21.tip){
  152. return;
  153. }
  154. var cc=typeof _22.content=="function"?_22.content.call(_1f):_22.content;
  155. _21.tip.children(".tooltip-content").html(cc);
  156. _22.onUpdate.call(_1f,cc);
  157. };
  158. function _23(_24){
  159. var _25=$.data(_24,"tooltip");
  160. if(_25){
  161. _6(_24);
  162. var _26=_25.options;
  163. if(_25.tip){
  164. _25.tip.remove();
  165. }
  166. if(_26._title){
  167. $(_24).attr("title",_26._title);
  168. }
  169. $.removeData(_24,"tooltip");
  170. $(_24).unbind(".tooltip").removeClass("tooltip-f");
  171. _26.onDestroy.call(_24);
  172. }
  173. };
  174. $.fn.tooltip=function(_27,_28){
  175. if(typeof _27=="string"){
  176. return $.fn.tooltip.methods[_27](this,_28);
  177. }
  178. _27=_27||{};
  179. return this.each(function(){
  180. var _29=$.data(this,"tooltip");
  181. if(_29){
  182. $.extend(_29.options,_27);
  183. }else{
  184. $.data(this,"tooltip",{options:$.extend({},$.fn.tooltip.defaults,$.fn.tooltip.parseOptions(this),_27)});
  185. _1(this);
  186. }
  187. _3(this);
  188. _19(this);
  189. });
  190. };
  191. $.fn.tooltip.methods={options:function(jq){
  192. return $.data(jq[0],"tooltip").options;
  193. },tip:function(jq){
  194. return $.data(jq[0],"tooltip").tip;
  195. },arrow:function(jq){
  196. return jq.tooltip("tip").children(".tooltip-arrow-outer,.tooltip-arrow");
  197. },show:function(jq,e){
  198. return jq.each(function(){
  199. _15(this,e);
  200. });
  201. },hide:function(jq,e){
  202. return jq.each(function(){
  203. _1c(this,e);
  204. });
  205. },update:function(jq,_2a){
  206. return jq.each(function(){
  207. _19(this,_2a);
  208. });
  209. },reposition:function(jq){
  210. return jq.each(function(){
  211. _9(this);
  212. });
  213. },destroy:function(jq){
  214. return jq.each(function(){
  215. _23(this);
  216. });
  217. }};
  218. $.fn.tooltip.parseOptions=function(_2b){
  219. var t=$(_2b);
  220. var _2c=$.extend({},$.parser.parseOptions(_2b,["position","showEvent","hideEvent","content",{trackMouse:"boolean",deltaX:"number",deltaY:"number",showDelay:"number",hideDelay:"number"}]),{_title:t.attr("title")});
  221. t.attr("title","");
  222. if(!_2c.content){
  223. _2c.content=_2c._title;
  224. }
  225. return _2c;
  226. };
  227. $.fn.tooltip.defaults={position:"bottom",content:null,trackMouse:false,deltaX:0,deltaY:0,showEvent:"mouseenter",hideEvent:"mouseleave",showDelay:200,hideDelay:100,onShow:function(e){
  228. },onHide:function(e){
  229. },onUpdate:function(_2d){
  230. },onPosition:function(_2e,top){
  231. },onDestroy:function(){
  232. }};
  233. })(jQuery);