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