You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1159 lines
38 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.Tip
  17. * @extends Ext.Panel
  18. * @xtype tip
  19. * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
  20. * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
  21. * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
  22. * @constructor
  23. * Create a new Tip
  24. * @param {Object} config The configuration options
  25. */
  26. Ext.Tip = Ext.extend(Ext.Panel, {
  27. /**
  28. * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
  29. */
  30. /**
  31. * @cfg {Number} width
  32. * Width in pixels of the tip (defaults to auto). Width will be ignored if it exceeds the bounds of
  33. * {@link #minWidth} or {@link #maxWidth}. The maximum supported value is 500.
  34. */
  35. /**
  36. * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
  37. */
  38. minWidth : 40,
  39. /**
  40. * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300). The maximum supported value is 500.
  41. */
  42. maxWidth : 300,
  43. /**
  44. * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
  45. * for bottom-right shadow (defaults to "sides").
  46. */
  47. shadow : "sides",
  48. /**
  49. * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
  50. * for this tip relative to its element of origin (defaults to "tl-bl?").
  51. */
  52. defaultAlign : "tl-bl?",
  53. autoRender: true,
  54. quickShowInterval : 250,
  55. // private panel overrides
  56. frame:true,
  57. hidden:true,
  58. baseCls: 'x-tip',
  59. floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
  60. autoHeight:true,
  61. closeAction: 'hide',
  62. // private
  63. initComponent : function(){
  64. Ext.Tip.superclass.initComponent.call(this);
  65. if(this.closable && !this.title){
  66. this.elements += ',header';
  67. }
  68. },
  69. // private
  70. afterRender : function(){
  71. Ext.Tip.superclass.afterRender.call(this);
  72. if(this.closable){
  73. this.addTool({
  74. id: 'close',
  75. handler: this[this.closeAction],
  76. scope: this
  77. });
  78. }
  79. },
  80. /**
  81. * Shows this tip at the specified XY position. Example usage:
  82. * <pre><code>
  83. // Show the tip at x:50 and y:100
  84. tip.showAt([50,100]);
  85. </code></pre>
  86. * @param {Array} xy An array containing the x and y coordinates
  87. */
  88. showAt : function(xy){
  89. Ext.Tip.superclass.show.call(this);
  90. if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){
  91. this.doAutoWidth();
  92. }
  93. if(this.constrainPosition){
  94. xy = this.el.adjustForConstraints(xy);
  95. }
  96. this.setPagePosition(xy[0], xy[1]);
  97. },
  98. // protected
  99. doAutoWidth : function(adjust){
  100. adjust = adjust || 0;
  101. var bw = this.body.getTextWidth();
  102. if(this.title){
  103. bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));
  104. }
  105. bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr") + adjust;
  106. this.setWidth(bw.constrain(this.minWidth, this.maxWidth));
  107. // IE7 repaint bug on initial show
  108. if(Ext.isIE7 && !this.repainted){
  109. this.el.repaint();
  110. this.repainted = true;
  111. }
  112. },
  113. /**
  114. * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}
  115. * anchor position value. Example usage:
  116. * <pre><code>
  117. // Show the tip at the default position ('tl-br?')
  118. tip.showBy('my-el');
  119. // Show the tip's top-left corner anchored to the element's top-right corner
  120. tip.showBy('my-el', 'tl-tr');
  121. </code></pre>
  122. * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to
  123. * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or
  124. * {@link #defaultAlign} if specified).
  125. */
  126. showBy : function(el, pos){
  127. if(!this.rendered){
  128. this.render(Ext.getBody());
  129. }
  130. this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
  131. },
  132. initDraggable : function(){
  133. this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);
  134. this.header.addClass('x-tip-draggable');
  135. }
  136. });
  137. Ext.reg('tip', Ext.Tip);
  138. // private - custom Tip DD implementation
  139. Ext.Tip.DD = function(tip, config){
  140. Ext.apply(this, config);
  141. this.tip = tip;
  142. Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);
  143. this.setHandleElId(tip.header.id);
  144. this.scroll = false;
  145. };
  146. Ext.extend(Ext.Tip.DD, Ext.dd.DD, {
  147. moveOnly:true,
  148. scroll:false,
  149. headerOffsets:[100, 25],
  150. startDrag : function(){
  151. this.tip.el.disableShadow();
  152. },
  153. endDrag : function(e){
  154. this.tip.el.enableShadow(true);
  155. }
  156. });/**
  157. * @class Ext.ToolTip
  158. * @extends Ext.Tip
  159. * A standard tooltip implementation for providing additional information when hovering over a target element.
  160. * @xtype tooltip
  161. * @constructor
  162. * Create a new Tooltip
  163. * @param {Object} config The configuration options
  164. */
  165. Ext.ToolTip = Ext.extend(Ext.Tip, {
  166. /**
  167. * When a Tooltip is configured with the <code>{@link #delegate}</code>
  168. * option to cause selected child elements of the <code>{@link #target}</code>
  169. * Element to each trigger a seperate show event, this property is set to
  170. * the DOM element which triggered the show.
  171. * @type DOMElement
  172. * @property triggerElement
  173. */
  174. /**
  175. * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to monitor
  176. * for mouseover events to trigger showing this ToolTip.
  177. */
  178. /**
  179. * @cfg {Boolean} autoHide True to automatically hide the tooltip after the
  180. * mouse exits the target element or after the <code>{@link #dismissDelay}</code>
  181. * has expired if set (defaults to true). If <code>{@link closable} = true</code>
  182. * a close tool button will be rendered into the tooltip header.
  183. */
  184. /**
  185. * @cfg {Number} showDelay Delay in milliseconds before the tooltip displays
  186. * after the mouse enters the target element (defaults to 500)
  187. */
  188. showDelay : 500,
  189. /**
  190. * @cfg {Number} hideDelay Delay in milliseconds after the mouse exits the
  191. * target element but before the tooltip actually hides (defaults to 200).
  192. * Set to 0 for the tooltip to hide immediately.
  193. */
  194. hideDelay : 200,
  195. /**
  196. * @cfg {Number} dismissDelay Delay in milliseconds before the tooltip
  197. * automatically hides (defaults to 5000). To disable automatic hiding, set
  198. * dismissDelay = 0.
  199. */
  200. dismissDelay : 5000,
  201. /**
  202. * @cfg {Array} mouseOffset An XY offset from the mouse position where the
  203. * tooltip should be shown (defaults to [15,18]).
  204. */
  205. /**
  206. * @cfg {Boolean} trackMouse True to have the tooltip follow the mouse as it
  207. * moves over the target element (defaults to false).
  208. */
  209. trackMouse : false,
  210. /**
  211. * @cfg {Boolean} anchorToTarget True to anchor the tooltip to the target
  212. * element, false to anchor it relative to the mouse coordinates (defaults
  213. * to true). When <code>anchorToTarget</code> is true, use
  214. * <code>{@link #defaultAlign}</code> to control tooltip alignment to the
  215. * target element. When <code>anchorToTarget</code> is false, use
  216. * <code>{@link #anchorPosition}</code> instead to control alignment.
  217. */
  218. anchorToTarget : true,
  219. /**
  220. * @cfg {Number} anchorOffset A numeric pixel value used to offset the
  221. * default position of the anchor arrow (defaults to 0). When the anchor
  222. * position is on the top or bottom of the tooltip, <code>anchorOffset</code>
  223. * will be used as a horizontal offset. Likewise, when the anchor position
  224. * is on the left or right side, <code>anchorOffset</code> will be used as
  225. * a vertical offset.
  226. */
  227. anchorOffset : 0,
  228. /**
  229. * @cfg {String} delegate <p>Optional. A {@link Ext.DomQuery DomQuery}
  230. * selector which allows selection of individual elements within the
  231. * <code>{@link #target}</code> element to trigger showing and hiding the
  232. * ToolTip as the mouse moves within the target.</p>
  233. * <p>When specified, the child element of the target which caused a show
  234. * event is placed into the <code>{@link #triggerElement}</code> property
  235. * before the ToolTip is shown.</p>
  236. * <p>This may be useful when a Component has regular, repeating elements
  237. * in it, each of which need a Tooltip which contains information specific
  238. * to that element. For example:</p><pre><code>
  239. var myGrid = new Ext.grid.gridPanel(gridConfig);
  240. myGrid.on('render', function(grid) {
  241. var store = grid.getStore(); // Capture the Store.
  242. var view = grid.getView(); // Capture the GridView.
  243. myGrid.tip = new Ext.ToolTip({
  244. target: view.mainBody, // The overall target element.
  245. delegate: '.x-grid3-row', // Each grid row causes its own seperate show and hide.
  246. trackMouse: true, // Moving within the row should not hide the tip.
  247. renderTo: document.body, // Render immediately so that tip.body can be
  248. // referenced prior to the first show.
  249. listeners: { // Change content dynamically depending on which element
  250. // triggered the show.
  251. beforeshow: function updateTipBody(tip) {
  252. var rowIndex = view.findRowIndex(tip.triggerElement);
  253. tip.body.dom.innerHTML = 'Over Record ID ' + store.getAt(rowIndex).id;
  254. }
  255. }
  256. });
  257. });
  258. *</code></pre>
  259. */
  260. // private
  261. targetCounter : 0,
  262. constrainPosition : false,
  263. // private
  264. initComponent : function(){
  265. Ext.ToolTip.superclass.initComponent.call(this);
  266. this.lastActive = new Date();
  267. this.initTarget(this.target);
  268. this.origAnchor = this.anchor;
  269. },
  270. // private
  271. onRender : function(ct, position){
  272. Ext.ToolTip.superclass.onRender.call(this, ct, position);
  273. this.anchorCls = 'x-tip-anchor-' + this.getAnchorPosition();
  274. this.anchorEl = this.el.createChild({
  275. cls: 'x-tip-anchor ' + this.anchorCls
  276. });
  277. },
  278. // private
  279. afterRender : function(){
  280. Ext.ToolTip.superclass.afterRender.call(this);
  281. this.anchorEl.setStyle('z-index', this.el.getZIndex() + 1).setVisibilityMode(Ext.Element.DISPLAY);
  282. },
  283. /**
  284. * Binds this ToolTip to the specified element. The tooltip will be displayed when the mouse moves over the element.
  285. * @param {Mixed} t The Element, HtmlElement, or ID of an element to bind to
  286. */
  287. initTarget : function(target){
  288. var t;
  289. if((t = Ext.get(target))){
  290. if(this.target){
  291. var tg = Ext.get(this.target);
  292. this.mun(tg, 'mouseover', this.onTargetOver, this);
  293. this.mun(tg, 'mouseout', this.onTargetOut, this);
  294. this.mun(tg, 'mousemove', this.onMouseMove, this);
  295. }
  296. this.mon(t, {
  297. mouseover: this.onTargetOver,
  298. mouseout: this.onTargetOut,
  299. mousemove: this.onMouseMove,
  300. scope: this
  301. });
  302. this.target = t;
  303. }
  304. if(this.anchor){
  305. this.anchorTarget = this.target;
  306. }
  307. },
  308. // private
  309. onMouseMove : function(e){
  310. var t = this.delegate ? e.getTarget(this.delegate) : this.triggerElement = true;
  311. if (t) {
  312. this.targetXY = e.getXY();
  313. if (t === this.triggerElement) {
  314. if(!this.hidden && this.trackMouse){
  315. this.setPagePosition(this.getTargetXY());
  316. }
  317. } else {
  318. this.hide();
  319. this.lastActive = new Date(0);
  320. this.onTargetOver(e);
  321. }
  322. } else if (!this.closable && this.isVisible()) {
  323. this.hide();
  324. }
  325. },
  326. // private
  327. getTargetXY : function(){
  328. if(this.delegate){
  329. this.anchorTarget = this.triggerElement;
  330. }
  331. if(this.anchor){
  332. this.targetCounter++;
  333. var offsets = this.getOffsets(),
  334. xy = (this.anchorToTarget && !this.trackMouse) ? this.el.getAlignToXY(this.anchorTarget, this.getAnchorAlign()) : this.targetXY,
  335. dw = Ext.lib.Dom.getViewWidth() - 5,
  336. dh = Ext.lib.Dom.getViewHeight() - 5,
  337. de = document.documentElement,
  338. bd = document.body,
  339. scrollX = (de.scrollLeft || bd.scrollLeft || 0) + 5,
  340. scrollY = (de.scrollTop || bd.scrollTop || 0) + 5,
  341. axy = [xy[0] + offsets[0], xy[1] + offsets[1]],
  342. sz = this.getSize();
  343. this.anchorEl.removeClass(this.anchorCls);
  344. if(this.targetCounter < 2){
  345. if(axy[0] < scrollX){
  346. if(this.anchorToTarget){
  347. this.defaultAlign = 'l-r';
  348. if(this.mouseOffset){this.mouseOffset[0] *= -1;}
  349. }
  350. this.anchor = 'left';
  351. return this.getTargetXY();
  352. }
  353. if(axy[0]+sz.width > dw){
  354. if(this.anchorToTarget){
  355. this.defaultAlign = 'r-l';
  356. if(this.mouseOffset){this.mouseOffset[0] *= -1;}
  357. }
  358. this.anchor = 'right';
  359. return this.getTargetXY();
  360. }
  361. if(axy[1] < scrollY){
  362. if(this.anchorToTarget){
  363. this.defaultAlign = 't-b';
  364. if(this.mouseOffset){this.mouseOffset[1] *= -1;}
  365. }
  366. this.anchor = 'top';
  367. return this.getTargetXY();
  368. }
  369. if(axy[1]+sz.height > dh){
  370. if(this.anchorToTarget){
  371. this.defaultAlign = 'b-t';
  372. if(this.mouseOffset){this.mouseOffset[1] *= -1;}
  373. }
  374. this.anchor = 'bottom';
  375. return this.getTargetXY();
  376. }
  377. }
  378. this.anchorCls = 'x-tip-anchor-'+this.getAnchorPosition();
  379. this.anchorEl.addClass(this.anchorCls);
  380. this.targetCounter = 0;
  381. return axy;
  382. }else{
  383. var mouseOffset = this.getMouseOffset();
  384. return [this.targetXY[0]+mouseOffset[0], this.targetXY[1]+mouseOffset[1]];
  385. }
  386. },
  387. getMouseOffset : function(){
  388. var offset = this.anchor ? [0,0] : [15,18];
  389. if(this.mouseOffset){
  390. offset[0] += this.mouseOffset[0];
  391. offset[1] += this.mouseOffset[1];
  392. }
  393. return offset;
  394. },
  395. // private
  396. getAnchorPosition : function(){
  397. if(this.anchor){
  398. this.tipAnchor = this.anchor.charAt(0);
  399. }else{
  400. var m = this.defaultAlign.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  401. if(!m){
  402. throw 'AnchorTip.defaultAlign is invalid';
  403. }
  404. this.tipAnchor = m[1].charAt(0);
  405. }
  406. switch(this.tipAnchor){
  407. case 't': return 'top';
  408. case 'b': return 'bottom';
  409. case 'r': return 'right';
  410. }
  411. return 'left';
  412. },
  413. // private
  414. getAnchorAlign : function(){
  415. switch(this.anchor){
  416. case 'top' : return 'tl-bl';
  417. case 'left' : return 'tl-tr';
  418. case 'right': return 'tr-tl';
  419. default : return 'bl-tl';
  420. }
  421. },
  422. // private
  423. getOffsets : function(){
  424. var offsets,
  425. ap = this.getAnchorPosition().charAt(0);
  426. if(this.anchorToTarget && !this.trackMouse){
  427. switch(ap){
  428. case 't':
  429. offsets = [0, 9];
  430. break;
  431. case 'b':
  432. offsets = [0, -13];
  433. break;
  434. case 'r':
  435. offsets = [-13, 0];
  436. break;
  437. default:
  438. offsets = [9, 0];
  439. break;
  440. }
  441. }else{
  442. switch(ap){
  443. case 't':
  444. offsets = [-15-this.anchorOffset, 30];
  445. break;
  446. case 'b':
  447. offsets = [-19-this.anchorOffset, -13-this.el.dom.offsetHeight];
  448. break;
  449. case 'r':
  450. offsets = [-15-this.el.dom.offsetWidth, -13-this.anchorOffset];
  451. break;
  452. default:
  453. offsets = [25, -13-this.anchorOffset];
  454. break;
  455. }
  456. }
  457. var mouseOffset = this.getMouseOffset();
  458. offsets[0] += mouseOffset[0];
  459. offsets[1] += mouseOffset[1];
  460. return offsets;
  461. },
  462. // private
  463. onTargetOver : function(e){
  464. if(this.disabled || e.within(this.target.dom, true)){
  465. return;
  466. }
  467. var t = e.getTarget(this.delegate);
  468. if (t) {
  469. this.triggerElement = t;
  470. this.clearTimer('hide');
  471. this.targetXY = e.getXY();
  472. this.delayShow();
  473. }
  474. },
  475. // private
  476. delayShow : function(){
  477. if(this.hidden && !this.showTimer){
  478. if(this.lastActive.getElapsed() < this.quickShowInterval){
  479. this.show();
  480. }else{
  481. this.showTimer = this.show.defer(this.showDelay, this);
  482. }
  483. }else if(!this.hidden && this.autoHide !== false){
  484. this.show();
  485. }
  486. },
  487. // private
  488. onTargetOut : function(e){
  489. if(this.disabled || e.within(this.target.dom, true)){
  490. return;
  491. }
  492. this.clearTimer('show');
  493. if(this.autoHide !== false){
  494. this.delayHide();
  495. }
  496. },
  497. // private
  498. delayHide : function(){
  499. if(!this.hidden && !this.hideTimer){
  500. this.hideTimer = this.hide.defer(this.hideDelay, this);
  501. }
  502. },
  503. /**
  504. * Hides this tooltip if visible.
  505. */
  506. hide: function(){
  507. this.clearTimer('dismiss');
  508. this.lastActive = new Date();
  509. if(this.anchorEl){
  510. this.anchorEl.hide();
  511. }
  512. Ext.ToolTip.superclass.hide.call(this);
  513. delete this.triggerElement;
  514. },
  515. /**
  516. * Shows this tooltip at the current event target XY position.
  517. */
  518. show : function(){
  519. if(this.anchor){
  520. // pre-show it off screen so that the el will have dimensions
  521. // for positioning calcs when getting xy next
  522. this.showAt([-1000,-1000]);
  523. this.origConstrainPosition = this.constrainPosition;
  524. this.constrainPosition = false;
  525. this.anchor = this.origAnchor;
  526. }
  527. this.showAt(this.getTargetXY());
  528. if(this.anchor){
  529. this.anchorEl.show();
  530. this.syncAnchor();
  531. this.constrainPosition = this.origConstrainPosition;
  532. }else{
  533. this.anchorEl.hide();
  534. }
  535. },
  536. // inherit docs
  537. showAt : function(xy){
  538. this.lastActive = new Date();
  539. this.clearTimers();
  540. Ext.ToolTip.superclass.showAt.call(this, xy);
  541. if(this.dismissDelay && this.autoHide !== false){
  542. this.dismissTimer = this.hide.defer(this.dismissDelay, this);
  543. }
  544. if(this.anchor && !this.anchorEl.isVisible()){
  545. this.syncAnchor();
  546. this.anchorEl.show();
  547. }else{
  548. this.anchorEl.hide();
  549. }
  550. },
  551. // private
  552. syncAnchor : function(){
  553. var anchorPos, targetPos, offset;
  554. switch(this.tipAnchor.charAt(0)){
  555. case 't':
  556. anchorPos = 'b';
  557. targetPos = 'tl';
  558. offset = [20+this.anchorOffset, 2];
  559. break;
  560. case 'r':
  561. anchorPos = 'l';
  562. targetPos = 'tr';
  563. offset = [-2, 11+this.anchorOffset];
  564. break;
  565. case 'b':
  566. anchorPos = 't';
  567. targetPos = 'bl';
  568. offset = [20+this.anchorOffset, -2];
  569. break;
  570. default:
  571. anchorPos = 'r';
  572. targetPos = 'tl';
  573. offset = [2, 11+this.anchorOffset];
  574. break;
  575. }
  576. this.anchorEl.alignTo(this.el, anchorPos+'-'+targetPos, offset);
  577. },
  578. // private
  579. setPagePosition : function(x, y){
  580. Ext.ToolTip.superclass.setPagePosition.call(this, x, y);
  581. if(this.anchor){
  582. this.syncAnchor();
  583. }
  584. },
  585. // private
  586. clearTimer : function(name){
  587. name = name + 'Timer';
  588. clearTimeout(this[name]);
  589. delete this[name];
  590. },
  591. // private
  592. clearTimers : function(){
  593. this.clearTimer('show');
  594. this.clearTimer('dismiss');
  595. this.clearTimer('hide');
  596. },
  597. // private
  598. onShow : function(){
  599. Ext.ToolTip.superclass.onShow.call(this);
  600. Ext.getDoc().on('mousedown', this.onDocMouseDown, this);
  601. },
  602. // private
  603. onHide : function(){
  604. Ext.ToolTip.superclass.onHide.call(this);
  605. Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
  606. },
  607. // private
  608. onDocMouseDown : function(e){
  609. if(this.autoHide !== true && !this.closable && !e.within(this.el.dom)){
  610. this.disable();
  611. this.doEnable.defer(100, this);
  612. }
  613. },
  614. // private
  615. doEnable : function(){
  616. if(!this.isDestroyed){
  617. this.enable();
  618. }
  619. },
  620. // private
  621. onDisable : function(){
  622. this.clearTimers();
  623. this.hide();
  624. },
  625. // private
  626. adjustPosition : function(x, y){
  627. if(this.constrainPosition){
  628. var ay = this.targetXY[1], h = this.getSize().height;
  629. if(y <= ay && (y+h) >= ay){
  630. y = ay-h-5;
  631. }
  632. }
  633. return {x : x, y: y};
  634. },
  635. beforeDestroy : function(){
  636. this.clearTimers();
  637. Ext.destroy(this.anchorEl);
  638. delete this.anchorEl;
  639. delete this.target;
  640. delete this.anchorTarget;
  641. delete this.triggerElement;
  642. Ext.ToolTip.superclass.beforeDestroy.call(this);
  643. },
  644. // private
  645. onDestroy : function(){
  646. Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
  647. Ext.ToolTip.superclass.onDestroy.call(this);
  648. }
  649. });
  650. Ext.reg('tooltip', Ext.ToolTip);/**
  651. * @class Ext.QuickTip
  652. * @extends Ext.ToolTip
  653. * @xtype quicktip
  654. * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global
  655. * {@link Ext.QuickTips} instance. See the QuickTips class header for additional usage details and examples.
  656. * @constructor
  657. * Create a new Tip
  658. * @param {Object} config The configuration options
  659. */
  660. Ext.QuickTip = Ext.extend(Ext.ToolTip, {
  661. /**
  662. * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to associate with this quicktip (defaults to the document).
  663. */
  664. /**
  665. * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false).
  666. */
  667. interceptTitles : false,
  668. // private
  669. tagConfig : {
  670. namespace : "ext",
  671. attribute : "qtip",
  672. width : "qwidth",
  673. target : "target",
  674. title : "qtitle",
  675. hide : "hide",
  676. cls : "qclass",
  677. align : "qalign",
  678. anchor : "anchor"
  679. },
  680. // private
  681. initComponent : function(){
  682. this.target = this.target || Ext.getDoc();
  683. this.targets = this.targets || {};
  684. Ext.QuickTip.superclass.initComponent.call(this);
  685. },
  686. /**
  687. * Configures a new quick tip instance and assigns it to a target element. The following config values are
  688. * supported (for example usage, see the {@link Ext.QuickTips} class header):
  689. * <div class="mdetail-params"><ul>
  690. * <li>autoHide</li>
  691. * <li>cls</li>
  692. * <li>dismissDelay (overrides the singleton value)</li>
  693. * <li>target (required)</li>
  694. * <li>text (required)</li>
  695. * <li>title</li>
  696. * <li>width</li></ul></div>
  697. * @param {Object} config The config object
  698. */
  699. register : function(config){
  700. var cs = Ext.isArray(config) ? config : arguments;
  701. for(var i = 0, len = cs.length; i < len; i++){
  702. var c = cs[i];
  703. var target = c.target;
  704. if(target){
  705. if(Ext.isArray(target)){
  706. for(var j = 0, jlen = target.length; j < jlen; j++){
  707. this.targets[Ext.id(target[j])] = c;
  708. }
  709. } else{
  710. this.targets[Ext.id(target)] = c;
  711. }
  712. }
  713. }
  714. },
  715. /**
  716. * Removes this quick tip from its element and destroys it.
  717. * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
  718. */
  719. unregister : function(el){
  720. delete this.targets[Ext.id(el)];
  721. },
  722. /**
  723. * Hides a visible tip or cancels an impending show for a particular element.
  724. * @param {String/HTMLElement/Element} el The element that is the target of the tip.
  725. */
  726. cancelShow: function(el){
  727. var at = this.activeTarget;
  728. el = Ext.get(el).dom;
  729. if(this.isVisible()){
  730. if(at && at.el == el){
  731. this.hide();
  732. }
  733. }else if(at && at.el == el){
  734. this.clearTimer('show');
  735. }
  736. },
  737. getTipCfg: function(e) {
  738. var t = e.getTarget(),
  739. ttp,
  740. cfg;
  741. if(this.interceptTitles && t.title && Ext.isString(t.title)){
  742. ttp = t.title;
  743. t.qtip = ttp;
  744. t.removeAttribute("title");
  745. e.preventDefault();
  746. }else{
  747. cfg = this.tagConfig;
  748. ttp = t.qtip || Ext.fly(t).getAttribute(cfg.attribute, cfg.namespace);
  749. }
  750. return ttp;
  751. },
  752. // private
  753. onTargetOver : function(e){
  754. if(this.disabled){
  755. return;
  756. }
  757. this.targetXY = e.getXY();
  758. var t = e.getTarget();
  759. if(!t || t.nodeType !== 1 || t == document || t == document.body){
  760. return;
  761. }
  762. if(this.activeTarget && ((t == this.activeTarget.el) || Ext.fly(this.activeTarget.el).contains(t))){
  763. this.clearTimer('hide');
  764. this.show();
  765. return;
  766. }
  767. if(t && this.targets[t.id]){
  768. this.activeTarget = this.targets[t.id];
  769. this.activeTarget.el = t;
  770. this.anchor = this.activeTarget.anchor;
  771. if(this.anchor){
  772. this.anchorTarget = t;
  773. }
  774. this.delayShow();
  775. return;
  776. }
  777. var ttp, et = Ext.fly(t), cfg = this.tagConfig, ns = cfg.namespace;
  778. if(ttp = this.getTipCfg(e)){
  779. var autoHide = et.getAttribute(cfg.hide, ns);
  780. this.activeTarget = {
  781. el: t,
  782. text: ttp,
  783. width: et.getAttribute(cfg.width, ns),
  784. autoHide: autoHide != "user" && autoHide !== 'false',
  785. title: et.getAttribute(cfg.title, ns),
  786. cls: et.getAttribute(cfg.cls, ns),
  787. align: et.getAttribute(cfg.align, ns)
  788. };
  789. this.anchor = et.getAttribute(cfg.anchor, ns);
  790. if(this.anchor){
  791. this.anchorTarget = t;
  792. }
  793. this.delayShow();
  794. }
  795. },
  796. // private
  797. onTargetOut : function(e){
  798. // If moving within the current target, and it does not have a new tip, ignore the mouseout
  799. if (this.activeTarget && e.within(this.activeTarget.el) && !this.getTipCfg(e)) {
  800. return;
  801. }
  802. this.clearTimer('show');
  803. if(this.autoHide !== false){
  804. this.delayHide();
  805. }
  806. },
  807. // inherit docs
  808. showAt : function(xy){
  809. var t = this.activeTarget;
  810. if(t){
  811. if(!this.rendered){
  812. this.render(Ext.getBody());
  813. this.activeTarget = t;
  814. }
  815. if(t.width){
  816. this.setWidth(t.width);
  817. this.body.setWidth(this.adjustBodyWidth(t.width - this.getFrameWidth()));
  818. this.measureWidth = false;
  819. } else{
  820. this.measureWidth = true;
  821. }
  822. this.setTitle(t.title || '');
  823. this.body.update(t.text);
  824. this.autoHide = t.autoHide;
  825. this.dismissDelay = t.dismissDelay || this.dismissDelay;
  826. if(this.lastCls){
  827. this.el.removeClass(this.lastCls);
  828. delete this.lastCls;
  829. }
  830. if(t.cls){
  831. this.el.addClass(t.cls);
  832. this.lastCls = t.cls;
  833. }
  834. if(this.anchor){
  835. this.constrainPosition = false;
  836. }else if(t.align){ // TODO: this doesn't seem to work consistently
  837. xy = this.el.getAlignToXY(t.el, t.align);
  838. this.constrainPosition = false;
  839. }else{
  840. this.constrainPosition = true;
  841. }
  842. }
  843. Ext.QuickTip.superclass.showAt.call(this, xy);
  844. },
  845. // inherit docs
  846. hide: function(){
  847. delete this.activeTarget;
  848. Ext.QuickTip.superclass.hide.call(this);
  849. }
  850. });
  851. Ext.reg('quicktip', Ext.QuickTip);/**
  852. * @class Ext.QuickTips
  853. * <p>Provides attractive and customizable tooltips for any element. The QuickTips
  854. * singleton is used to configure and manage tooltips globally for multiple elements
  855. * in a generic manner. To create individual tooltips with maximum customizability,
  856. * you should consider either {@link Ext.Tip} or {@link Ext.ToolTip}.</p>
  857. * <p>Quicktips can be configured via tag attributes directly in markup, or by
  858. * registering quick tips programmatically via the {@link #register} method.</p>
  859. * <p>The singleton's instance of {@link Ext.QuickTip} is available via
  860. * {@link #getQuickTip}, and supports all the methods, and all the all the
  861. * configuration properties of Ext.QuickTip. These settings will apply to all
  862. * tooltips shown by the singleton.</p>
  863. * <p>Below is the summary of the configuration properties which can be used.
  864. * For detailed descriptions see the config options for the {@link Ext.QuickTip QuickTip} class</p>
  865. * <p><b>QuickTips singleton configs (all are optional)</b></p>
  866. * <div class="mdetail-params"><ul><li>dismissDelay</li>
  867. * <li>hideDelay</li>
  868. * <li>maxWidth</li>
  869. * <li>minWidth</li>
  870. * <li>showDelay</li>
  871. * <li>trackMouse</li></ul></div>
  872. * <p><b>Target element configs (optional unless otherwise noted)</b></p>
  873. * <div class="mdetail-params"><ul><li>autoHide</li>
  874. * <li>cls</li>
  875. * <li>dismissDelay (overrides singleton value)</li>
  876. * <li>target (required)</li>
  877. * <li>text (required)</li>
  878. * <li>title</li>
  879. * <li>width</li></ul></div>
  880. * <p>Here is an example showing how some of these config options could be used:</p>
  881. * <pre><code>
  882. // Init the singleton. Any tag-based quick tips will start working.
  883. Ext.QuickTips.init();
  884. // Apply a set of config properties to the singleton
  885. Ext.apply(Ext.QuickTips.getQuickTip(), {
  886. maxWidth: 200,
  887. minWidth: 100,
  888. showDelay: 50, // Show 50ms after entering target
  889. trackMouse: true
  890. });
  891. // Manually register a quick tip for a specific element
  892. Ext.QuickTips.register({
  893. target: 'my-div',
  894. title: 'My Tooltip',
  895. text: 'This tooltip was added in code',
  896. width: 100,
  897. dismissDelay: 10000 // Hide after 10 seconds hover
  898. });
  899. </code></pre>
  900. * <p>To register a quick tip in markup, you simply add one or more of the valid QuickTip attributes prefixed with
  901. * the <b>ext:</b> namespace. The HTML element itself is automatically set as the quick tip target. Here is the summary
  902. * of supported attributes (optional unless otherwise noted):</p>
  903. * <ul><li><b>hide</b>: Specifying "user" is equivalent to setting autoHide = false. Any other value will be the
  904. * same as autoHide = true.</li>
  905. * <li><b>qclass</b>: A CSS class to be applied to the quick tip (equivalent to the 'cls' target element config).</li>
  906. * <li><b>qtip (required)</b>: The quick tip text (equivalent to the 'text' target element config).</li>
  907. * <li><b>qtitle</b>: The quick tip title (equivalent to the 'title' target element config).</li>
  908. * <li><b>qwidth</b>: The quick tip width (equivalent to the 'width' target element config).</li></ul>
  909. * <p>Here is an example of configuring an HTML element to display a tooltip from markup:</p>
  910. * <pre><code>
  911. // Add a quick tip to an HTML button
  912. &lt;input type="button" value="OK" ext:qtitle="OK Button" ext:qwidth="100"
  913. ext:qtip="This is a quick tip from markup!">&lt;/input>
  914. </code></pre>
  915. * @singleton
  916. */
  917. Ext.QuickTips = function(){
  918. var tip,
  919. disabled = false;
  920. return {
  921. /**
  922. * Initialize the global QuickTips instance and prepare any quick tips.
  923. * @param {Boolean} autoRender True to render the QuickTips container immediately to preload images. (Defaults to true)
  924. */
  925. init : function(autoRender){
  926. if(!tip){
  927. if(!Ext.isReady){
  928. Ext.onReady(function(){
  929. Ext.QuickTips.init(autoRender);
  930. });
  931. return;
  932. }
  933. tip = new Ext.QuickTip({
  934. elements:'header,body',
  935. disabled: disabled
  936. });
  937. if(autoRender !== false){
  938. tip.render(Ext.getBody());
  939. }
  940. }
  941. },
  942. // Protected method called by the dd classes
  943. ddDisable : function(){
  944. // don't disable it if we don't need to
  945. if(tip && !disabled){
  946. tip.disable();
  947. }
  948. },
  949. // Protected method called by the dd classes
  950. ddEnable : function(){
  951. // only enable it if it hasn't been disabled
  952. if(tip && !disabled){
  953. tip.enable();
  954. }
  955. },
  956. /**
  957. * Enable quick tips globally.
  958. */
  959. enable : function(){
  960. if(tip){
  961. tip.enable();
  962. }
  963. disabled = false;
  964. },
  965. /**
  966. * Disable quick tips globally.
  967. */
  968. disable : function(){
  969. if(tip){
  970. tip.disable();
  971. }
  972. disabled = true;
  973. },
  974. /**
  975. * Returns true if quick tips are enabled, else false.
  976. * @return {Boolean}
  977. */
  978. isEnabled : function(){
  979. return tip !== undefined && !tip.disabled;
  980. },
  981. /**
  982. * Gets the single {@link Ext.QuickTip QuickTip} instance used to show tips from all registered elements.
  983. * @return {Ext.QuickTip}
  984. */
  985. getQuickTip : function(){
  986. return tip;
  987. },
  988. /**
  989. * Configures a new quick tip instance and assigns it to a target element. See
  990. * {@link Ext.QuickTip#register} for details.
  991. * @param {Object} config The config object
  992. */
  993. register : function(){
  994. tip.register.apply(tip, arguments);
  995. },
  996. /**
  997. * Removes any registered quick tip from the target element and destroys it.
  998. * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
  999. */
  1000. unregister : function(){
  1001. tip.unregister.apply(tip, arguments);
  1002. },
  1003. /**
  1004. * Alias of {@link #register}.
  1005. * @param {Object} config The config object
  1006. */
  1007. tips : function(){
  1008. tip.register.apply(tip, arguments);
  1009. }
  1010. };
  1011. }();/**
  1012. * @class Ext.slider.Tip
  1013. * @extends Ext.Tip
  1014. * Simple plugin for using an Ext.Tip with a slider to show the slider value. Example usage:
  1015. <pre>
  1016. new Ext.Slider({
  1017. width: 214,
  1018. minValue: 0,
  1019. maxValue: 100,
  1020. plugins: new Ext.slider.Tip()
  1021. });
  1022. </pre>
  1023. * Optionally provide your own tip text by overriding getText:
  1024. <pre>
  1025. new Ext.Slider({
  1026. width: 214,
  1027. minValue: 0,
  1028. maxValue: 100,
  1029. plugins: new Ext.slider.Tip({
  1030. getText: function(thumb){
  1031. return String.format('<b>{0}% complete</b>', thumb.value);
  1032. }
  1033. })
  1034. });
  1035. </pre>
  1036. */
  1037. Ext.slider.Tip = Ext.extend(Ext.Tip, {
  1038. minWidth: 10,
  1039. offsets : [0, -10],
  1040. init: function(slider) {
  1041. slider.on({
  1042. scope : this,
  1043. dragstart: this.onSlide,
  1044. drag : this.onSlide,
  1045. dragend : this.hide,
  1046. destroy : this.destroy
  1047. });
  1048. },
  1049. /**
  1050. * @private
  1051. * Called whenever a dragstart or drag event is received on the associated Thumb.
  1052. * Aligns the Tip with the Thumb's new position.
  1053. * @param {Ext.slider.MultiSlider} slider The slider
  1054. * @param {Ext.EventObject} e The Event object
  1055. * @param {Ext.slider.Thumb} thumb The thumb that the Tip is attached to
  1056. */
  1057. onSlide : function(slider, e, thumb) {
  1058. this.show();
  1059. this.body.update(this.getText(thumb));
  1060. this.doAutoWidth();
  1061. this.el.alignTo(thumb.el, 'b-t?', this.offsets);
  1062. },
  1063. /**
  1064. * Used to create the text that appears in the Tip's body. By default this just returns
  1065. * the value of the Slider Thumb that the Tip is attached to. Override to customize.
  1066. * @param {Ext.slider.Thumb} thumb The Thumb that the Tip is attached to
  1067. * @return {String} The text to display in the tip
  1068. */
  1069. getText : function(thumb) {
  1070. return String(thumb.value);
  1071. }
  1072. });
  1073. //backwards compatibility - SliderTip used to be a ux before 3.2
  1074. Ext.ux.SliderTip = Ext.slider.Tip;