Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / QuickTips.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 <div id="cls-Ext.QuickTips"></div>/**\r
15  * @class Ext.QuickTips\r
16  * <p>Provides attractive and customizable tooltips for any element. The QuickTips\r
17  * singleton is used to configure and manage tooltips globally for multiple elements\r
18  * in a generic manner.  To create individual tooltips with maximum customizability,\r
19  * you should consider either {@link Ext.Tip} or {@link Ext.ToolTip}.</p>\r
20  * <p>Quicktips can be configured via tag attributes directly in markup, or by\r
21  * registering quick tips programmatically via the {@link #register} method.</p>\r
22  * <p>The singleton's instance of {@link Ext.QuickTip} is available via\r
23  * {@link #getQuickTip}, and supports all the methods, and all the all the\r
24  * configuration properties of Ext.QuickTip. These settings will apply to all\r
25  * tooltips shown by the singleton.</p>\r
26  * <p>Below is the summary of the configuration properties which can be used.\r
27  * For detailed descriptions see {@link #getQuickTip}</p>\r
28  * <p><b>QuickTips singleton configs (all are optional)</b></p>\r
29  * <div class="mdetail-params"><ul><li>dismissDelay</li>\r
30  * <li>hideDelay</li>\r
31  * <li>maxWidth</li>\r
32  * <li>minWidth</li>\r
33  * <li>showDelay</li>\r
34  * <li>trackMouse</li></ul></div>\r
35  * <p><b>Target element configs (optional unless otherwise noted)</b></p>\r
36  * <div class="mdetail-params"><ul><li>autoHide</li>\r
37  * <li>cls</li>\r
38  * <li>dismissDelay (overrides singleton value)</li>\r
39  * <li>target (required)</li>\r
40  * <li>text (required)</li>\r
41  * <li>title</li>\r
42  * <li>width</li></ul></div>\r
43  * <p>Here is an example showing how some of these config options could be used:</p>\r
44  * <pre><code>\r
45 // Init the singleton.  Any tag-based quick tips will start working.\r
46 Ext.QuickTips.init();\r
47 \r
48 // Apply a set of config properties to the singleton\r
49 Ext.apply(Ext.QuickTips.getQuickTip(), {\r
50     maxWidth: 200,\r
51     minWidth: 100,\r
52     showDelay: 50,\r
53     trackMouse: true\r
54 });\r
55 \r
56 // Manually register a quick tip for a specific element\r
57 Ext.QuickTips.register({\r
58     target: 'my-div',\r
59     title: 'My Tooltip',\r
60     text: 'This tooltip was added in code',\r
61     width: 100,\r
62     dismissDelay: 20\r
63 });\r
64 </code></pre>\r
65  * <p>To register a quick tip in markup, you simply add one or more of the valid QuickTip attributes prefixed with\r
66  * the <b>ext:</b> namespace.  The HTML element itself is automatically set as the quick tip target. Here is the summary\r
67  * of supported attributes (optional unless otherwise noted):</p>\r
68  * <ul><li><b>hide</b>: Specifying "user" is equivalent to setting autoHide = false.  Any other value will be the\r
69  * same as autoHide = true.</li>\r
70  * <li><b>qclass</b>: A CSS class to be applied to the quick tip (equivalent to the 'cls' target element config).</li>\r
71  * <li><b>qtip (required)</b>: The quick tip text (equivalent to the 'text' target element config).</li>\r
72  * <li><b>qtitle</b>: The quick tip title (equivalent to the 'title' target element config).</li>\r
73  * <li><b>qwidth</b>: The quick tip width (equivalent to the 'width' target element config).</li></ul>\r
74  * <p>Here is an example of configuring an HTML element to display a tooltip from markup:</p>\r
75  * <pre><code>\r
76 // Add a quick tip to an HTML button\r
77 &lt;input type="button" value="OK" ext:qtitle="OK Button" ext:qwidth="100"\r
78      ext:qtip="This is a quick tip from markup!">&lt;/input>\r
79 </code></pre>\r
80  * @singleton\r
81  */\r
82 Ext.QuickTips = function(){\r
83     var tip, locks = [];\r
84     return {\r
85         <div id="method-Ext.QuickTips-init"></div>/**\r
86          * Initialize the global QuickTips instance and prepare any quick tips.\r
87          * @param {Boolean} autoRender True to render the QuickTips container immediately to preload images. (Defaults to true) \r
88          */\r
89         init : function(autoRender){\r
90             if(!tip){\r
91                 if(!Ext.isReady){\r
92                     Ext.onReady(function(){\r
93                         Ext.QuickTips.init(autoRender);\r
94                     });\r
95                     return;\r
96                 }\r
97                 tip = new Ext.QuickTip({elements:'header,body'});\r
98                 if(autoRender !== false){\r
99                     tip.render(Ext.getBody());\r
100                 }\r
101             }\r
102         },\r
103 \r
104         <div id="method-Ext.QuickTips-enable"></div>/**\r
105          * Enable quick tips globally.\r
106          */\r
107         enable : function(){\r
108             if(tip){\r
109                 locks.pop();\r
110                 if(locks.length < 1){\r
111                     tip.enable();\r
112                 }\r
113             }\r
114         },\r
115 \r
116         <div id="method-Ext.QuickTips-disable"></div>/**\r
117          * Disable quick tips globally.\r
118          */\r
119         disable : function(){\r
120             if(tip){\r
121                 tip.disable();\r
122             }\r
123             locks.push(1);\r
124         },\r
125 \r
126         <div id="method-Ext.QuickTips-isEnabled"></div>/**\r
127          * Returns true if quick tips are enabled, else false.\r
128          * @return {Boolean}\r
129          */\r
130         isEnabled : function(){\r
131             return tip !== undefined && !tip.disabled;\r
132         },\r
133 \r
134         <div id="method-Ext.QuickTips-getQuickTip"></div>/**\r
135          * Gets the global QuickTips instance.\r
136          */\r
137         getQuickTip : function(){\r
138             return tip;\r
139         },\r
140 \r
141         <div id="method-Ext.QuickTips-register"></div>/**\r
142          * Configures a new quick tip instance and assigns it to a target element.  See\r
143          * {@link Ext.QuickTip#register} for details.\r
144          * @param {Object} config The config object\r
145          */\r
146         register : function(){\r
147             tip.register.apply(tip, arguments);\r
148         },\r
149 \r
150         <div id="method-Ext.QuickTips-unregister"></div>/**\r
151          * Removes any registered quick tip from the target element and destroys it.\r
152          * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.\r
153          */\r
154         unregister : function(){\r
155             tip.unregister.apply(tip, arguments);\r
156         },\r
157 \r
158         <div id="method-Ext.QuickTips-tips"></div>/**\r
159          * Alias of {@link #register}.\r
160          * @param {Object} config The config object\r
161          */\r
162         tips :function(){\r
163             tip.register.apply(tip, arguments);\r
164         }\r
165     }\r
166 }();</pre>
167 </body>
168 </html>