ToolTip.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-tip-ToolTip'>/**
  19. </span> * ToolTip is a {@link Ext.tip.Tip} implementation that handles the common case of displaying a
  20. * tooltip when hovering over a certain element or elements on the page. It allows fine-grained
  21. * control over the tooltip's alignment relative to the target element or mouse, and the timing
  22. * of when it is automatically shown and hidden.
  23. *
  24. * This implementation does **not** have a built-in method of automatically populating the tooltip's
  25. * text based on the target element; you must either configure a fixed {@link #html} value for each
  26. * ToolTip instance, or implement custom logic (e.g. in a {@link #beforeshow} event listener) to
  27. * generate the appropriate tooltip content on the fly. See {@link Ext.tip.QuickTip} for a more
  28. * convenient way of automatically populating and configuring a tooltip based on specific DOM
  29. * attributes of each target element.
  30. *
  31. * # Basic Example
  32. *
  33. * var tip = Ext.create('Ext.tip.ToolTip', {
  34. * target: 'clearButton',
  35. * html: 'Press this button to clear the form'
  36. * });
  37. *
  38. * {@img Ext.tip.ToolTip/Ext.tip.ToolTip1.png Basic Ext.tip.ToolTip}
  39. *
  40. * # Delegation
  41. *
  42. * In addition to attaching a ToolTip to a single element, you can also use delegation to attach
  43. * one ToolTip to many elements under a common parent. This is more efficient than creating many
  44. * ToolTip instances. To do this, point the {@link #target} config to a common ancestor of all the
  45. * elements, and then set the {@link #delegate} config to a CSS selector that will select all the
  46. * appropriate sub-elements.
  47. *
  48. * When using delegation, it is likely that you will want to programmatically change the content
  49. * of the ToolTip based on each delegate element; you can do this by implementing a custom
  50. * listener for the {@link #beforeshow} event. Example:
  51. *
  52. * var store = Ext.create('Ext.data.ArrayStore', {
  53. * fields: ['company', 'price', 'change'],
  54. * data: [
  55. * ['3m Co', 71.72, 0.02],
  56. * ['Alcoa Inc', 29.01, 0.42],
  57. * ['Altria Group Inc', 83.81, 0.28],
  58. * ['American Express Company', 52.55, 0.01],
  59. * ['American International Group, Inc.', 64.13, 0.31],
  60. * ['AT&amp;T Inc.', 31.61, -0.48]
  61. * ]
  62. * });
  63. *
  64. * var grid = Ext.create('Ext.grid.Panel', {
  65. * title: 'Array Grid',
  66. * store: store,
  67. * columns: [
  68. * {text: 'Company', flex: 1, dataIndex: 'company'},
  69. * {text: 'Price', width: 75, dataIndex: 'price'},
  70. * {text: 'Change', width: 75, dataIndex: 'change'}
  71. * ],
  72. * height: 200,
  73. * width: 400,
  74. * renderTo: Ext.getBody()
  75. * });
  76. *
  77. * grid.getView().on('render', function(view) {
  78. * view.tip = Ext.create('Ext.tip.ToolTip', {
  79. * // The overall target element.
  80. * target: view.el,
  81. * // Each grid row causes its own separate show and hide.
  82. * delegate: view.itemSelector,
  83. * // Moving within the row should not hide the tip.
  84. * trackMouse: true,
  85. * // Render immediately so that tip.body can be referenced prior to the first show.
  86. * renderTo: Ext.getBody(),
  87. * listeners: {
  88. * // Change content dynamically depending on which element triggered the show.
  89. * beforeshow: function updateTipBody(tip) {
  90. * tip.update('Over company &quot;' + view.getRecord(tip.triggerElement).get('company') + '&quot;');
  91. * }
  92. * }
  93. * });
  94. * });
  95. *
  96. * {@img Ext.tip.ToolTip/Ext.tip.ToolTip2.png Ext.tip.ToolTip with delegation}
  97. *
  98. * # Alignment
  99. *
  100. * The following configuration properties allow control over how the ToolTip is aligned relative to
  101. * the target element and/or mouse pointer:
  102. *
  103. * - {@link #anchor}
  104. * - {@link #anchorToTarget}
  105. * - {@link #anchorOffset}
  106. * - {@link #trackMouse}
  107. * - {@link #mouseOffset}
  108. *
  109. * # Showing/Hiding
  110. *
  111. * The following configuration properties allow control over how and when the ToolTip is automatically
  112. * shown and hidden:
  113. *
  114. * - {@link #autoHide}
  115. * - {@link #showDelay}
  116. * - {@link #hideDelay}
  117. * - {@link #dismissDelay}
  118. *
  119. * @docauthor Jason Johnston &lt;jason@sencha.com&gt;
  120. */
  121. Ext.define('Ext.tip.ToolTip', {
  122. extend: 'Ext.tip.Tip',
  123. alias: 'widget.tooltip',
  124. alternateClassName: 'Ext.ToolTip',
  125. <span id='Ext-tip-ToolTip-property-triggerElement'> /**
  126. </span> * @property {HTMLElement} triggerElement
  127. * When a ToolTip is configured with the `{@link #delegate}`
  128. * option to cause selected child elements of the `{@link #target}`
  129. * Element to each trigger a separate show event, this property is set to
  130. * the DOM element which triggered the show.
  131. */
  132. <span id='Ext-tip-ToolTip-cfg-target'> /**
  133. </span> * @cfg {HTMLElement/Ext.Element/String} target
  134. * The target element or string id to monitor for mouseover events to trigger
  135. * showing this ToolTip.
  136. */
  137. <span id='Ext-tip-ToolTip-cfg-autoHide'> /**
  138. </span> * @cfg {Boolean} [autoHide=true]
  139. * True to automatically hide the tooltip after the
  140. * mouse exits the target element or after the `{@link #dismissDelay}`
  141. * has expired if set. If `{@link #closable} = true`
  142. * a close tool button will be rendered into the tooltip header.
  143. */
  144. autoHide: true,
  145. <span id='Ext-tip-ToolTip-cfg-showDelay'> /**
  146. </span> * @cfg {Number} showDelay
  147. * Delay in milliseconds before the tooltip displays after the mouse enters the target element.
  148. */
  149. showDelay: 500,
  150. <span id='Ext-tip-ToolTip-cfg-hideDelay'> /**
  151. </span> * @cfg {Number} hideDelay
  152. * Delay in milliseconds after the mouse exits the target element but before the tooltip actually hides.
  153. * Set to 0 for the tooltip to hide immediately.
  154. */
  155. hideDelay: 200,
  156. <span id='Ext-tip-ToolTip-cfg-dismissDelay'> /**
  157. </span> * @cfg {Number} dismissDelay
  158. * Delay in milliseconds before the tooltip automatically hides. To disable automatic hiding, set
  159. * dismissDelay = 0.
  160. */
  161. dismissDelay: 5000,
  162. <span id='Ext-tip-ToolTip-cfg-mouseOffset'> /**
  163. </span> * @cfg {Number[]} [mouseOffset=[15,18]]
  164. * An XY offset from the mouse position where the tooltip should be shown.
  165. */
  166. <span id='Ext-tip-ToolTip-cfg-trackMouse'> /**
  167. </span> * @cfg {Boolean} trackMouse
  168. * True to have the tooltip follow the mouse as it moves over the target element.
  169. */
  170. trackMouse: false,
  171. <span id='Ext-tip-ToolTip-cfg-anchor'> /**
  172. </span> * @cfg {String} anchor
  173. * If specified, indicates that the tip should be anchored to a
  174. * particular side of the target element or mouse pointer (&quot;top&quot;, &quot;right&quot;, &quot;bottom&quot;,
  175. * or &quot;left&quot;), with an arrow pointing back at the target or mouse pointer. If
  176. * {@link #constrainPosition} is enabled, this will be used as a preferred value
  177. * only and may be flipped as needed.
  178. */
  179. <span id='Ext-tip-ToolTip-cfg-anchorToTarget'> /**
  180. </span> * @cfg {Boolean} anchorToTarget
  181. * True to anchor the tooltip to the target element, false to anchor it relative to the mouse coordinates.
  182. * When `anchorToTarget` is true, use `{@link #defaultAlign}` to control tooltip alignment to the
  183. * target element. When `anchorToTarget` is false, use `{@link #anchor}` instead to control alignment.
  184. */
  185. anchorToTarget: true,
  186. <span id='Ext-tip-ToolTip-cfg-anchorOffset'> /**
  187. </span> * @cfg {Number} anchorOffset
  188. * A numeric pixel value used to offset the default position of the anchor arrow. When the anchor
  189. * position is on the top or bottom of the tooltip, `anchorOffset` will be used as a horizontal offset.
  190. * Likewise, when the anchor position is on the left or right side, `anchorOffset` will be used as
  191. * a vertical offset.
  192. */
  193. anchorOffset: 0,
  194. <span id='Ext-tip-ToolTip-cfg-delegate'> /**
  195. </span> * @cfg {String} delegate
  196. *
  197. * A {@link Ext.DomQuery DomQuery} selector which allows selection of individual elements within the
  198. * `{@link #target}` element to trigger showing and hiding the ToolTip as the mouse moves within the
  199. * target.
  200. *
  201. * When specified, the child element of the target which caused a show event is placed into the
  202. * `{@link #triggerElement}` property before the ToolTip is shown.
  203. *
  204. * This may be useful when a Component has regular, repeating elements in it, each of which need a
  205. * ToolTip which contains information specific to that element.
  206. *
  207. * See the delegate example in class documentation of {@link Ext.tip.ToolTip}.
  208. */
  209. // private
  210. targetCounter: 0,
  211. quickShowInterval: 250,
  212. // private
  213. initComponent: function() {
  214. var me = this;
  215. me.callParent(arguments);
  216. me.lastActive = new Date();
  217. me.setTarget(me.target);
  218. me.origAnchor = me.anchor;
  219. },
  220. // private
  221. onRender: function(ct, position) {
  222. var me = this;
  223. me.callParent(arguments);
  224. me.anchorCls = Ext.baseCSSPrefix + 'tip-anchor-' + me.getAnchorPosition();
  225. me.anchorEl = me.el.createChild({
  226. cls: Ext.baseCSSPrefix + 'tip-anchor ' + me.anchorCls
  227. });
  228. },
  229. <span id='Ext-tip-ToolTip-method-setTarget'> /**
  230. </span> * Binds this ToolTip to the specified element. The tooltip will be displayed when the mouse moves over the element.
  231. * @param {String/HTMLElement/Ext.Element} t The Element, HtmlElement, or ID of an element to bind to
  232. */
  233. setTarget: function(target) {
  234. var me = this,
  235. t = Ext.get(target),
  236. tg;
  237. if (me.target) {
  238. tg = Ext.get(me.target);
  239. me.mun(tg, 'mouseover', me.onTargetOver, me);
  240. me.mun(tg, 'mouseout', me.onTargetOut, me);
  241. me.mun(tg, 'mousemove', me.onMouseMove, me);
  242. }
  243. me.target = t;
  244. if (t) {
  245. me.mon(t, {
  246. // TODO - investigate why IE6/7 seem to fire recursive resize in e.getXY
  247. // breaking QuickTip#onTargetOver (EXTJSIV-1608)
  248. freezeEvent: true,
  249. mouseover: me.onTargetOver,
  250. mouseout: me.onTargetOut,
  251. mousemove: me.onMouseMove,
  252. scope: me
  253. });
  254. }
  255. if (me.anchor) {
  256. me.anchorTarget = me.target;
  257. }
  258. },
  259. // private
  260. onMouseMove: function(e) {
  261. var me = this,
  262. t = me.delegate ? e.getTarget(me.delegate) : me.triggerElement = true,
  263. xy;
  264. if (t) {
  265. me.targetXY = e.getXY();
  266. if (t === me.triggerElement) {
  267. if (!me.hidden &amp;&amp; me.trackMouse) {
  268. xy = me.getTargetXY();
  269. if (me.constrainPosition) {
  270. xy = me.el.adjustForConstraints(xy, me.el.getScopeParent());
  271. }
  272. me.setPagePosition(xy);
  273. }
  274. } else {
  275. me.hide();
  276. me.lastActive = new Date(0);
  277. me.onTargetOver(e);
  278. }
  279. } else if ((!me.closable &amp;&amp; me.isVisible()) &amp;&amp; me.autoHide !== false) {
  280. me.hide();
  281. }
  282. },
  283. // private
  284. getTargetXY: function() {
  285. var me = this,
  286. mouseOffset,
  287. offsets, xy, dw, dh, de, bd, scrollX, scrollY, axy, sz, constrainPosition;
  288. if (me.delegate) {
  289. me.anchorTarget = me.triggerElement;
  290. }
  291. if (me.anchor) {
  292. me.targetCounter++;
  293. offsets = me.getOffsets();
  294. xy = (me.anchorToTarget &amp;&amp; !me.trackMouse) ? me.el.getAlignToXY(me.anchorTarget, me.getAnchorAlign()) : me.targetXY;
  295. dw = Ext.Element.getViewWidth() - 5;
  296. dh = Ext.Element.getViewHeight() - 5;
  297. de = document.documentElement;
  298. bd = document.body;
  299. scrollX = (de.scrollLeft || bd.scrollLeft || 0) + 5;
  300. scrollY = (de.scrollTop || bd.scrollTop || 0) + 5;
  301. axy = [xy[0] + offsets[0], xy[1] + offsets[1]];
  302. sz = me.getSize();
  303. constrainPosition = me.constrainPosition;
  304. me.anchorEl.removeCls(me.anchorCls);
  305. if (me.targetCounter &lt; 2 &amp;&amp; constrainPosition) {
  306. if (axy[0] &lt; scrollX) {
  307. if (me.anchorToTarget) {
  308. me.defaultAlign = 'l-r';
  309. if (me.mouseOffset) {
  310. me.mouseOffset[0] *= -1;
  311. }
  312. }
  313. me.anchor = 'left';
  314. return me.getTargetXY();
  315. }
  316. if (axy[0] + sz.width &gt; dw) {
  317. if (me.anchorToTarget) {
  318. me.defaultAlign = 'r-l';
  319. if (me.mouseOffset) {
  320. me.mouseOffset[0] *= -1;
  321. }
  322. }
  323. me.anchor = 'right';
  324. return me.getTargetXY();
  325. }
  326. if (axy[1] &lt; scrollY) {
  327. if (me.anchorToTarget) {
  328. me.defaultAlign = 't-b';
  329. if (me.mouseOffset) {
  330. me.mouseOffset[1] *= -1;
  331. }
  332. }
  333. me.anchor = 'top';
  334. return me.getTargetXY();
  335. }
  336. if (axy[1] + sz.height &gt; dh) {
  337. if (me.anchorToTarget) {
  338. me.defaultAlign = 'b-t';
  339. if (me.mouseOffset) {
  340. me.mouseOffset[1] *= -1;
  341. }
  342. }
  343. me.anchor = 'bottom';
  344. return me.getTargetXY();
  345. }
  346. }
  347. me.anchorCls = Ext.baseCSSPrefix + 'tip-anchor-' + me.getAnchorPosition();
  348. me.anchorEl.addCls(me.anchorCls);
  349. me.targetCounter = 0;
  350. return axy;
  351. } else {
  352. mouseOffset = me.getMouseOffset();
  353. return (me.targetXY) ? [me.targetXY[0] + mouseOffset[0], me.targetXY[1] + mouseOffset[1]] : mouseOffset;
  354. }
  355. },
  356. getMouseOffset: function() {
  357. var me = this,
  358. offset = me.anchor ? [0, 0] : [15, 18];
  359. if (me.mouseOffset) {
  360. offset[0] += me.mouseOffset[0];
  361. offset[1] += me.mouseOffset[1];
  362. }
  363. return offset;
  364. },
  365. // private
  366. getAnchorPosition: function() {
  367. var me = this,
  368. m;
  369. if (me.anchor) {
  370. me.tipAnchor = me.anchor.charAt(0);
  371. } else {
  372. m = me.defaultAlign.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  373. //&lt;debug&gt;
  374. if (!m) {
  375. Ext.Error.raise('The AnchorTip.defaultAlign value &quot;' + me.defaultAlign + '&quot; is invalid.');
  376. }
  377. //&lt;/debug&gt;
  378. me.tipAnchor = m[1].charAt(0);
  379. }
  380. switch (me.tipAnchor) {
  381. case 't':
  382. return 'top';
  383. case 'b':
  384. return 'bottom';
  385. case 'r':
  386. return 'right';
  387. }
  388. return 'left';
  389. },
  390. // private
  391. getAnchorAlign: function() {
  392. switch (this.anchor) {
  393. case 'top':
  394. return 'tl-bl';
  395. case 'left':
  396. return 'tl-tr';
  397. case 'right':
  398. return 'tr-tl';
  399. default:
  400. return 'bl-tl';
  401. }
  402. },
  403. // private
  404. getOffsets: function() {
  405. var me = this,
  406. mouseOffset,
  407. offsets,
  408. ap = me.getAnchorPosition().charAt(0);
  409. if (me.anchorToTarget &amp;&amp; !me.trackMouse) {
  410. switch (ap) {
  411. case 't':
  412. offsets = [0, 9];
  413. break;
  414. case 'b':
  415. offsets = [0, -13];
  416. break;
  417. case 'r':
  418. offsets = [ - 13, 0];
  419. break;
  420. default:
  421. offsets = [9, 0];
  422. break;
  423. }
  424. } else {
  425. switch (ap) {
  426. case 't':
  427. offsets = [ - 15 - me.anchorOffset, 30];
  428. break;
  429. case 'b':
  430. offsets = [ - 19 - me.anchorOffset, -13 - me.el.dom.offsetHeight];
  431. break;
  432. case 'r':
  433. offsets = [ - 15 - me.el.dom.offsetWidth, -13 - me.anchorOffset];
  434. break;
  435. default:
  436. offsets = [25, -13 - me.anchorOffset];
  437. break;
  438. }
  439. }
  440. mouseOffset = me.getMouseOffset();
  441. offsets[0] += mouseOffset[0];
  442. offsets[1] += mouseOffset[1];
  443. return offsets;
  444. },
  445. // private
  446. onTargetOver: function(e) {
  447. var me = this,
  448. t;
  449. if (me.disabled || e.within(me.target.dom, true)) {
  450. return;
  451. }
  452. t = e.getTarget(me.delegate);
  453. if (t) {
  454. me.triggerElement = t;
  455. me.clearTimer('hide');
  456. me.targetXY = e.getXY();
  457. me.delayShow();
  458. }
  459. },
  460. // private
  461. delayShow: function() {
  462. var me = this;
  463. if (me.hidden &amp;&amp; !me.showTimer) {
  464. if (Ext.Date.getElapsed(me.lastActive) &lt; me.quickShowInterval) {
  465. me.show();
  466. } else {
  467. me.showTimer = Ext.defer(me.show, me.showDelay, me);
  468. }
  469. }
  470. else if (!me.hidden &amp;&amp; me.autoHide !== false) {
  471. me.show();
  472. }
  473. },
  474. onShowVeto: function(){
  475. this.callParent();
  476. this.clearTimer('show');
  477. },
  478. // private
  479. onTargetOut: function(e) {
  480. var me = this;
  481. // If disabled, moving within the current target, ignore the mouseout
  482. // EventObject.within is the only correct way to determine this.
  483. if (me.disabled || e.within(me.target.dom, true)) {
  484. return;
  485. }
  486. me.clearTimer('show');
  487. if (me.autoHide !== false) {
  488. me.delayHide();
  489. }
  490. },
  491. // private
  492. delayHide: function() {
  493. var me = this;
  494. if (!me.hidden &amp;&amp; !me.hideTimer) {
  495. me.hideTimer = Ext.defer(me.hide, me.hideDelay, me);
  496. }
  497. },
  498. <span id='Ext-tip-ToolTip-method-hide'> /**
  499. </span> * Hides this tooltip if visible.
  500. */
  501. hide: function() {
  502. var me = this;
  503. me.clearTimer('dismiss');
  504. me.lastActive = new Date();
  505. if (me.anchorEl) {
  506. me.anchorEl.hide();
  507. }
  508. me.callParent(arguments);
  509. delete me.triggerElement;
  510. },
  511. <span id='Ext-tip-ToolTip-method-show'> /**
  512. </span> * Shows this tooltip at the current event target XY position.
  513. */
  514. show: function() {
  515. var me = this;
  516. // Show this Component first, so that sizing can be calculated
  517. // pre-show it off screen so that the el will have dimensions
  518. this.callParent();
  519. if (this.hidden === false) {
  520. me.setPagePosition(-10000, -10000);
  521. if (me.anchor) {
  522. me.anchor = me.origAnchor;
  523. }
  524. if (!me.calledFromShowAt) {
  525. me.showAt(me.getTargetXY());
  526. }
  527. if (me.anchor) {
  528. me.syncAnchor();
  529. me.anchorEl.show();
  530. } else {
  531. me.anchorEl.hide();
  532. }
  533. }
  534. },
  535. // inherit docs
  536. showAt: function(xy) {
  537. var me = this;
  538. me.lastActive = new Date();
  539. me.clearTimers();
  540. me.calledFromShowAt = true;
  541. // Only call if this is hidden. May have been called from show above.
  542. if (!me.isVisible()) {
  543. this.callParent(arguments);
  544. }
  545. // Show may have been vetoed.
  546. if (me.isVisible()) {
  547. me.setPagePosition(xy[0], xy[1]);
  548. if (me.constrainPosition || me.constrain) {
  549. me.doConstrain();
  550. }
  551. me.toFront(true);
  552. me.el.sync(true);
  553. if (me.dismissDelay &amp;&amp; me.autoHide !== false) {
  554. me.dismissTimer = Ext.defer(me.hide, me.dismissDelay, me);
  555. }
  556. if (me.anchor) {
  557. me.syncAnchor();
  558. if (!me.anchorEl.isVisible()) {
  559. me.anchorEl.show();
  560. }
  561. } else {
  562. me.anchorEl.hide();
  563. }
  564. }
  565. delete me.calledFromShowAt;
  566. },
  567. // private
  568. syncAnchor: function() {
  569. var me = this,
  570. anchorPos,
  571. targetPos,
  572. offset;
  573. switch (me.tipAnchor.charAt(0)) {
  574. case 't':
  575. anchorPos = 'b';
  576. targetPos = 'tl';
  577. offset = [20 + me.anchorOffset, 1];
  578. break;
  579. case 'r':
  580. anchorPos = 'l';
  581. targetPos = 'tr';
  582. offset = [ - 1, 12 + me.anchorOffset];
  583. break;
  584. case 'b':
  585. anchorPos = 't';
  586. targetPos = 'bl';
  587. offset = [20 + me.anchorOffset, -1];
  588. break;
  589. default:
  590. anchorPos = 'r';
  591. targetPos = 'tl';
  592. offset = [1, 12 + me.anchorOffset];
  593. break;
  594. }
  595. me.anchorEl.alignTo(me.el, anchorPos + '-' + targetPos, offset);
  596. me.anchorEl.setStyle('z-index', parseInt(me.el.getZIndex(), 10) || 0 + 1).setVisibilityMode(Ext.Element.DISPLAY);
  597. },
  598. // private
  599. setPagePosition: function(x, y) {
  600. var me = this;
  601. me.callParent(arguments);
  602. if (me.anchor) {
  603. me.syncAnchor();
  604. }
  605. },
  606. // private
  607. clearTimer: function(name) {
  608. name = name + 'Timer';
  609. clearTimeout(this[name]);
  610. delete this[name];
  611. },
  612. // private
  613. clearTimers: function() {
  614. var me = this;
  615. me.clearTimer('show');
  616. me.clearTimer('dismiss');
  617. me.clearTimer('hide');
  618. },
  619. // private
  620. onShow: function() {
  621. var me = this;
  622. me.callParent();
  623. me.mon(Ext.getDoc(), 'mousedown', me.onDocMouseDown, me);
  624. },
  625. // private
  626. onHide: function() {
  627. var me = this;
  628. me.callParent();
  629. me.mun(Ext.getDoc(), 'mousedown', me.onDocMouseDown, me);
  630. },
  631. // private
  632. onDocMouseDown: function(e) {
  633. var me = this;
  634. if (!me.closable &amp;&amp; !e.within(me.el.dom)) {
  635. me.disable();
  636. Ext.defer(me.doEnable, 100, me);
  637. }
  638. },
  639. // private
  640. doEnable: function() {
  641. if (!this.isDestroyed) {
  642. this.enable();
  643. }
  644. },
  645. // private
  646. onDisable: function() {
  647. this.callParent();
  648. this.clearTimers();
  649. this.hide();
  650. },
  651. beforeDestroy: function() {
  652. var me = this;
  653. me.clearTimers();
  654. Ext.destroy(me.anchorEl);
  655. delete me.anchorEl;
  656. delete me.target;
  657. delete me.anchorTarget;
  658. delete me.triggerElement;
  659. me.callParent();
  660. },
  661. // private
  662. onDestroy: function() {
  663. Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
  664. this.callParent();
  665. }
  666. });
  667. </pre>
  668. </body>
  669. </html>