diff -r 322d0feea350 -r 89ef5ed3c48b src/cm/media/js/lib/yui/yui_3.10.3/docs/node/dom-node.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/media/js/lib/yui/yui_3.10.3/docs/node/dom-node.html Tue Jul 16 14:29:46 2013 +0200 @@ -0,0 +1,378 @@ + + + + + Example: DOM Methods + + + + + + + + + + +
+
+

+
+ + +

Example: DOM Methods

+
+
+
+
+ +
+

Click any of the blue boxes to copy to the other stack.

+

Click a box in the other stack to remove it completely.

+
+ +
+ +
    +
  • Dog
  • +
  • Cat
  • +
  • Fish
  • +
  • Bird
  • +
+ +
    +
  • Wheelbarrow
  • +
  • Ice Cream Cone
  • +
+ + + +
+ +

Setting up the HTML

+

First we need some HTML to work with.

+
<ul id="demo">
+    <li>Dog</li>
+    <li>Cat</li>
+    <li>Fish</li>
+    <li>Bird</li>
+</ul>
+
+<ul id="demo2">
+    <li>Wheelbarrow</li>
+    <li>Ice Cream Cone</li>
+</ul>
+ +

Using DOM Methods

+

Most common DOM methods are available via Node instances. These can be used to add, remove, and retrieve other nodes.

+
clone = item.cloneNode(true);
+list2.append(clone);
+item.remove(); // sugar for item.get('parentNode').removeChild(item);
+ + +

Complete Example Source

+
<style>
+.example ul {
+    vertical-align: top;
+}
+</style>
+<ul id="demo">
+    <li>Dog</li>
+    <li>Cat</li>
+    <li>Fish</li>
+    <li>Bird</li>
+</ul>
+
+<ul id="demo2">
+    <li>Wheelbarrow</li>
+    <li>Ice Cream Cone</li>
+</ul>
+
+<script type="text/javascript">
+YUI().use('node', function(Y) {
+    var list2 = Y.one('#demo2');
+
+    var onList1Click = function(e) {
+        var item = e.currentTarget;
+
+        if (list2.getStyle('display') === 'none') {
+            list2.show();
+        }
+
+        list2.append(item.cloneNode(true));
+
+    };
+
+    var onList2Click = function(e) {
+        var item = e.currentTarget;
+
+        item.remove(); // sugar for item.get('parentNode').removeChild(item);
+
+        if (list2.all('li').size() < 1) { // hide the list if its empty
+            list2.hide();
+        }
+        
+    };
+
+    Y.one('#demo').delegate('click', onList1Click, 'li');
+    Y.one('#demo2').delegate('click', onList2Click, 'li');
+});
+</script>
+ +
+
+
+ +
+ +
+
+
+ + + + + + + + + + +