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.
16 * @class Ext.tip.QuickTipManager
18 * Provides attractive and customizable tooltips for any element. The QuickTips
19 * singleton is used to configure and manage tooltips globally for multiple elements
20 * in a generic manner. To create individual tooltips with maximum customizability,
21 * you should consider either {@link Ext.tip.Tip} or {@link Ext.tip.ToolTip}.
23 * Quicktips can be configured via tag attributes directly in markup, or by
24 * registering quick tips programmatically via the {@link #register} method.
26 * The singleton's instance of {@link Ext.tip.QuickTip} is available via
27 * {@link #getQuickTip}, and supports all the methods, and all the all the
28 * configuration properties of Ext.tip.QuickTip. These settings will apply to all
29 * tooltips shown by the singleton.
31 * Below is the summary of the configuration properties which can be used.
32 * For detailed descriptions see the config options for the {@link Ext.tip.QuickTip QuickTip} class
34 * ## QuickTips singleton configs (all are optional)
43 * ## Target element configs (optional unless otherwise noted)
47 * - `dismissDelay` (overrides singleton value)
48 * - `target` (required)
53 * Here is an example showing how some of these config options could be used:
55 * {@img Ext.tip.QuickTipManager/Ext.tip.QuickTipManager.png Ext.tip.QuickTipManager component}
59 * // Init the singleton. Any tag-based quick tips will start working.
60 * Ext.tip.QuickTipManager.init();
62 * // Apply a set of config properties to the singleton
63 * Ext.apply(Ext.tip.QuickTipManager.getQuickTip(), {
66 * showDelay: 50 // Show 50ms after entering target
69 * // Create a small panel to add a quick tip to
70 * Ext.create('Ext.container.Container', {
71 * id: 'quickTipContainer',
75 * backgroundColor:'#000000'
77 * renderTo: Ext.getBody()
81 * // Manually register a quick tip for a specific element
82 * Ext.tip.QuickTipManager.register({
83 * target: 'quickTipContainer',
84 * title: 'My Tooltip',
85 * text: 'This tooltip was added in code',
87 * dismissDelay: 10000 // Hide after 10 seconds hover
90 * To register a quick tip in markup, you simply add one or more of the valid QuickTip attributes prefixed with
91 * the **data-** namespace. The HTML element itself is automatically set as the quick tip target. Here is the summary
92 * of supported attributes (optional unless otherwise noted):
94 * - `hide`: Specifying "user" is equivalent to setting autoHide = false. Any other value will be the same as autoHide = true.
95 * - `qclass`: A CSS class to be applied to the quick tip (equivalent to the 'cls' target element config).
96 * - `qtip (required)`: The quick tip text (equivalent to the 'text' target element config).
97 * - `qtitle`: The quick tip title (equivalent to the 'title' target element config).
98 * - `qwidth`: The quick tip width (equivalent to the 'width' target element config).
100 * Here is an example of configuring an HTML element to display a tooltip from markup:
102 * // Add a quick tip to an HTML button
103 * <input type="button" value="OK" data-qtitle="OK Button" data-qwidth="100"
104 * data-qtip="This is a quick tip from markup!"></input>
108 Ext.define('Ext.tip.QuickTipManager', function() {
113 requires: ['Ext.tip.QuickTip'],
115 alternateClassName: 'Ext.QuickTips',
118 * Initialize the global QuickTips instance and prepare any quick tips.
119 * @param {Boolean} autoRender True to render the QuickTips container immediately to
120 * preload images. (Defaults to true)
121 * @param {Object} config An optional config object for the created QuickTip. By
122 * default, the {@link Ext.tip.QuickTip QuickTip} class is instantiated, but this can
123 * be changed by supplying an xtype property or a className property in this object.
124 * All other properties on this object are configuration for the created component.
126 init : function (autoRender, config) {
129 Ext.onReady(function(){
130 Ext.tip.QuickTipManager.init(autoRender);
135 var tipConfig = Ext.apply({ disabled: disabled }, config),
136 className = tipConfig.className,
137 xtype = tipConfig.xtype;
140 delete tipConfig.className;
142 className = 'widget.' + xtype;
143 delete tipConfig.xtype;
146 if (autoRender !== false) {
147 tipConfig.renderTo = document.body;
150 if (tipConfig.renderTo.tagName != 'BODY') { // e.g., == 'FRAMESET'
152 sourceClass: 'Ext.tip.QuickTipManager',
153 sourceMethod: 'init',
154 msg: 'Cannot init QuickTipManager: no document body'
160 tip = Ext.create(className || 'Ext.tip.QuickTip', tipConfig);
165 * Destroy the QuickTips instance.
167 destroy: function() {
175 // Protected method called by the dd classes
176 ddDisable : function(){
177 // don't disable it if we don't need to
178 if(tip && !disabled){
183 // Protected method called by the dd classes
184 ddEnable : function(){
185 // only enable it if it hasn't been disabled
186 if(tip && !disabled){
192 * Enable quick tips globally.
202 * Disable quick tips globally.
204 disable : function(){
212 * Returns true if quick tips are enabled, else false.
215 isEnabled : function(){
216 return tip !== undefined && !tip.disabled;
220 * Gets the single {@link Ext.tip.QuickTip QuickTip} instance used to show tips from all registered elements.
221 * @return {Ext.tip.QuickTip}
223 getQuickTip : function(){
228 * Configures a new quick tip instance and assigns it to a target element. See
229 * {@link Ext.tip.QuickTip#register} for details.
230 * @param {Object} config The config object
232 register : function(){
233 tip.register.apply(tip, arguments);
237 * Removes any registered quick tip from the target element and destroys it.
238 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
240 unregister : function(){
241 tip.unregister.apply(tip, arguments);
245 * Alias of {@link #register}.
246 * @param {Object} config The config object
249 tip.register.apply(tip, arguments);