/hippo/src/main/webapp/ext/src/widgets/tips/QuickTip.js

http://hdbc.googlecode.com/ · JavaScript · 207 lines · 148 code · 11 blank · 48 comment · 43 complexity · 8105e6dd82480186a63717e500e75212 MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.QuickTip
  9. * @extends Ext.ToolTip
  10. * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global
  11. * {@link Ext.QuickTips} instance. See the QuickTips class header for additional usage details and examples.
  12. * @constructor
  13. * Create a new Tip
  14. * @param {Object} config The configuration options
  15. */
  16. Ext.QuickTip = Ext.extend(Ext.ToolTip, {
  17. /**
  18. * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to associate with this quicktip (defaults to the document).
  19. */
  20. /**
  21. * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false).
  22. */
  23. interceptTitles : false,
  24. // private
  25. tagConfig : {
  26. namespace : "ext",
  27. attribute : "qtip",
  28. width : "qwidth",
  29. target : "target",
  30. title : "qtitle",
  31. hide : "hide",
  32. cls : "qclass",
  33. align : "qalign",
  34. anchor : "anchor"
  35. },
  36. // private
  37. initComponent : function(){
  38. this.target = this.target || Ext.getDoc();
  39. this.targets = this.targets || {};
  40. Ext.QuickTip.superclass.initComponent.call(this);
  41. },
  42. /**
  43. * Configures a new quick tip instance and assigns it to a target element. The following config values are
  44. * supported (for example usage, see the {@link Ext.QuickTips} class header):
  45. * <div class="mdetail-params"><ul>
  46. * <li>autoHide</li>
  47. * <li>cls</li>
  48. * <li>dismissDelay (overrides the singleton value)</li>
  49. * <li>target (required)</li>
  50. * <li>text (required)</li>
  51. * <li>title</li>
  52. * <li>width</li></ul></div>
  53. * @param {Object} config The config object
  54. */
  55. register : function(config){
  56. var cs = Ext.isArray(config) ? config : arguments;
  57. for(var i = 0, len = cs.length; i < len; i++){
  58. var c = cs[i];
  59. var target = c.target;
  60. if(target){
  61. if(Ext.isArray(target)){
  62. for(var j = 0, jlen = target.length; j < jlen; j++){
  63. this.targets[Ext.id(target[j])] = c;
  64. }
  65. } else{
  66. this.targets[Ext.id(target)] = c;
  67. }
  68. }
  69. }
  70. },
  71. /**
  72. * Removes this quick tip from its element and destroys it.
  73. * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
  74. */
  75. unregister : function(el){
  76. delete this.targets[Ext.id(el)];
  77. },
  78. /**
  79. * Hides a visible tip or cancels an impending show for a particular element.
  80. * @param {String/HTMLElement/Element} el The element that is the target of the tip.
  81. */
  82. cancelShow: function(el){
  83. var at = this.activeTarget;
  84. el = Ext.get(el).dom;
  85. if(this.isVisible()){
  86. if(at && at.el == el){
  87. this.hide();
  88. }
  89. }else if(at && at.el == el){
  90. this.clearTimer('show');
  91. }
  92. },
  93. // private
  94. onTargetOver : function(e){
  95. if(this.disabled){
  96. return;
  97. }
  98. this.targetXY = e.getXY();
  99. var t = e.getTarget();
  100. if(!t || t.nodeType !== 1 || t == document || t == document.body){
  101. return;
  102. }
  103. if(this.activeTarget && t == this.activeTarget.el){
  104. this.clearTimer('hide');
  105. this.show();
  106. return;
  107. }
  108. if(t && this.targets[t.id]){
  109. this.activeTarget = this.targets[t.id];
  110. this.activeTarget.el = t;
  111. this.anchor = this.activeTarget.anchor;
  112. if(this.anchor){
  113. this.anchorTarget = t;
  114. }
  115. this.delayShow();
  116. return;
  117. }
  118. var ttp, et = Ext.fly(t), cfg = this.tagConfig;
  119. var ns = cfg.namespace;
  120. if(this.interceptTitles && t.title){
  121. ttp = t.title;
  122. t.qtip = ttp;
  123. t.removeAttribute("title");
  124. e.preventDefault();
  125. } else{
  126. ttp = t.qtip || et.getAttribute(cfg.attribute, ns);
  127. }
  128. if(ttp){
  129. var autoHide = et.getAttribute(cfg.hide, ns);
  130. this.activeTarget = {
  131. el: t,
  132. text: ttp,
  133. width: et.getAttribute(cfg.width, ns),
  134. autoHide: autoHide != "user" && autoHide !== 'false',
  135. title: et.getAttribute(cfg.title, ns),
  136. cls: et.getAttribute(cfg.cls, ns),
  137. align: et.getAttribute(cfg.align, ns)
  138. };
  139. this.anchor = et.getAttribute(cfg.anchor, ns);
  140. if(this.anchor){
  141. this.anchorTarget = t;
  142. }
  143. this.delayShow();
  144. }
  145. },
  146. // private
  147. onTargetOut : function(e){
  148. this.clearTimer('show');
  149. if(this.autoHide !== false){
  150. this.delayHide();
  151. }
  152. },
  153. // inherit docs
  154. showAt : function(xy){
  155. var t = this.activeTarget;
  156. if(t){
  157. if(!this.rendered){
  158. this.render(Ext.getBody());
  159. this.activeTarget = t;
  160. }
  161. if(t.width){
  162. this.setWidth(t.width);
  163. this.body.setWidth(this.adjustBodyWidth(t.width - this.getFrameWidth()));
  164. this.measureWidth = false;
  165. } else{
  166. this.measureWidth = true;
  167. }
  168. this.setTitle(t.title || '');
  169. this.body.update(t.text);
  170. this.autoHide = t.autoHide;
  171. this.dismissDelay = t.dismissDelay || this.dismissDelay;
  172. if(this.lastCls){
  173. this.el.removeClass(this.lastCls);
  174. delete this.lastCls;
  175. }
  176. if(t.cls){
  177. this.el.addClass(t.cls);
  178. this.lastCls = t.cls;
  179. }
  180. if(this.anchor){
  181. this.constrainPosition = false;
  182. }else if(t.align){ // TODO: this doesn't seem to work consistently
  183. xy = this.el.getAlignToXY(t.el, t.align);
  184. this.constrainPosition = false;
  185. }else{
  186. this.constrainPosition = true;
  187. }
  188. }
  189. Ext.QuickTip.superclass.showAt.call(this, xy);
  190. },
  191. // inherit docs
  192. hide: function(){
  193. delete this.activeTarget;
  194. Ext.QuickTip.superclass.hide.call(this);
  195. }
  196. });