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