jquery.tooltip.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**
  2. * jQuery EasyUI 1.3.4
  3. *
  4. * Copyright (c) 2009-2013 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL or commercial licenses
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. * http://www.gnu.org/licenses/gpl.txt
  9. * http://www.jeasyui.com/license_commercial.php
  10. *
  11. */
  12. (function($){
  13. function _1(_2){
  14. $(_2).addClass("tooltip-f");
  15. };
  16. function _3(_4){
  17. var _5=$.data(_4,"tooltip").options;
  18. $(_4).unbind(".tooltip").bind(_5.showEvent+".tooltip",function(e){
  19. _10(_4,e);
  20. }).bind(_5.hideEvent+".tooltip",function(e){
  21. _17(_4,e);
  22. }).bind("mousemove.tooltip",function(e){
  23. if(_5.trackMouse){
  24. _5.trackMouseX=e.pageX;
  25. _5.trackMouseY=e.pageY;
  26. _6(_4);
  27. }
  28. });
  29. };
  30. function _7(_8){
  31. var _9=$.data(_8,"tooltip");
  32. if(_9.showTimer){
  33. clearTimeout(_9.showTimer);
  34. _9.showTimer=null;
  35. }
  36. if(_9.hideTimer){
  37. clearTimeout(_9.hideTimer);
  38. _9.hideTimer=null;
  39. }
  40. };
  41. function _6(_a){
  42. var _b=$.data(_a,"tooltip");
  43. if(!_b||!_b.tip){
  44. return;
  45. }
  46. var _c=_b.options;
  47. var _d=_b.tip;
  48. if(_c.trackMouse){
  49. t=$();
  50. var _e=_c.trackMouseX+_c.deltaX;
  51. var _f=_c.trackMouseY+_c.deltaY;
  52. }else{
  53. var t=$(_a);
  54. var _e=t.offset().left+_c.deltaX;
  55. var _f=t.offset().top+_c.deltaY;
  56. }
  57. switch(_c.position){
  58. case "right":
  59. _e+=t._outerWidth()+12+(_c.trackMouse?12:0);
  60. _f-=(_d._outerHeight()-t._outerHeight())/2;
  61. break;
  62. case "left":
  63. _e-=_d._outerWidth()+12+(_c.trackMouse?12:0);
  64. _f-=(_d._outerHeight()-t._outerHeight())/2;
  65. break;
  66. case "top":
  67. _e-=(_d._outerWidth()-t._outerWidth())/2;
  68. _f-=_d._outerHeight()+12+(_c.trackMouse?12:0);
  69. break;
  70. case "bottom":
  71. _e-=(_d._outerWidth()-t._outerWidth())/2;
  72. _f+=t._outerHeight()+12+(_c.trackMouse?12:0);
  73. break;
  74. }
  75. _d.css({left:_e,top:_f,zIndex:(_c.zIndex!=undefined?_c.zIndex:($.fn.window?$.fn.window.defaults.zIndex++:""))});
  76. _c.onPosition.call(_a,_e,_f);
  77. };
  78. function _10(_11,e){
  79. var _12=$.data(_11,"tooltip");
  80. var _13=_12.options;
  81. var tip=_12.tip;
  82. if(!tip){
  83. 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");
  84. _12.tip=tip;
  85. _14(_11);
  86. }
  87. tip.removeClass("tooltip-top tooltip-bottom tooltip-left tooltip-right").addClass("tooltip-"+_13.position);
  88. _7(_11);
  89. _12.showTimer=setTimeout(function(){
  90. _6(_11);
  91. tip.show();
  92. _13.onShow.call(_11,e);
  93. var _15=tip.children(".tooltip-arrow-outer");
  94. var _16=tip.children(".tooltip-arrow");
  95. var bc="border-"+_13.position+"-color";
  96. _15.add(_16).css({borderTopColor:"",borderBottomColor:"",borderLeftColor:"",borderRightColor:""});
  97. _15.css(bc,tip.css(bc));
  98. _16.css(bc,tip.css("backgroundColor"));
  99. },_13.showDelay);
  100. };
  101. function _17(_18,e){
  102. var _19=$.data(_18,"tooltip");
  103. if(_19&&_19.tip){
  104. _7(_18);
  105. _19.hideTimer=setTimeout(function(){
  106. _19.tip.hide();
  107. _19.options.onHide.call(_18,e);
  108. },_19.options.hideDelay);
  109. }
  110. };
  111. function _14(_1a,_1b){
  112. var _1c=$.data(_1a,"tooltip");
  113. var _1d=_1c.options;
  114. if(_1b){
  115. _1d.content=_1b;
  116. }
  117. if(!_1c.tip){
  118. return;
  119. }
  120. var cc=typeof _1d.content=="function"?_1d.content.call(_1a):_1d.content;
  121. _1c.tip.children(".tooltip-content").html(cc);
  122. _1d.onUpdate.call(_1a,cc);
  123. };
  124. function _1e(_1f){
  125. var _20=$.data(_1f,"tooltip");
  126. if(_20){
  127. _7(_1f);
  128. var _21=_20.options;
  129. if(_20.tip){
  130. _20.tip.remove();
  131. }
  132. if(_21._title){
  133. $(_1f).attr("title",_21._title);
  134. }
  135. $.removeData(_1f,"tooltip");
  136. $(_1f).unbind(".tooltip").removeClass("tooltip-f");
  137. _21.onDestroy.call(_1f);
  138. }
  139. };
  140. $.fn.tooltip=function(_22,_23){
  141. if(typeof _22=="string"){
  142. return $.fn.tooltip.methods[_22](this,_23);
  143. }
  144. _22=_22||{};
  145. return this.each(function(){
  146. var _24=$.data(this,"tooltip");
  147. if(_24){
  148. $.extend(_24.options,_22);
  149. }else{
  150. $.data(this,"tooltip",{options:$.extend({},$.fn.tooltip.defaults,$.fn.tooltip.parseOptions(this),_22)});
  151. _1(this);
  152. }
  153. _3(this);
  154. _14(this);
  155. });
  156. };
  157. $.fn.tooltip.methods={options:function(jq){
  158. return $.data(jq[0],"tooltip").options;
  159. },tip:function(jq){
  160. return $.data(jq[0],"tooltip").tip;
  161. },arrow:function(jq){
  162. return jq.tooltip("tip").children(".tooltip-arrow-outer,.tooltip-arrow");
  163. },show:function(jq,e){
  164. return jq.each(function(){
  165. _10(this,e);
  166. });
  167. },hide:function(jq,e){
  168. return jq.each(function(){
  169. _17(this,e);
  170. });
  171. },update:function(jq,_25){
  172. return jq.each(function(){
  173. _14(this,_25);
  174. });
  175. },reposition:function(jq){
  176. return jq.each(function(){
  177. _6(this);
  178. });
  179. },destroy:function(jq){
  180. return jq.each(function(){
  181. _1e(this);
  182. });
  183. }};
  184. $.fn.tooltip.parseOptions=function(_26){
  185. var t=$(_26);
  186. var _27=$.extend({},$.parser.parseOptions(_26,["position","showEvent","hideEvent","content",{deltaX:"number",deltaY:"number",showDelay:"number",hideDelay:"number"}]),{_title:t.attr("title")});
  187. t.attr("title","");
  188. if(!_27.content){
  189. _27.content=_27._title;
  190. }
  191. return _27;
  192. };
  193. $.fn.tooltip.defaults={position:"bottom",content:null,trackMouse:false,deltaX:0,deltaY:0,showEvent:"mouseenter",hideEvent:"mouseleave",showDelay:200,hideDelay:100,onShow:function(e){
  194. },onHide:function(e){
  195. },onUpdate:function(_28){
  196. },onPosition:function(_29,top){
  197. },onDestroy:function(){
  198. }};
  199. })(jQuery);