3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @extends Ext.panel.Panel
18 * This is the base class for {@link Ext.tip.QuickTip} and {@link Ext.tip.ToolTip} that provides the basic layout and
19 * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
20 * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
23 Ext.define('Ext.tip.Tip', {
24 extend: 'Ext.panel.Panel',
25 requires: [ 'Ext.layout.component.Tip' ],
26 alternateClassName: 'Ext.Tip',
28 * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
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.
36 * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
40 * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300). The maximum supported value is 500.
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").
50 * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.core.Element#alignTo} anchor position value
51 * for this tip relative to its element of origin (defaults to "tl-bl?").
53 defaultAlign : "tl-bl?",
55 * @cfg {Boolean} constrainPosition If true, then the tooltip will be automatically constrained to stay within
56 * the browser viewport. Defaults to false.
58 constrainPosition : true,
65 // private panel overrides
68 baseCls: Ext.baseCSSPrefix + 'tip',
74 focusOnToFront: false,
75 componentLayout: 'tip',
78 * @cfg {String} closeAction
79 * <p>The action to take when the close header tool is clicked:
80 * <div class="mdetail-params"><ul>
81 * <li><b><code>'{@link #destroy}'</code></b> : <div class="sub-desc">
82 * {@link #destroy remove} the window from the DOM and {@link Ext.Component#destroy destroy}
83 * it and all descendant Components. The window will <b>not</b> be available to be
84 * redisplayed via the {@link #show} method.
86 * <li><b><code>'{@link #hide}'</code></b> : <b>Default</b><div class="sub-desc">
87 * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
88 * The window will be available to be redisplayed via the {@link #show} method.
91 * <p><b>Note:</b> This behavior has changed! setting *does* affect the {@link #close} method
92 * which will invoke the approriate closeAction.
98 initComponent: function() {
99 this.callParent(arguments);
101 // Or in the deprecated config. Floating.doConstrain only constrains if the constrain property is truthy.
102 this.constrain = this.constrain || this.constrainPosition;
106 * Shows this tip at the specified XY position. Example usage:
108 // Show the tip at x:50 and y:100
109 tip.showAt([50,100]);
111 * @param {Array} xy An array containing the x and y coordinates
113 showAt : function(xy){
116 // Show may have been vetoed.
117 if (me.isVisible()) {
118 me.setPagePosition(xy[0], xy[1]);
119 if (me.constrainPosition || me.constrain) {
127 * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.core.Element#alignTo}
128 * anchor position value. Example usage:
130 // Show the tip at the default position ('tl-br?')
133 // Show the tip's top-left corner anchored to the element's top-right corner
134 tip.showBy('my-el', 'tl-tr');
136 * @param {Mixed} el An HTMLElement, Ext.core.Element or string id of the target element to align to
137 * @param {String} position (optional) A valid {@link Ext.core.Element#alignTo} anchor position (defaults to 'tl-br?' or
138 * {@link #defaultAlign} if specified).
140 showBy : function(el, pos) {
141 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
147 * Set Tip draggable using base Component's draggability
149 initDraggable : function(){
153 delegate: me.header.el,
155 constrainTo: me.el.dom.parentNode
157 // Important: Bypass Panel's initDraggable. Call direct to Component's implementation.
158 Ext.Component.prototype.initDraggable.call(me);
161 // Tip does not ghost. Drag is "live"