ligerTip.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * jQuery ligerUI 1.1.9
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2012 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. //气泡,可以在制定位置显示
  12. $.ligerTip = function (p)
  13. {
  14. return $.ligerui.run.call(null, "ligerTip", arguments);
  15. };
  16. //在指定Dom Element右侧显示气泡
  17. //target:将ligerui对象ID附加上
  18. $.fn.ligerTip = function (options)
  19. {
  20. this.each(function ()
  21. {
  22. var p = $.extend({}, $.ligerDefaults.ElementTip, options || {});
  23. p.target = p.target || this;
  24. //如果是自动模式:鼠标经过时显示,移开时关闭
  25. if (p.auto || options == undefined)
  26. {
  27. if (!p.content)
  28. {
  29. p.content = this.title;
  30. if (p.removeTitle)
  31. $(this).removeAttr("title");
  32. }
  33. p.content = p.content || this.title;
  34. $(this).bind('mouseover.tip', function ()
  35. {
  36. p.x = $(this).offset().left + $(this).width() + (p.distanceX || 0);
  37. p.y = $(this).offset().top + (p.distanceY || 0);
  38. $.ligerTip(p);
  39. }).bind('mouseout.tip', function ()
  40. {
  41. var tipmanager = $.ligerui.managers[this.ligeruitipid];
  42. if (tipmanager)
  43. {
  44. tipmanager.remove();
  45. }
  46. });
  47. }
  48. else
  49. {
  50. if (p.target.ligeruitipid) return;
  51. p.x = $(this).offset().left + $(this).width() + (p.distanceX || 0);
  52. p.y = $(this).offset().top + (p.distanceY || 0);
  53. p.x = p.x || 0;
  54. p.y = p.y || 0;
  55. $.ligerTip(p);
  56. }
  57. });
  58. return $.ligerui.get(this, 'ligeruitipid');
  59. };
  60. //关闭指定在Dom Element(附加了ligerui对象ID,属性名"ligeruitipid")显示的气泡
  61. $.fn.ligerHideTip = function (options)
  62. {
  63. return this.each(function ()
  64. {
  65. var p = options || {};
  66. if (p.isLabel == undefined)
  67. {
  68. //如果是lable,将查找指定的input,并找到ligerui对象ID
  69. p.isLabel = this.tagName.toLowerCase() == "label" && $(this).attr("for") != null;
  70. }
  71. var target = this;
  72. if (p.isLabel)
  73. {
  74. var forele = $("#" + $(this).attr("for"));
  75. if (forele.length == 0) return;
  76. target = forele[0];
  77. }
  78. var tipmanager = $.ligerui.managers[target.ligeruitipid];
  79. if (tipmanager)
  80. {
  81. tipmanager.remove();
  82. }
  83. }).unbind('mouseover.tip').unbind('mouseout.tip');
  84. };
  85. $.fn.ligerGetTipManager = function ()
  86. {
  87. return $.ligerui.get(this);
  88. };
  89. $.ligerDefaults = $.ligerDefaults || {};
  90. //隐藏气泡
  91. $.ligerDefaults.HideTip = {};
  92. //气泡
  93. $.ligerDefaults.Tip = {
  94. content: null,
  95. callback: null,
  96. width: 150,
  97. height: null,
  98. x: 0,
  99. y: 0,
  100. appendIdTo: null, //保存ID到那一个对象(jQuery)(待移除)
  101. target: null,
  102. auto: null, //是否自动模式,如果是,那么:鼠标经过时显示,移开时关闭,并且当content为空时自动读取attr[title]
  103. removeTitle: true //自动模式时,默认是否移除掉title
  104. };
  105. //在指定Dom Element右侧显示气泡,通过$.fn.ligerTip调用
  106. $.ligerDefaults.ElementTip = {
  107. distanceX: 1,
  108. distanceY: -3,
  109. auto: null,
  110. removeTitle: true
  111. };
  112. $.ligerMethos.Tip = {};
  113. $.ligerui.controls.Tip = function (options)
  114. {
  115. $.ligerui.controls.Tip.base.constructor.call(this, null, options);
  116. };
  117. $.ligerui.controls.Tip.ligerExtend($.ligerui.core.UIComponent, {
  118. __getType: function ()
  119. {
  120. return 'Tip';
  121. },
  122. __idPrev: function ()
  123. {
  124. return 'Tip';
  125. },
  126. _extendMethods: function ()
  127. {
  128. return $.ligerMethos.Tip;
  129. },
  130. _render: function ()
  131. {
  132. var g = this, p = this.options;
  133. var tip = $('<div class="l-verify-tip"><div class="l-verify-tip-corner"></div><div class="l-verify-tip-content"></div></div>');
  134. g.tip = tip;
  135. g.tip.attr("id", g.id);
  136. if (p.content)
  137. {
  138. $("> .l-verify-tip-content:first", tip).html(p.content);
  139. tip.appendTo('body');
  140. }
  141. else
  142. {
  143. return;
  144. }
  145. tip.css({ left: p.x, top: p.y }).show();
  146. p.width && $("> .l-verify-tip-content:first", tip).width(p.width - 8);
  147. p.height && $("> .l-verify-tip-content:first", tip).width(p.height);
  148. eee = p.appendIdTo;
  149. if (p.appendIdTo)
  150. {
  151. p.appendIdTo.attr("ligerTipId", g.id);
  152. }
  153. if (p.target)
  154. {
  155. $(p.target).attr("ligerTipId", g.id);
  156. p.target.ligeruitipid = g.id;
  157. }
  158. p.callback && p.callback(tip);
  159. g.set(p);
  160. },
  161. _setContent: function (content)
  162. {
  163. $("> .l-verify-tip-content:first", this.tip).html(content);
  164. },
  165. remove: function ()
  166. {
  167. if (this.options.appendIdTo)
  168. {
  169. this.options.appendIdTo.removeAttr("ligerTipId");
  170. }
  171. if (this.options.target)
  172. {
  173. $(this.options.target).removeAttr("ligerTipId");
  174. this.options.target.ligeruitipid = null;
  175. }
  176. this.tip.remove();
  177. }
  178. });
  179. })(jQuery);