|
1 <!DOCTYPE html> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Example: Showing and Hiding</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: Showing and Hiding</h1> |
|
25 <div class="yui3-g"> |
|
26 <div class="yui3-u-3-4"> |
|
27 <div id="main"> |
|
28 <div class="content"><link href="../assets/node/node.css" rel="stylesheet" type="text/css"> |
|
29 <div class="intro"> |
|
30 <p>This example shows how to show and hide <code>Node</code> instances.</p> |
|
31 </div> |
|
32 |
|
33 <div class="example"> |
|
34 <link rel="stylesheet" href='../../build/cssbutton/cssbutton.css'></link> |
|
35 |
|
36 <style> |
|
37 .example #demo { |
|
38 background-color: #D4D8EB; |
|
39 text-align: center; |
|
40 border: 1px solid #9EA8C6; |
|
41 border-radius: 3px 3px 3px 3px; |
|
42 box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25); |
|
43 width: 23em; |
|
44 margin-top: 0.3em; |
|
45 } |
|
46 |
|
47 </style> |
|
48 |
|
49 <button id="hide" class="yui3-button">Hide</button> |
|
50 <button id="show" class="yui3-button">Show</button> |
|
51 <button id="toggle" class="yui3-button">Toggle</button> |
|
52 |
|
53 <div id="demo"><p>Show or hide me with the buttons above.</p></div> |
|
54 |
|
55 <script type="text/javascript"> |
|
56 YUI().use('node', function(Y) { |
|
57 Y.delegate('click', function(e) { |
|
58 var buttonID = e.currentTarget.get('id'), |
|
59 node = Y.one('#demo'); |
|
60 |
|
61 if (buttonID === 'show') { |
|
62 node.show(); |
|
63 } else if (buttonID === 'hide') { |
|
64 node.hide(); |
|
65 } else if (buttonID === 'toggle') { |
|
66 node.toggleView(); |
|
67 } |
|
68 |
|
69 }, document, 'button'); |
|
70 }); |
|
71 </script> |
|
72 |
|
73 </div> |
|
74 |
|
75 <h2>Showing a Node</h2> |
|
76 <p>By default, Node instances are hidden using the node's <code>hidden</code> attribute and the CSS <code>display</code>. Calling the <code>show</code> method displays the node.</p> |
|
77 <pre class="code prettyprint">Y.one('#demo').show();</pre> |
|
78 |
|
79 |
|
80 <h2>Hiding a Node</h2> |
|
81 <p>The opposite of <code>show</code>, the <code>hide</code> method sets the node's <code>hidden</code> attribute to <code>true</code> and the CSS <code>display</code> to <code>none</code>.</p> |
|
82 <pre class="code prettyprint">Y.one('#demo').hide();</pre> |
|
83 |
|
84 |
|
85 <h2>Toggling visibility</h2> |
|
86 <p>You can toggle the visibility between show and hide using <code>toggleView</code>.</p> |
|
87 <pre class="code prettyprint">Y.one('#demo').toggleView();</pre> |
|
88 |
|
89 |
|
90 <h2>Checking visibility</h2> |
|
91 <p>You can detect whether a node is visible or not by checking for the hidden attribute:</p> |
|
92 <pre class="code prettyprint">var isHidden = Y.one('#demo').getAttribute('hidden') === 'true';</pre> |
|
93 |
|
94 <h2>Complete Example Source</h2> |
|
95 <pre class="code prettyprint"><link rel="stylesheet" href='../../build/cssbutton/cssbutton.css'></link> |
|
96 |
|
97 <style> |
|
98 .example #demo { |
|
99 background-color: #D4D8EB; |
|
100 text-align: center; |
|
101 border: 1px solid #9EA8C6; |
|
102 border-radius: 3px 3px 3px 3px; |
|
103 box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25); |
|
104 width: 23em; |
|
105 margin-top: 0.3em; |
|
106 } |
|
107 |
|
108 </style> |
|
109 |
|
110 <button id="hide" class="yui3-button">Hide</button> |
|
111 <button id="show" class="yui3-button">Show</button> |
|
112 <button id="toggle" class="yui3-button">Toggle</button> |
|
113 |
|
114 <div id="demo"><p>Show or hide me with the buttons above.</p></div> |
|
115 |
|
116 <script type="text/javascript"> |
|
117 YUI().use('node', function(Y) { |
|
118 Y.delegate('click', function(e) { |
|
119 var buttonID = e.currentTarget.get('id'), |
|
120 node = Y.one('#demo'); |
|
121 |
|
122 if (buttonID === 'show') { |
|
123 node.show(); |
|
124 } else if (buttonID === 'hide') { |
|
125 node.hide(); |
|
126 } else if (buttonID === 'toggle') { |
|
127 node.toggleView(); |
|
128 } |
|
129 |
|
130 }, document, 'button'); |
|
131 }); |
|
132 </script></pre> |
|
133 |
|
134 </div> |
|
135 </div> |
|
136 </div> |
|
137 |
|
138 <div class="yui3-u-1-4"> |
|
139 <div class="sidebar"> |
|
140 |
|
141 |
|
142 |
|
143 <div class="sidebox"> |
|
144 <div class="hd"> |
|
145 <h2 class="no-toc">Examples</h2> |
|
146 </div> |
|
147 |
|
148 <div class="bd"> |
|
149 <ul class="examples"> |
|
150 |
|
151 |
|
152 <li data-description="Using selectors and property accessors with Node."> |
|
153 <a href="properties.html">Set and Get Properties</a> |
|
154 </li> |
|
155 |
|
156 |
|
157 |
|
158 <li data-description="Using DOM methods with Node."> |
|
159 <a href="dom-node.html">DOM Methods</a> |
|
160 </li> |
|
161 |
|
162 |
|
163 |
|
164 <li data-description="Building a simple store and shopping cart."> |
|
165 <a href="store.html">DOM Methods - Store</a> |
|
166 </li> |
|
167 |
|
168 |
|
169 |
|
170 <li data-description="Listening for DOM events with Node instances."> |
|
171 <a href="events.html">Handling DOM Events</a> |
|
172 </li> |
|
173 |
|
174 |
|
175 |
|
176 <li data-description="NodeList provides Node functionality for manipulating multiple nodes at once."> |
|
177 <a href="nodelist.html">Using NodeList - Simple</a> |
|
178 </li> |
|
179 |
|
180 |
|
181 |
|
182 <li data-description="How to use multiple NodeList features to build a simple game."> |
|
183 <a href="ducks.html">Using NodeList - Ducks Game</a> |
|
184 </li> |
|
185 |
|
186 |
|
187 |
|
188 <li data-description="Using a single event listener to handle events on multiple nodes."> |
|
189 <a href="node-evt-delegation.html">Delegating Node Events</a> |
|
190 </li> |
|
191 |
|
192 |
|
193 |
|
194 <li data-description="This example demonstrates how to position an element in page coordinates."> |
|
195 <a href="node-xy.html">Node Positioning</a> |
|
196 </li> |
|
197 |
|
198 |
|
199 |
|
200 <li data-description="This example demonstrates how to set styles and get style information."> |
|
201 <a href="node-style.html">Node Styling</a> |
|
202 </li> |
|
203 |
|
204 |
|
205 |
|
206 <li data-description="This example demonstrates how to insert content into a Node."> |
|
207 <a href="node-insert.html">Adding Node Content - Burger Builder</a> |
|
208 </li> |
|
209 |
|
210 |
|
211 |
|
212 <li data-description="This example demonstrates how to show and hide a Node."> |
|
213 <a href="node-view.html">Showing and Hiding</a> |
|
214 </li> |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 </ul> |
|
232 </div> |
|
233 </div> |
|
234 |
|
235 |
|
236 |
|
237 <div class="sidebox"> |
|
238 <div class="hd"> |
|
239 <h2 class="no-toc">Examples That Use This Component</h2> |
|
240 </div> |
|
241 |
|
242 <div class="bd"> |
|
243 <ul class="examples"> |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 <li data-description="Creating an accessible toolbar using the Focus Manager Node Plugin and Node's support for the WAI-ARIA Roles and States."> |
|
269 <a href="../node-focusmanager/node-focusmanager-toolbar.html">Accessible Toolbar</a> |
|
270 </li> |
|
271 |
|
272 |
|
273 |
|
274 <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."> |
|
275 <a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a> |
|
276 </li> |
|
277 |
|
278 |
|
279 |
|
280 <li data-description="Use the Event Utility to attach simple DOM event handlers."> |
|
281 <a href="../event/basic-example.html">Simple DOM Events</a> |
|
282 </li> |
|
283 |
|
284 |
|
285 |
|
286 <li data-description="Example Photo Browser application."> |
|
287 <a href="../dd/photo-browser.html">Photo Browser</a> |
|
288 </li> |
|
289 |
|
290 |
|
291 |
|
292 <li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
293 <a href="../dd/portal-drag.html">Portal Style Example</a> |
|
294 </li> |
|
295 |
|
296 |
|
297 |
|
298 <li data-description="Use IO to request XML data from a remote web service."> |
|
299 <a href="../io/weather.html">Request XML data from Yahoo! Weather</a> |
|
300 </li> |
|
301 |
|
302 |
|
303 |
|
304 <li data-description="Use IO to make a cross-domain request to Yahoo! Pipes, returning data from disparate sources."> |
|
305 <a href="../io/xdr.html">Request JSON using Yahoo! Pipes</a> |
|
306 </li> |
|
307 |
|
308 |
|
309 </ul> |
|
310 </div> |
|
311 </div> |
|
312 |
|
313 </div> |
|
314 </div> |
|
315 </div> |
|
316 </div> |
|
317 |
|
318 <script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
319 <script>prettyPrint();</script> |
|
320 |
|
321 <script> |
|
322 YUI.Env.Tests = { |
|
323 examples: [], |
|
324 project: '../assets', |
|
325 assets: '../assets/node', |
|
326 name: 'node-view', |
|
327 title: 'Showing and Hiding', |
|
328 newWindow: '', |
|
329 auto: false |
|
330 }; |
|
331 YUI.Env.Tests.examples.push('properties'); |
|
332 YUI.Env.Tests.examples.push('dom-node'); |
|
333 YUI.Env.Tests.examples.push('store'); |
|
334 YUI.Env.Tests.examples.push('events'); |
|
335 YUI.Env.Tests.examples.push('nodelist'); |
|
336 YUI.Env.Tests.examples.push('ducks'); |
|
337 YUI.Env.Tests.examples.push('node-evt-delegation'); |
|
338 YUI.Env.Tests.examples.push('node-xy'); |
|
339 YUI.Env.Tests.examples.push('node-style'); |
|
340 YUI.Env.Tests.examples.push('node-insert'); |
|
341 YUI.Env.Tests.examples.push('node-view'); |
|
342 YUI.Env.Tests.examples.push('node-focusmanager-toolbar'); |
|
343 YUI.Env.Tests.examples.push('node-focusmanager-button'); |
|
344 YUI.Env.Tests.examples.push('basic-example'); |
|
345 YUI.Env.Tests.examples.push('photo-browser'); |
|
346 YUI.Env.Tests.examples.push('portal-drag'); |
|
347 YUI.Env.Tests.examples.push('weather'); |
|
348 YUI.Env.Tests.examples.push('xdr'); |
|
349 |
|
350 </script> |
|
351 <script src="../assets/yui/test-runner.js"></script> |
|
352 |
|
353 |
|
354 |
|
355 </body> |
|
356 </html> |