|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Simple Tooltip</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Simple Tooltip</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style type="text/css" scoped> |
|
|
29 |
/* Hide overlay markup while loading, if js is enabled */ |
|
|
30 |
.yui3-js-enabled .yui3-overlay-loading { |
|
|
31 |
top:-1000em; |
|
|
32 |
left:-1000em; |
|
|
33 |
position:absolute; |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/* Example Layout CSS */ |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
</style> |
|
|
41 |
|
|
|
42 |
<div class="intro"> |
|
|
43 |
<p>This example demonstrates a lightweight and flexible setup for display |
|
|
44 |
of tooltips.</p> |
|
|
45 |
<p>This displays the tooltip adjacent to the cursor |
|
|
46 |
and takes advantage of the shim capabilities of <code>Overlay</code>, |
|
|
47 |
allowing the tooltip to properly display over <code>select</code> elements in IE.</p> |
|
|
48 |
</div> |
|
|
49 |
|
|
|
50 |
<div class="example"> |
|
|
51 |
<style> |
|
|
52 |
.example .lists { |
|
|
53 |
margin: 10px auto; /*center in viewport*/ |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
.example .list { |
|
|
57 |
-moz-padding-start: 0; |
|
|
58 |
-webkit-padding-start: 0; |
|
|
59 |
width: 300px; |
|
|
60 |
margin: 0; |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
.example #tooltip .yui3-widget-bd{ |
|
|
64 |
text-align: left; |
|
|
65 |
max-width: 15em; |
|
|
66 |
*width: 10em; |
|
|
67 |
background-color: #FFF6D5; |
|
|
68 |
border: solid 1px #aa8; |
|
|
69 |
padding: 0.2em 0.5em 0.3em; |
|
|
70 |
-moz-border-radius: 2px; |
|
|
71 |
-webkit-border-radius: 2px; |
|
|
72 |
-moz-box-shadow: 3px 3px 5px rgba(0,0,0,0.2); |
|
|
73 |
-webkit-box-shadow: 3px 3px 5px rgba(0,0,0,0.2); |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
.example .list li{ |
|
|
77 |
list-style: none; |
|
|
78 |
margin: 0 0 20px; |
|
|
79 |
border: 1px solid #C9C9C9; |
|
|
80 |
width: 300px; |
|
|
81 |
} |
|
|
82 |
|
|
|
83 |
.example .list img{ |
|
|
84 |
vertical-align: bottom; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
.example .list .select{ |
|
|
88 |
padding: 1.5em 0 0.5em; |
|
|
89 |
text-indent: 0.5em; |
|
|
90 |
background-color: #F7DBB2; |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
</style> |
|
|
94 |
|
|
|
95 |
<body class="yui3-skin-sam"> |
|
|
96 |
<div id="tooltip"></div> |
|
|
97 |
|
|
|
98 |
<div class="yui3-g lists"> |
|
|
99 |
<div class="yui3-u-1-2"> <!-- see CSS Grids --> |
|
|
100 |
<ul class="list"> |
|
|
101 |
<li class="wrench"><img src="../assets/overlay/img/wrench.png"></li> |
|
|
102 |
<li class="calipers"><img src="../assets/overlay/img/calipers.png"/></li> |
|
|
103 |
<li class="drill"><img src="../assets/overlay/img/drill.png"/></li> |
|
|
104 |
<li class="ohm"><img src="../assets/overlay/img/ohm.png"/></li> |
|
|
105 |
<li class="level"><img src="../assets/overlay/img/level.png"/></li> |
|
|
106 |
</ul> |
|
|
107 |
</div> |
|
|
108 |
<div class="yui3-u"> |
|
|
109 |
<ul class="list"> |
|
|
110 |
<li class="endwrench"><img src="../assets/overlay/img/endwrench.png"/></li> |
|
|
111 |
<li class="knife"><img src="../assets/overlay/img/knife.png"/></li> |
|
|
112 |
<li class="scissors"><img src="../assets/overlay/img/scissors.png"/></li> |
|
|
113 |
<li class="screwdriver"><img src="../assets/overlay/img/screwdriver.png"/></li> |
|
|
114 |
<li class="tape"><img src="../assets/overlay/img/tape.png"/></li> |
|
|
115 |
<li class="select">Tooltips cover <select><option>select</option></select> elements in IE.</li> |
|
|
116 |
</ul> |
|
|
117 |
</div> |
|
|
118 |
</div> |
|
|
119 |
|
|
|
120 |
<script> |
|
|
121 |
YUI().use('overlay', 'event', 'widget-anim', function (Y) { |
|
|
122 |
|
|
|
123 |
var waitingToShow = false, |
|
|
124 |
|
|
|
125 |
// array for text to be displayed in tooltips |
|
|
126 |
tipText = [ |
|
|
127 |
{'name': 'wrench', 'text': "Avoid dropping on toe."}, |
|
|
128 |
{'name': 'calipers', 'text': 'Dial calipers: +- .001,<br>human hair .004'}, |
|
|
129 |
{'name': 'drill', 'text': 'Variable-speed and cordless too.'}, |
|
|
130 |
{'name': 'ohm', 'text': 'Never test microwaves with a volt-ohm meter.'}, |
|
|
131 |
{'name': 'level', 'text': 'Unreliable in zero gravity conditions.'}, |
|
|
132 |
{'name': 'endwrench', 'text': '11/16 box-end wrench A.K.A spanner - (British)'}, |
|
|
133 |
{'name': 'knife', 'text': 'Wants to roll off table and stick in foot.'}, |
|
|
134 |
{'name': 'scissors', 'text': "Don't run with these."}, |
|
|
135 |
{'name': 'screwdriver', 'text': 'Not intended for garden weeding.'}, |
|
|
136 |
{'name': 'tape', 'text': 'Remove before cutting.'}, |
|
|
137 |
{'name': 'select', 'text': 'Covering select'} |
|
|
138 |
]; |
|
|
139 |
|
|
|
140 |
var tooltip = new Y.Overlay({ |
|
|
141 |
srcNode: "#tooltip", |
|
|
142 |
visible: false |
|
|
143 |
}).plug(Y.Plugin.WidgetAnim); |
|
|
144 |
tooltip.anim.get('animHide').set('duration', 0.01); |
|
|
145 |
tooltip.anim.get('animShow').set('duration', 0.3); |
|
|
146 |
tooltip.render(); |
|
|
147 |
|
|
|
148 |
// handler that positions and shows the tooltip |
|
|
149 |
var onMousemove = function (e) { |
|
|
150 |
var i; |
|
|
151 |
if (tooltip.get('visible') === false) { |
|
|
152 |
// while it's still hidden, move the tooltip adjacent to the cursor |
|
|
153 |
Y.one('#tooltip').setStyle('opacity', '0'); |
|
|
154 |
tooltip.move([(e.pageX + 10), (e.pageY + 20)]); |
|
|
155 |
} |
|
|
156 |
if (waitingToShow === false) { |
|
|
157 |
// wait half a second, then show tooltip |
|
|
158 |
setTimeout(function(){ |
|
|
159 |
Y.one('#tooltip').setStyle('opacity', '1'); |
|
|
160 |
tooltip.show(); |
|
|
161 |
}, 500); |
|
|
162 |
|
|
|
163 |
// while waiting to show tooltip, don't let other |
|
|
164 |
// mousemoves try to show tooltip too. |
|
|
165 |
waitingToShow = true; |
|
|
166 |
|
|
|
167 |
// loop through the tipText array looking for a match between |
|
|
168 |
// the class name and the array literal <code>name</code> |
|
|
169 |
for (i = 0; i < tipText.length; i += 1) { |
|
|
170 |
if (e.currentTarget.hasClass(tipText[i].name)) { |
|
|
171 |
|
|
|
172 |
// found a match, so set the content in the tooltip's body |
|
|
173 |
tooltip.setStdModContent('body', tipText[i].text); |
|
|
174 |
break; |
|
|
175 |
} |
|
|
176 |
} |
|
|
177 |
} |
|
|
178 |
} |
|
|
179 |
|
|
|
180 |
// handler that hides the tooltip |
|
|
181 |
var onMouseleave = function (e) { |
|
|
182 |
|
|
|
183 |
// this check prevents hiding the tooltip |
|
|
184 |
// when the cursor moves over the tooltip itself |
|
|
185 |
if ((e.relatedTarget) && (e.relatedTarget.hasClass('yui3-widget-bd') === false)) { |
|
|
186 |
tooltip.hide(); |
|
|
187 |
waitingToShow = false; |
|
|
188 |
} |
|
|
189 |
} |
|
|
190 |
|
|
|
191 |
Y.delegate('mousemove', onMousemove, '.lists', 'li'); |
|
|
192 |
Y.delegate('mouseleave', onMouseleave, '.lists', 'li'); |
|
|
193 |
Y.one('#tooltip').on('mouseleave', onMouseleave); |
|
|
194 |
|
|
|
195 |
}); |
|
|
196 |
</script> |
|
|
197 |
</body> |
|
|
198 |
</div> |
|
|
199 |
|
|
|
200 |
<h2>Simple Tooltips</h2> |
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
<h3>The Tooltip Markup</h3> |
|
|
205 |
|
|
|
206 |
<p>We just need a <code>div</code> for the tooltip, and some elements that want to |
|
|
207 |
have tooltips.</p> |
|
|
208 |
|
|
|
209 |
<pre class="code prettyprint"><div id="tooltip"></div> |
|
|
210 |
|
|
|
211 |
<ul class="list"> |
|
|
212 |
<li class="wrench"><img src="../assets/overlay/img/wrench.png"/></li> |
|
|
213 |
<li class="calipers"><img src="../assets/overlay/img/calipers.png"/></li> |
|
|
214 |
<li class="drill"><img src="../assets/overlay/img/drill.png"/></li> |
|
|
215 |
<li class="ohm"><img src="../assets/overlay/img/ohm.png"/></li> |
|
|
216 |
<li class="level"><img src="../assets/overlay/img/level.png"/></li> |
|
|
217 |
</ul></pre> |
|
|
218 |
|
|
|
219 |
|
|
|
220 |
<h3>Setting Up the YUI Instance</h3> |
|
|
221 |
|
|
|
222 |
<p>We'll use the <code>Overlay</code> module to provide shimming for correctly covering |
|
|
223 |
<code><select></code> elements in IE. We'll use <code>Event</code> for its <code>onmouseleave</code> event, and |
|
|
224 |
<code>widget-anim</code> as a plugin to provide the fade-in for the tooltip. |
|
|
225 |
</p> |
|
|
226 |
|
|
|
227 |
<pre class="code prettyprint">YUI().use('overlay', 'event', 'widget-anim', function (Y) { |
|
|
228 |
// code will go here. |
|
|
229 |
});</pre> |
|
|
230 |
|
|
|
231 |
<h3>Declare some variables</h3> |
|
|
232 |
|
|
|
233 |
<p>These variables include an array of strings for various tooltips. |
|
|
234 |
If a DOM element has a class matching one of the <code>name</code> values in the <code>tipText</code> array, |
|
|
235 |
it will display the corresponding text value in its tooltip when the cursor moves |
|
|
236 |
over it. |
|
|
237 |
</p> |
|
|
238 |
|
|
|
239 |
<pre class="code prettyprint">var waitingToShow = false, |
|
|
240 |
|
|
|
241 |
// array for text to be displayed in tooltips |
|
|
242 |
tipText = [ |
|
|
243 |
{'name': 'wrench', 'text': "Avoid dropping on toe."}, |
|
|
244 |
{'name': 'calipers', 'text': 'Dial calipers: +- .001,<br>human hair .004'}, |
|
|
245 |
{'name': 'drill', 'text': 'Variable-speed and cordless too.'}, |
|
|
246 |
{'name': 'ohm', 'text': 'Never test microwaves with a volt-ohm meter.'}, |
|
|
247 |
{'name': 'level', 'text': 'Unreliable in zero gravity conditions.'} |
|
|
248 |
// the array continues... |
|
|
249 |
];</pre> |
|
|
250 |
|
|
|
251 |
|
|
|
252 |
<h3>Instantiating The Tooltip</h3> |
|
|
253 |
|
|
|
254 |
<p>To create an overlay instance for the tooltip, |
|
|
255 |
we use the overlay constructor <code>Y.Overlay</code>, specifying the source node |
|
|
256 |
as the selector of the tooltip element. |
|
|
257 |
</p> |
|
|
258 |
|
|
|
259 |
<pre class="code prettyprint">var tooltip = new Y.Overlay({ |
|
|
260 |
srcNode: "#tooltip", |
|
|
261 |
visible: false |
|
|
262 |
}).plug(Y.Plugin.WidgetAnim); |
|
|
263 |
tooltip.anim.get('animHide').set('duration', 0.01); |
|
|
264 |
tooltip.anim.get('animShow').set('duration', 0.3); |
|
|
265 |
tooltip.render();</pre> |
|
|
266 |
|
|
|
267 |
|
|
|
268 |
<h3>Event Handlers</h3> |
|
|
269 |
|
|
|
270 |
<p> |
|
|
271 |
Create event handlers for the mouse events |
|
|
272 |
and place them above the listeners code. |
|
|
273 |
</p> |
|
|
274 |
<pre class="code prettyprint">// handler that positions and shows the tooltip |
|
|
275 |
var onMousemove = function (e) { |
|
|
276 |
var i; |
|
|
277 |
if (tooltip.get('visible') === false) { |
|
|
278 |
// while it's still hidden, move the tooltip adjacent to the cursor |
|
|
279 |
Y.one('#tooltip').setStyle('opacity', '0'); |
|
|
280 |
tooltip.move([(e.pageX + 10), (e.pageY + 20)]); |
|
|
281 |
} |
|
|
282 |
if (waitingToShow === false) { |
|
|
283 |
// wait half a second, then show tooltip |
|
|
284 |
setTimeout(function(){ |
|
|
285 |
Y.one('#tooltip').setStyle('opacity', '1'); |
|
|
286 |
tooltip.show(); |
|
|
287 |
}, 500); |
|
|
288 |
|
|
|
289 |
// while waiting to show tooltip, don't let other |
|
|
290 |
// mousemoves try to show tooltip too. |
|
|
291 |
waitingToShow = true; |
|
|
292 |
|
|
|
293 |
// loop through the tipText array looking for a match between |
|
|
294 |
// the class name and the array literal `name` |
|
|
295 |
for (i = 0; i < tipText.length; i += 1) { |
|
|
296 |
if (e.currentTarget.hasClass(tipText[i].name)) { |
|
|
297 |
|
|
|
298 |
// found a match, so set the content in the tooltip's body |
|
|
299 |
tooltip.setStdModContent('body', tipText[i].text); |
|
|
300 |
break; |
|
|
301 |
} |
|
|
302 |
} |
|
|
303 |
} |
|
|
304 |
} |
|
|
305 |
|
|
|
306 |
// handler that hides the tooltip |
|
|
307 |
var onMouseleave = function (e) { |
|
|
308 |
|
|
|
309 |
// this check prevents hiding the tooltip |
|
|
310 |
// when the cursor moves over the tooltip itself |
|
|
311 |
if ((e.relatedTarget) && (e.relatedTarget.hasClass('yui3-widget-bd') === false)) { |
|
|
312 |
tooltip.hide(); |
|
|
313 |
waitingToShow = false; |
|
|
314 |
} |
|
|
315 |
}</pre> |
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
<h3>Event Listeners</h3> |
|
|
320 |
|
|
|
321 |
<p> |
|
|
322 |
Add listeners for <code>mousemove</code> and <code>mouseout</code> events |
|
|
323 |
to whatever elements you want to have tooltips. |
|
|
324 |
Using <code>mousemove</code> instead of <code>mouseover</code>, and using a <code>delay</code> in the <code>transition</code> |
|
|
325 |
makes the tooltip fade in adjacent to the cursor. |
|
|
326 |
See <a href="../event/index.html#delegation">event delegation</a> for efficient |
|
|
327 |
event subscribing to multiple elements. |
|
|
328 |
</p> |
|
|
329 |
|
|
|
330 |
<pre class="code prettyprint">Y.delegate('mousemove', onMousemove, '.lists', 'li'); |
|
|
331 |
Y.delegate('mouseleave', onMouseleave, '.lists', 'li'); |
|
|
332 |
Y.one('#tooltip').on('mouseleave', onMouseleave);</pre> |
|
|
333 |
|
|
|
334 |
<p> |
|
|
335 |
This example demonstrates how you can use the existing Overlay component |
|
|
336 |
to create a one-off Tooltip for your page. |
|
|
337 |
If you plan to re-use the Tooltip on multiple pages, |
|
|
338 |
or in a variety of use cases, it's a good idea to encapsulate |
|
|
339 |
all the code which makes a tooltip work into a reusable Widget class. |
|
|
340 |
The example, |
|
|
341 |
<a href="../widget/widget-tooltip.html">Creating a Simple Tooltip Widget with Extensions</a>, |
|
|
342 |
shows how you can create a reusable, flexible Tooltip class. |
|
|
343 |
</p> |
|
|
344 |
|
|
|
345 |
<h3>Complete Example Source</h3> |
|
|
346 |
<pre class="code prettyprint"><style> |
|
|
347 |
.example .lists { |
|
|
348 |
margin: 10px auto; /*center in viewport*/ |
|
|
349 |
} |
|
|
350 |
|
|
|
351 |
.example .list { |
|
|
352 |
-moz-padding-start: 0; |
|
|
353 |
-webkit-padding-start: 0; |
|
|
354 |
width: 300px; |
|
|
355 |
margin: 0; |
|
|
356 |
} |
|
|
357 |
|
|
|
358 |
.example #tooltip .yui3-widget-bd{ |
|
|
359 |
text-align: left; |
|
|
360 |
max-width: 15em; |
|
|
361 |
*width: 10em; |
|
|
362 |
background-color: #FFF6D5; |
|
|
363 |
border: solid 1px #aa8; |
|
|
364 |
padding: 0.2em 0.5em 0.3em; |
|
|
365 |
-moz-border-radius: 2px; |
|
|
366 |
-webkit-border-radius: 2px; |
|
|
367 |
-moz-box-shadow: 3px 3px 5px rgba(0,0,0,0.2); |
|
|
368 |
-webkit-box-shadow: 3px 3px 5px rgba(0,0,0,0.2); |
|
|
369 |
} |
|
|
370 |
|
|
|
371 |
.example .list li{ |
|
|
372 |
list-style: none; |
|
|
373 |
margin: 0 0 20px; |
|
|
374 |
border: 1px solid #C9C9C9; |
|
|
375 |
width: 300px; |
|
|
376 |
} |
|
|
377 |
|
|
|
378 |
.example .list img{ |
|
|
379 |
vertical-align: bottom; |
|
|
380 |
} |
|
|
381 |
|
|
|
382 |
.example .list .select{ |
|
|
383 |
padding: 1.5em 0 0.5em; |
|
|
384 |
text-indent: 0.5em; |
|
|
385 |
background-color: #F7DBB2; |
|
|
386 |
} |
|
|
387 |
|
|
|
388 |
</style> |
|
|
389 |
|
|
|
390 |
<body class="yui3-skin-sam"> |
|
|
391 |
<div id="tooltip"></div> |
|
|
392 |
|
|
|
393 |
<div class="yui3-g lists"> |
|
|
394 |
<div class="yui3-u-1-2"> <!-- see CSS Grids --> |
|
|
395 |
<ul class="list"> |
|
|
396 |
<li class="wrench"><img src="../assets/overlay/img/wrench.png"></li> |
|
|
397 |
<li class="calipers"><img src="../assets/overlay/img/calipers.png"/></li> |
|
|
398 |
<li class="drill"><img src="../assets/overlay/img/drill.png"/></li> |
|
|
399 |
<li class="ohm"><img src="../assets/overlay/img/ohm.png"/></li> |
|
|
400 |
<li class="level"><img src="../assets/overlay/img/level.png"/></li> |
|
|
401 |
</ul> |
|
|
402 |
</div> |
|
|
403 |
<div class="yui3-u"> |
|
|
404 |
<ul class="list"> |
|
|
405 |
<li class="endwrench"><img src="../assets/overlay/img/endwrench.png"/></li> |
|
|
406 |
<li class="knife"><img src="../assets/overlay/img/knife.png"/></li> |
|
|
407 |
<li class="scissors"><img src="../assets/overlay/img/scissors.png"/></li> |
|
|
408 |
<li class="screwdriver"><img src="../assets/overlay/img/screwdriver.png"/></li> |
|
|
409 |
<li class="tape"><img src="../assets/overlay/img/tape.png"/></li> |
|
|
410 |
<li class="select">Tooltips cover <select><option>select</option></select> elements in IE.</li> |
|
|
411 |
</ul> |
|
|
412 |
</div> |
|
|
413 |
</div> |
|
|
414 |
|
|
|
415 |
<script> |
|
|
416 |
YUI().use('overlay', 'event', 'widget-anim', function (Y) { |
|
|
417 |
|
|
|
418 |
var waitingToShow = false, |
|
|
419 |
|
|
|
420 |
// array for text to be displayed in tooltips |
|
|
421 |
tipText = [ |
|
|
422 |
{'name': 'wrench', 'text': "Avoid dropping on toe."}, |
|
|
423 |
{'name': 'calipers', 'text': 'Dial calipers: +- .001,<br>human hair .004'}, |
|
|
424 |
{'name': 'drill', 'text': 'Variable-speed and cordless too.'}, |
|
|
425 |
{'name': 'ohm', 'text': 'Never test microwaves with a volt-ohm meter.'}, |
|
|
426 |
{'name': 'level', 'text': 'Unreliable in zero gravity conditions.'}, |
|
|
427 |
{'name': 'endwrench', 'text': '11/16 box-end wrench A.K.A spanner - (British)'}, |
|
|
428 |
{'name': 'knife', 'text': 'Wants to roll off table and stick in foot.'}, |
|
|
429 |
{'name': 'scissors', 'text': "Don't run with these."}, |
|
|
430 |
{'name': 'screwdriver', 'text': 'Not intended for garden weeding.'}, |
|
|
431 |
{'name': 'tape', 'text': 'Remove before cutting.'}, |
|
|
432 |
{'name': 'select', 'text': 'Covering select'} |
|
|
433 |
]; |
|
|
434 |
|
|
|
435 |
var tooltip = new Y.Overlay({ |
|
|
436 |
srcNode: "#tooltip", |
|
|
437 |
visible: false |
|
|
438 |
}).plug(Y.Plugin.WidgetAnim); |
|
|
439 |
tooltip.anim.get('animHide').set('duration', 0.01); |
|
|
440 |
tooltip.anim.get('animShow').set('duration', 0.3); |
|
|
441 |
tooltip.render(); |
|
|
442 |
|
|
|
443 |
// handler that positions and shows the tooltip |
|
|
444 |
var onMousemove = function (e) { |
|
|
445 |
var i; |
|
|
446 |
if (tooltip.get('visible') === false) { |
|
|
447 |
// while it's still hidden, move the tooltip adjacent to the cursor |
|
|
448 |
Y.one('#tooltip').setStyle('opacity', '0'); |
|
|
449 |
tooltip.move([(e.pageX + 10), (e.pageY + 20)]); |
|
|
450 |
} |
|
|
451 |
if (waitingToShow === false) { |
|
|
452 |
// wait half a second, then show tooltip |
|
|
453 |
setTimeout(function(){ |
|
|
454 |
Y.one('#tooltip').setStyle('opacity', '1'); |
|
|
455 |
tooltip.show(); |
|
|
456 |
}, 500); |
|
|
457 |
|
|
|
458 |
// while waiting to show tooltip, don't let other |
|
|
459 |
// mousemoves try to show tooltip too. |
|
|
460 |
waitingToShow = true; |
|
|
461 |
|
|
|
462 |
// loop through the tipText array looking for a match between |
|
|
463 |
// the class name and the array literal `name` |
|
|
464 |
for (i = 0; i < tipText.length; i += 1) { |
|
|
465 |
if (e.currentTarget.hasClass(tipText[i].name)) { |
|
|
466 |
|
|
|
467 |
// found a match, so set the content in the tooltip's body |
|
|
468 |
tooltip.setStdModContent('body', tipText[i].text); |
|
|
469 |
break; |
|
|
470 |
} |
|
|
471 |
} |
|
|
472 |
} |
|
|
473 |
} |
|
|
474 |
|
|
|
475 |
// handler that hides the tooltip |
|
|
476 |
var onMouseleave = function (e) { |
|
|
477 |
|
|
|
478 |
// this check prevents hiding the tooltip |
|
|
479 |
// when the cursor moves over the tooltip itself |
|
|
480 |
if ((e.relatedTarget) && (e.relatedTarget.hasClass('yui3-widget-bd') === false)) { |
|
|
481 |
tooltip.hide(); |
|
|
482 |
waitingToShow = false; |
|
|
483 |
} |
|
|
484 |
} |
|
|
485 |
|
|
|
486 |
Y.delegate('mousemove', onMousemove, '.lists', 'li'); |
|
|
487 |
Y.delegate('mouseleave', onMouseleave, '.lists', 'li'); |
|
|
488 |
Y.one('#tooltip').on('mouseleave', onMouseleave); |
|
|
489 |
|
|
|
490 |
}); |
|
|
491 |
</script> |
|
|
492 |
</body></pre> |
|
|
493 |
|
|
|
494 |
</div> |
|
|
495 |
</div> |
|
|
496 |
</div> |
|
|
497 |
|
|
|
498 |
<div class="yui3-u-1-4"> |
|
|
499 |
<div class="sidebar"> |
|
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
|
503 |
<div class="sidebox"> |
|
|
504 |
<div class="hd"> |
|
|
505 |
<h2 class="no-toc">Examples</h2> |
|
|
506 |
</div> |
|
|
507 |
|
|
|
508 |
<div class="bd"> |
|
|
509 |
<ul class="examples"> |
|
|
510 |
|
|
|
511 |
|
|
|
512 |
<li data-description="Shows how to instantiate a basic Overlay instance, and use the Overlay's basic XY positioning support."> |
|
|
513 |
<a href="overlay-xy.html">Basic XY Positioning</a> |
|
|
514 |
</li> |
|
|
515 |
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
<li data-description="Shows how to create a simple tooltip incorporating the overlay shim feature."> |
|
|
519 |
<a href="overlay-tooltip.html">Simple Tooltip</a> |
|
|
520 |
</li> |
|
|
521 |
|
|
|
522 |
|
|
|
523 |
|
|
|
524 |
<li data-description="Shows how to use the Overlay's XY alignment support, to align the Overlay relative to another element, or to the viewport."> |
|
|
525 |
<a href="overlay-align.html">Alignment Support</a> |
|
|
526 |
</li> |
|
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
|
530 |
<li data-description="Shows how to use the Overlay's zindex and shim support when positioning Overlays above other elements on the page."> |
|
|
531 |
<a href="overlay-stack.html">Stack Support</a> |
|
|
532 |
</li> |
|
|
533 |
|
|
|
534 |
|
|
|
535 |
|
|
|
536 |
<li data-description="Shows how to modify content in the Overlay's header, body and footer sections."> |
|
|
537 |
<a href="overlay-stdmod.html">Standard Module Support</a> |
|
|
538 |
</li> |
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
<li data-description="Shows how to use Overlay's constrainment support, to limit the XY value which can be set for an Overlay."> |
|
|
543 |
<a href="overlay-constrain.html">Constrain Support</a> |
|
|
544 |
</li> |
|
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
<li data-description="Shows how to create a simple plugin to retrieve content for the Overlay using the io utility."> |
|
|
549 |
<a href="overlay-io-plugin.html">IO Plugin</a> |
|
|
550 |
</li> |
|
|
551 |
|
|
|
552 |
|
|
|
553 |
|
|
|
554 |
<li data-description="Shows how to create a simple plugin to animate the Overlay's movement and visibility."> |
|
|
555 |
<a href="overlay-anim-plugin.html">Animation Plugin</a> |
|
|
556 |
</li> |
|
|
557 |
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
</ul> |
|
|
564 |
</div> |
|
|
565 |
</div> |
|
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
|
569 |
<div class="sidebox"> |
|
|
570 |
<div class="hd"> |
|
|
571 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
572 |
</div> |
|
|
573 |
|
|
|
574 |
<div class="bd"> |
|
|
575 |
<ul class="examples"> |
|
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
|
589 |
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
|
594 |
<li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event's delegation support and mouseenter event, along with the Overlay widget and Node's support for the WAI-ARIA Roles and States."> |
|
|
595 |
<a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a> |
|
|
596 |
</li> |
|
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
|
600 |
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input"> |
|
|
601 |
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a> |
|
|
602 |
</li> |
|
|
603 |
|
|
|
604 |
|
|
|
605 |
</ul> |
|
|
606 |
</div> |
|
|
607 |
</div> |
|
|
608 |
|
|
|
609 |
</div> |
|
|
610 |
</div> |
|
|
611 |
</div> |
|
|
612 |
</div> |
|
|
613 |
|
|
|
614 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
615 |
<script>prettyPrint();</script> |
|
|
616 |
|
|
|
617 |
<script> |
|
|
618 |
YUI.Env.Tests = { |
|
|
619 |
examples: [], |
|
|
620 |
project: '../assets', |
|
|
621 |
assets: '../assets/overlay', |
|
|
622 |
name: 'overlay-tooltip', |
|
|
623 |
title: 'Simple Tooltip', |
|
|
624 |
newWindow: '', |
|
|
625 |
auto: false |
|
|
626 |
}; |
|
|
627 |
YUI.Env.Tests.examples.push('overlay-xy'); |
|
|
628 |
YUI.Env.Tests.examples.push('overlay-tooltip'); |
|
|
629 |
YUI.Env.Tests.examples.push('overlay-align'); |
|
|
630 |
YUI.Env.Tests.examples.push('overlay-stack'); |
|
|
631 |
YUI.Env.Tests.examples.push('overlay-stdmod'); |
|
|
632 |
YUI.Env.Tests.examples.push('overlay-constrain'); |
|
|
633 |
YUI.Env.Tests.examples.push('overlay-io-plugin'); |
|
|
634 |
YUI.Env.Tests.examples.push('overlay-anim-plugin'); |
|
|
635 |
YUI.Env.Tests.examples.push('node-focusmanager-button'); |
|
|
636 |
YUI.Env.Tests.examples.push('stylesheet-theme'); |
|
|
637 |
|
|
|
638 |
</script> |
|
|
639 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
640 |
|
|
|
641 |
|
|
|
642 |
|
|
|
643 |
</body> |
|
|
644 |
</html> |