src/cm/media/js/lib/yui/yui_3.10.3/docs/node/node-insert.html
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 <!DOCTYPE html>
       
     2 <html lang="en">
       
     3 <head>
       
     4     <meta charset="utf-8">
       
     5     <title>Example: Adding Node Content - Burger Builder</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: Adding Node Content - Burger Builder</h1>
       
    25     <div class="yui3-g">
       
    26         <div class="yui3-u-3-4">
       
    27             <div id="main">
       
    28                 <div class="content"><div class="intro">
       
    29     <p>This example demonstrates how to insert content when working with <code>NodeList</code> instances.</p>
       
    30     <p>Click buttons to build your burger.</p>
       
    31 </div>
       
    32 
       
    33 <div class="example">
       
    34 <style>
       
    35 .example .demo, .example .buttons-list{
       
    36     width: 302px;
       
    37     display: inline-block;
       
    38     zoom: 1;
       
    39     *display: inline;
       
    40     margin: 0;
       
    41     padding: 0;
       
    42     vertical-align: top;
       
    43     text-align: center;        
       
    44 }
       
    45 .example .buttons-list{
       
    46     list-style: none;
       
    47     text-align: left;
       
    48     margin-left: 100px;
       
    49     width: auto;
       
    50     height: 21em;    
       
    51 }
       
    52 .example .buttons-list .yui3-button {
       
    53     margin-bottom: 0.5em;
       
    54 }
       
    55 .example .buttons-list .ketchup{
       
    56     margin-bottom: 1em;
       
    57 }
       
    58 .example .buttons-list .another{
       
    59     display: none;
       
    60 }
       
    61 .example .demo li {
       
    62     position: relative;
       
    63     list-style: none;
       
    64     height: 0;
       
    65     width: 302px;
       
    66     opacity: 0;
       
    67     margin: 0 0 0 -800px;
       
    68     cursor: no-drop;
       
    69     font-size: 1px;
       
    70 }
       
    71 .example .demo li img {
       
    72     position: absolute;
       
    73     top: 0;
       
    74     left: 0;
       
    75 }
       
    76 .example .demo .bun-top, .example .demo .bun-bottom{
       
    77     opacity: 1;
       
    78     height: 106px;
       
    79     margin: 0;
       
    80 }
       
    81 </style>
       
    82     <ul class="demo">
       
    83         <li class="bun-top"><img src="../assets/node/images/burg_bun_top.png" width="271" height="106" alt="Burger bun top"/></li>
       
    84         <li class="bun-bottom"><img src="../assets/node/images/burg_bun_bottom.png" width="291" height="115" alt="Burger bun bottom"/></li>
       
    85     </ul>
       
    86     <ul class="buttons-list">
       
    87         <li><button class='yui3-button patty'> Patty &#183; Before Last Bun</button></li>
       
    88         <li><button class='yui3-button lettuce'> Lettuce &#183; Before Last Bun</button></li>
       
    89         <li><button class='yui3-button cheese' disabled="disabled"> Cheese &#183; Before First Patty</button></li>
       
    90         <li><button class='yui3-button tomato'> Tomato &#183; After First Bun</button></li>
       
    91         <li><button class='yui3-button onions'> Onions &#183; After First Bun</button></li>
       
    92         <li><button class='yui3-button pickles'> Pickles &#183; After First Bun</button></li>
       
    93         <li><button class='yui3-button ketchup'> Ketchup &#183; After First Bun</button></li>
       
    94         <li><button class='yui3-button done'> Done</button></li>
       
    95         <li><button class='yui3-button another'> Another Please</button></li>
       
    96     </ul>
       
    97 <script>
       
    98 YUI().use('node', 'cssbutton', 'transition', 'UA', function (Y) {
       
    99     var demo = Y.one('.demo'),
       
   100         btnList = Y.all('.buttons-list .yui3-button'),
       
   101         i = 0,
       
   102         objList,
       
   103         myZIndex,
       
   104         imgPath = '../assets/node/images/';
       
   105 
       
   106     if (Y.UA.ie && Y.UA.ie < 7) {
       
   107 
       
   108         // Add a prefix to the image file name in the imgPath.
       
   109         // This is needed to work around IE6 non-support of alpha pngs
       
   110         imgPath = imgPath + '8bit_';
       
   111         Y.one('.example .demo .bun-top img').setAttribute('src', imgPath + 'burg_bun_top.png');
       
   112         Y.one('.example .demo .bun-bottom img').setAttribute('src', imgPath + 'burg_bun_bottom.png');
       
   113     }
       
   114 
       
   115     // This smoothes out the visual experience of adding
       
   116     // an element to the burger
       
   117     var transitionObject = function (obj) {
       
   118         obj.transition({
       
   119             duration: 0.8,
       
   120 
       
   121             // height grows from initial 0, to height of contained image
       
   122             height: obj.one('img').getStyle('height'),
       
   123             marginLeft: '0px', // transition into place from offscreen left.
       
   124             opacity: {
       
   125                 delay: 0.2,
       
   126                 duration: 0.5,
       
   127                 value: 1
       
   128             }
       
   129         });
       
   130     }
       
   131 
       
   132     // This removes an element of the burger
       
   133     // the height transitions to 0, it moves left, and fades out
       
   134     var removeObject = function(e) {
       
   135         e.currentTarget.transition({
       
   136             duration: 0.8,
       
   137             height: 0,
       
   138             marginLeft: '-400px',
       
   139             opacity: {
       
   140                 delay: 0.2,
       
   141                 duration: 0.5,
       
   142                 value: 0
       
   143             }
       
   144         },
       
   145             // after the transition finishes...
       
   146             function(){
       
   147                 e.currentTarget.remove(); // remove the clicked item from the DOM
       
   148 
       
   149                 // If there's no patty in the burger
       
   150                 if (Y.one('.example .demo').getHTML().indexOf('patty') === -1) {
       
   151                     // Disable the cheese button
       
   152                     // Cheese is inserted before first patty.
       
   153                     // The cheese button will be enabled when there's a patty
       
   154                     Y.one('.buttons-list .cheese')._node.disabled = true;
       
   155                 }
       
   156         });
       
   157     }
       
   158 
       
   159     // This inserts burger parts and manages the display of buttons
       
   160     var buttonClicks = function (e) {
       
   161         var obj;
       
   162         if (this.hasClass('patty')) {
       
   163             // Create a node with an image of the burger part
       
   164             obj = Y.Node.create('<li class="patty"><img src="' + imgPath + 'burg_patty.png" width="268" height="75" alt="Burger patty"/></li>');
       
   165 
       
   166             // Insert it before the bottom bun
       
   167             demo.insert(obj, Y.one('.bun-bottom'));
       
   168 
       
   169             // Smooth out insert with transition
       
   170             transitionObject(obj);
       
   171             
       
   172             // Cheese button becomes available 
       
   173             // only when there's a patty to insert before
       
   174             Y.one('.buttons-list .cheese')._node.disabled = false; 
       
   175         } else if (this.hasClass('lettuce')) {
       
   176             obj = Y.Node.create('<li class="lettuce"><img src="' + imgPath + 'burg_lettuce.png" width="302" height="87" alt="Lettuce"/></li>');
       
   177             demo.insert(obj, Y.one('.bun-bottom'));
       
   178             transitionObject(obj);        
       
   179         } else if (this.hasClass('cheese')) {
       
   180             obj = Y.Node.create('<li class="cheese"><img src="' + imgPath + 'burg_cheese.png" width="274" height="89" alt="Cheese"/></li>');
       
   181             demo.insert(obj, Y.one('.patty'));
       
   182             transitionObject(obj);
       
   183         } else if (this.hasClass('ketchup')) {
       
   184             obj = Y.Node.create('<li class="ketchup"><img src="' + imgPath + 'burg_ketchup.png" width="208" height="66" alt="Ketchup"/></li>');
       
   185             Y.one('.bun-top').insert(obj, 'after');
       
   186             transitionObject(obj);
       
   187         } else if (this.hasClass('pickles')) {
       
   188             obj = Y.Node.create('<li class="pickles"><img src="' + imgPath + 'burg_pickles.png" width="236" height="61" alt="Pickles"/></li>');
       
   189             Y.one('.bun-top').insert(obj, 'after');
       
   190             transitionObject(obj);
       
   191         } else if (this.hasClass('onions')) {
       
   192             obj = Y.Node.create('<li class="onions"><img src="' + imgPath + 'burg_onions.png" width="248" height="77" alt="Onions"/></li>');
       
   193             Y.one('.bun-top').insert(obj, 'after');
       
   194             transitionObject(obj);
       
   195         } else if (this.hasClass('tomato')) {
       
   196             obj = Y.Node.create('<li class="tomato"><img src="' + imgPath + 'burg_tomato.png" width="225" height="68" alt="Tomato slice"/></li>');
       
   197             Y.one('.bun-top').insert(obj, 'after');
       
   198             transitionObject(obj);
       
   199         } else if (this.hasClass('done')) {
       
   200             objList = Y.all('.demo li');
       
   201             myZIndex = objList.size();  // for resetting z-index of burger parts
       
   202             
       
   203             // Hide all the buttons when done
       
   204             btnList.setStyle('display', 'none');
       
   205             
       
   206             // Show the "Another Please" button
       
   207             Y.one('.buttons-list .another').setStyle('display', 'block');
       
   208 
       
   209             // The normal z-index of <li>s in a <ul> results in the
       
   210             // bottom of the bun picture being on top
       
   211             // The z-index of the burger elements must be reversed.
       
   212             for (i = 0; i < objList.size(); i += 1) {
       
   213                 objList.item(i).setStyle('zIndex', myZIndex);
       
   214                 myZIndex -= 1;
       
   215                 objList.item(i).setStyle('position', 'relative');
       
   216                 // transition the height of the elements proportionally smaller
       
   217                 // so you could get your mouth around it
       
   218                 objList.item(i).transition({
       
   219                     duration: 0.5,
       
   220                     height: parseInt(objList.item(i).one('img').getStyle('height'), 10) * 0.15 + 'px'
       
   221                 });
       
   222             }    
       
   223         } else if (this.hasClass('another')) {
       
   224             // Empty out the content of the burger image
       
   225             demo.setContent('');
       
   226 
       
   227             // Insert just the buns
       
   228             demo.append('<li class="bun-top"><img src="' + imgPath + 'burg_bun_top.png" width="271" height="106" alt="Burger bun top"/></li>');
       
   229             demo.append('<li class="bun-bottom"><img src="' + imgPath + 'burg_bun_bottom.png" width="291" height="115" alt="Burger bun bottom"/></li>');
       
   230 
       
   231             // Disable the cheese button
       
   232             // Cheese is inserted before first patty.
       
   233             // The cheese button will be enabled when there's a patty
       
   234             Y.one('.buttons-list .cheese')._node.disabled = true;
       
   235 
       
   236             // Display all the buttons except the "Another Please"
       
   237             btnList.setStyle('display', 'block');
       
   238             Y.one('.buttons-list .another').setStyle('display', 'none');
       
   239         }
       
   240     }
       
   241     Y.on('click', buttonClicks, '.example .buttons-list .yui3-button');
       
   242     Y.one('.example .demo').delegate('click', removeObject, 'li');
       
   243 });
       
   244 </script>
       
   245 
       
   246 </div>
       
   247 
       
   248 <h2>Setting up the NodeList</h2>
       
   249 <p>First we need some HTML to work with.</p>
       
   250 <pre class="code prettyprint">&lt;ul class=&quot;demo&quot;&gt;
       
   251     &lt;li class=&quot;bun-top&quot;&gt;&lt;img src=&quot;assets&#x2F;images&#x2F;bun_top.png&quot;&#x2F;&gt;&lt;&#x2F;li&gt;
       
   252     &lt;li class=&quot;bun-bottom&quot;&gt;&lt;img src=&quot;assets&#x2F;images&#x2F;bun_bottom.png&quot;&#x2F;&gt;&lt;&#x2F;li&gt;
       
   253 &lt;&#x2F;ul&gt;</pre>
       
   254 
       
   255 <p>Next we'll add some buttons to be clicked.</p>
       
   256 <pre class="code prettyprint">&lt;ul class=&quot;buttons-list&quot;&gt;
       
   257     &lt;li&gt;&lt;button class=&#x27;yui3-button patty&#x27;&gt; Patty &amp;#183; Before Last Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   258     &lt;li&gt;&lt;button class=&#x27;yui3-button lettuce&#x27;&gt; Lettuce &amp;#183; Before Last Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   259     &lt;li&gt;&lt;button class=&#x27;yui3-button cheese&#x27; disabled=&quot;disabled&quot;&gt; Cheese &amp;#183; Before First Patty&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   260     &lt;li&gt;&lt;button class=&#x27;yui3-button tomato&#x27;&gt; Tomato &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   261     &lt;li&gt;&lt;button class=&#x27;yui3-button onions&#x27;&gt; Onions &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   262     &lt;li&gt;&lt;button class=&#x27;yui3-button pickles&#x27;&gt; Pickles &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   263     &lt;li&gt;&lt;button class=&#x27;yui3-button ketchup&#x27;&gt; Ketchup &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   264     &lt;li&gt;&lt;button class=&#x27;yui3-button done&#x27;&gt; Done&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   265     &lt;li&gt;&lt;button class=&#x27;yui3-button another&#x27;&gt; Another Please&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   266 &lt;&#x2F;ul&gt;</pre>
       
   267 
       
   268 <h2>Adding Content</h2>
       
   269 <p>After defining some <code>var</code>s, we'll
       
   270 add a <code>buttonClicks</code> handler to run when an event is fired.
       
   271 It will add content to the <code>demo</code> node.</p>
       
   272 <p>Note that the <code>this</code> in the handler is the object that was clicked.</p>
       
   273 <pre class="code prettyprint">var demo = Y.one(&#x27;.demo&#x27;),
       
   274     btnList = Y.all(&#x27;.buttons-list .yui3-button&#x27;),
       
   275     ...;
       
   276 
       
   277     &#x2F;&#x2F; This inserts burger parts and manages the display of buttons
       
   278     var buttonClicks = function (e) {
       
   279         var obj;
       
   280         if (this.hasClass(&#x27;patty&#x27;)) {
       
   281             &#x2F;&#x2F; Create a node with an image of the burger part
       
   282             obj = Y.Node.create(&#x27;&lt;li class=&quot;patty&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_patty.png&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   283 
       
   284             &#x2F;&#x2F; Insert it before the bottom bun
       
   285             demo.insert(obj, Y.one(&#x27;.bun-bottom&#x27;));
       
   286 
       
   287             &#x2F;&#x2F; ...
       
   288         } else if &#x2F;&#x2F; other buttons follow...</pre>
       
   289 
       
   290 <p>The handler inserts different objects into the <code>demo</code> container object 
       
   291 in different places based on these methods:
       
   292 <ul>
       
   293     <li><code>prepend</code> - as firstChild</li>
       
   294     <li><code>append</code> - as lastChild</li>
       
   295     <li><code>insert</code> - before a specified node or childNode index</li>
       
   296 </ul> 
       
   297 </p>
       
   298 
       
   299 <h2>Attaching Events</h2>
       
   300 <p>We assign our handler to all of the <code>yui3-button</code> objects through
       
   301 event subscription to the matching selector.</p>
       
   302 <pre class="code prettyprint">Y.on(&#x27;click&#x27;, buttonClicks, &#x27;.example .buttons-list .yui3-button&#x27;);</pre>
       
   303 
       
   304 <h2>Transitions</h2>
       
   305 <p>When an event handler simply inserts an object, it appears instantly, and
       
   306 other DOM objects are rendered in their new locations, which
       
   307 can be a visually jarring experience.
       
   308 </p>
       
   309 <p>
       
   310 In this example, we've added a <code>transitionObject</code> function to smooth things out.
       
   311 Inserted burger elements have an initial CSS <code>height</code> of 0.
       
   312 After each insertion, we call the <code>transitionObject</code> function,
       
   313 passing the inserted object. It begins growing to a height equal to the image
       
   314 it contains (the images are different heights). This gradually pushes open a space
       
   315 for itself, while it moves in from offscreen left, and fades in.
       
   316 </p>
       
   317 <pre class="code prettyprint">var transitionObject = function (obj) {
       
   318     obj.transition({
       
   319         duration: 0.8,
       
   320 
       
   321         &#x2F;&#x2F; height grows from initial 0, to height of contained image
       
   322         height: obj.one(&#x27;img&#x27;).getStyle(&#x27;height&#x27;),
       
   323         marginLeft: &#x27;0px&#x27;, &#x2F;&#x2F; transition into place from offscreen left.
       
   324         opacity: {
       
   325             delay: 0.2,
       
   326             duration: 0.5,
       
   327             value: 1
       
   328         }
       
   329     });
       
   330 }</pre>
       
   331 
       
   332 <p>
       
   333 Here's more code in the <code>buttonClicks</code> handler where we call <code>transitionObject</code>,
       
   334 and do some special handling for the cheese button state.
       
   335 </p>
       
   336 <pre class="code prettyprint">&#x2F;&#x2F; This inserts burger parts and manages the display of buttons
       
   337 var buttonClicks = function (e) {
       
   338     var obj;
       
   339     if (this.hasClass(&#x27;patty&#x27;)) {
       
   340         &#x2F;&#x2F; Create a node with an image of the burger part
       
   341         obj = Y.Node.create(&#x27;&lt;li class=&quot;patty&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_patty.png&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   342 
       
   343         &#x2F;&#x2F; Insert it before the bottom bun
       
   344         demo.insert(obj, Y.one(&#x27;.bun-bottom&#x27;));
       
   345 
       
   346         &#x2F;&#x2F; Smooth out insert with transition
       
   347         transitionObject(obj);
       
   348 
       
   349         &#x2F;&#x2F; Cheese button becomes available
       
   350         &#x2F;&#x2F; only when there&#x27;s a patty to insert before
       
   351         Y.one(&#x27;.buttons-list .cheese&#x27;)._node.disabled = false;
       
   352     } else if &#x2F;&#x2F; other buttons follow...</pre>
       
   353 
       
   354 <h2>Complete Example Source</h2>
       
   355 <p>
       
   356 In the complete source you'll see we also added handling for:
       
   357 <ul>
       
   358 <li>Removing elements from the burger</li>
       
   359 <li>Clicking the Done button to vertically compress the burger</li>
       
   360 <li>Requesting another</li>
       
   361 </ul>
       
   362 </p>
       
   363 <pre class="code prettyprint">&lt;style&gt;
       
   364 .example .demo, .example .buttons-list{
       
   365     width: 302px;
       
   366     display: inline-block;
       
   367     zoom: 1;
       
   368     *display: inline;
       
   369     margin: 0;
       
   370     padding: 0;
       
   371     vertical-align: top;
       
   372     text-align: center;        
       
   373 }
       
   374 .example .buttons-list{
       
   375     list-style: none;
       
   376     text-align: left;
       
   377     margin-left: 100px;
       
   378     width: auto;
       
   379     height: 21em;    
       
   380 }
       
   381 .example .buttons-list .yui3-button {
       
   382     margin-bottom: 0.5em;
       
   383 }
       
   384 .example .buttons-list .ketchup{
       
   385     margin-bottom: 1em;
       
   386 }
       
   387 .example .buttons-list .another{
       
   388     display: none;
       
   389 }
       
   390 .example .demo li {
       
   391     position: relative;
       
   392     list-style: none;
       
   393     height: 0;
       
   394     width: 302px;
       
   395     opacity: 0;
       
   396     margin: 0 0 0 -800px;
       
   397     cursor: no-drop;
       
   398     font-size: 1px;
       
   399 }
       
   400 .example .demo li img {
       
   401     position: absolute;
       
   402     top: 0;
       
   403     left: 0;
       
   404 }
       
   405 .example .demo .bun-top, .example .demo .bun-bottom{
       
   406     opacity: 1;
       
   407     height: 106px;
       
   408     margin: 0;
       
   409 }
       
   410 &lt;&#x2F;style&gt;
       
   411     &lt;ul class=&quot;demo&quot;&gt;
       
   412         &lt;li class=&quot;bun-top&quot;&gt;&lt;img src=&quot;..&#x2F;assets&#x2F;node&#x2F;images&#x2F;burg_bun_top.png&quot; width=&quot;271&quot; height=&quot;106&quot; alt=&quot;Burger bun top&quot;&#x2F;&gt;&lt;&#x2F;li&gt;
       
   413         &lt;li class=&quot;bun-bottom&quot;&gt;&lt;img src=&quot;..&#x2F;assets&#x2F;node&#x2F;images&#x2F;burg_bun_bottom.png&quot; width=&quot;291&quot; height=&quot;115&quot; alt=&quot;Burger bun bottom&quot;&#x2F;&gt;&lt;&#x2F;li&gt;
       
   414     &lt;&#x2F;ul&gt;
       
   415     &lt;ul class=&quot;buttons-list&quot;&gt;
       
   416         &lt;li&gt;&lt;button class=&#x27;yui3-button patty&#x27;&gt; Patty &amp;#183; Before Last Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   417         &lt;li&gt;&lt;button class=&#x27;yui3-button lettuce&#x27;&gt; Lettuce &amp;#183; Before Last Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   418         &lt;li&gt;&lt;button class=&#x27;yui3-button cheese&#x27; disabled=&quot;disabled&quot;&gt; Cheese &amp;#183; Before First Patty&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   419         &lt;li&gt;&lt;button class=&#x27;yui3-button tomato&#x27;&gt; Tomato &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   420         &lt;li&gt;&lt;button class=&#x27;yui3-button onions&#x27;&gt; Onions &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   421         &lt;li&gt;&lt;button class=&#x27;yui3-button pickles&#x27;&gt; Pickles &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   422         &lt;li&gt;&lt;button class=&#x27;yui3-button ketchup&#x27;&gt; Ketchup &amp;#183; After First Bun&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   423         &lt;li&gt;&lt;button class=&#x27;yui3-button done&#x27;&gt; Done&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   424         &lt;li&gt;&lt;button class=&#x27;yui3-button another&#x27;&gt; Another Please&lt;&#x2F;button&gt;&lt;&#x2F;li&gt;
       
   425     &lt;&#x2F;ul&gt;
       
   426 &lt;script&gt;
       
   427 YUI().use(&#x27;node&#x27;, &#x27;cssbutton&#x27;, &#x27;transition&#x27;, &#x27;UA&#x27;, function (Y) {
       
   428     var demo = Y.one(&#x27;.demo&#x27;),
       
   429         btnList = Y.all(&#x27;.buttons-list .yui3-button&#x27;),
       
   430         i = 0,
       
   431         objList,
       
   432         myZIndex,
       
   433         imgPath = &#x27;..&#x2F;assets&#x2F;node&#x2F;images&#x2F;&#x27;;
       
   434 
       
   435     if (Y.UA.ie &amp;&amp; Y.UA.ie &lt; 7) {
       
   436 
       
   437         &#x2F;&#x2F; Add a prefix to the image file name in the imgPath.
       
   438         &#x2F;&#x2F; This is needed to work around IE6 non-support of alpha pngs
       
   439         imgPath = imgPath + &#x27;8bit_&#x27;;
       
   440         Y.one(&#x27;.example .demo .bun-top img&#x27;).setAttribute(&#x27;src&#x27;, imgPath + &#x27;burg_bun_top.png&#x27;);
       
   441         Y.one(&#x27;.example .demo .bun-bottom img&#x27;).setAttribute(&#x27;src&#x27;, imgPath + &#x27;burg_bun_bottom.png&#x27;);
       
   442     }
       
   443 
       
   444     &#x2F;&#x2F; This smoothes out the visual experience of adding
       
   445     &#x2F;&#x2F; an element to the burger
       
   446     var transitionObject = function (obj) {
       
   447         obj.transition({
       
   448             duration: 0.8,
       
   449 
       
   450             &#x2F;&#x2F; height grows from initial 0, to height of contained image
       
   451             height: obj.one(&#x27;img&#x27;).getStyle(&#x27;height&#x27;),
       
   452             marginLeft: &#x27;0px&#x27;, &#x2F;&#x2F; transition into place from offscreen left.
       
   453             opacity: {
       
   454                 delay: 0.2,
       
   455                 duration: 0.5,
       
   456                 value: 1
       
   457             }
       
   458         });
       
   459     }
       
   460 
       
   461     &#x2F;&#x2F; This removes an element of the burger
       
   462     &#x2F;&#x2F; the height transitions to 0, it moves left, and fades out
       
   463     var removeObject = function(e) {
       
   464         e.currentTarget.transition({
       
   465             duration: 0.8,
       
   466             height: 0,
       
   467             marginLeft: &#x27;-400px&#x27;,
       
   468             opacity: {
       
   469                 delay: 0.2,
       
   470                 duration: 0.5,
       
   471                 value: 0
       
   472             }
       
   473         },
       
   474             &#x2F;&#x2F; after the transition finishes...
       
   475             function(){
       
   476                 e.currentTarget.remove(); &#x2F;&#x2F; remove the clicked item from the DOM
       
   477 
       
   478                 &#x2F;&#x2F; If there&#x27;s no patty in the burger
       
   479                 if (Y.one(&#x27;.example .demo&#x27;).getHTML().indexOf(&#x27;patty&#x27;) === -1) {
       
   480                     &#x2F;&#x2F; Disable the cheese button
       
   481                     &#x2F;&#x2F; Cheese is inserted before first patty.
       
   482                     &#x2F;&#x2F; The cheese button will be enabled when there&#x27;s a patty
       
   483                     Y.one(&#x27;.buttons-list .cheese&#x27;)._node.disabled = true;
       
   484                 }
       
   485         });
       
   486     }
       
   487 
       
   488     &#x2F;&#x2F; This inserts burger parts and manages the display of buttons
       
   489     var buttonClicks = function (e) {
       
   490         var obj;
       
   491         if (this.hasClass(&#x27;patty&#x27;)) {
       
   492             &#x2F;&#x2F; Create a node with an image of the burger part
       
   493             obj = Y.Node.create(&#x27;&lt;li class=&quot;patty&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_patty.png&quot; width=&quot;268&quot; height=&quot;75&quot; alt=&quot;Burger patty&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   494 
       
   495             &#x2F;&#x2F; Insert it before the bottom bun
       
   496             demo.insert(obj, Y.one(&#x27;.bun-bottom&#x27;));
       
   497 
       
   498             &#x2F;&#x2F; Smooth out insert with transition
       
   499             transitionObject(obj);
       
   500             
       
   501             &#x2F;&#x2F; Cheese button becomes available 
       
   502             &#x2F;&#x2F; only when there&#x27;s a patty to insert before
       
   503             Y.one(&#x27;.buttons-list .cheese&#x27;)._node.disabled = false; 
       
   504         } else if (this.hasClass(&#x27;lettuce&#x27;)) {
       
   505             obj = Y.Node.create(&#x27;&lt;li class=&quot;lettuce&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_lettuce.png&quot; width=&quot;302&quot; height=&quot;87&quot; alt=&quot;Lettuce&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   506             demo.insert(obj, Y.one(&#x27;.bun-bottom&#x27;));
       
   507             transitionObject(obj);        
       
   508         } else if (this.hasClass(&#x27;cheese&#x27;)) {
       
   509             obj = Y.Node.create(&#x27;&lt;li class=&quot;cheese&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_cheese.png&quot; width=&quot;274&quot; height=&quot;89&quot; alt=&quot;Cheese&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   510             demo.insert(obj, Y.one(&#x27;.patty&#x27;));
       
   511             transitionObject(obj);
       
   512         } else if (this.hasClass(&#x27;ketchup&#x27;)) {
       
   513             obj = Y.Node.create(&#x27;&lt;li class=&quot;ketchup&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_ketchup.png&quot; width=&quot;208&quot; height=&quot;66&quot; alt=&quot;Ketchup&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   514             Y.one(&#x27;.bun-top&#x27;).insert(obj, &#x27;after&#x27;);
       
   515             transitionObject(obj);
       
   516         } else if (this.hasClass(&#x27;pickles&#x27;)) {
       
   517             obj = Y.Node.create(&#x27;&lt;li class=&quot;pickles&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_pickles.png&quot; width=&quot;236&quot; height=&quot;61&quot; alt=&quot;Pickles&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   518             Y.one(&#x27;.bun-top&#x27;).insert(obj, &#x27;after&#x27;);
       
   519             transitionObject(obj);
       
   520         } else if (this.hasClass(&#x27;onions&#x27;)) {
       
   521             obj = Y.Node.create(&#x27;&lt;li class=&quot;onions&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_onions.png&quot; width=&quot;248&quot; height=&quot;77&quot; alt=&quot;Onions&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   522             Y.one(&#x27;.bun-top&#x27;).insert(obj, &#x27;after&#x27;);
       
   523             transitionObject(obj);
       
   524         } else if (this.hasClass(&#x27;tomato&#x27;)) {
       
   525             obj = Y.Node.create(&#x27;&lt;li class=&quot;tomato&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_tomato.png&quot; width=&quot;225&quot; height=&quot;68&quot; alt=&quot;Tomato slice&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   526             Y.one(&#x27;.bun-top&#x27;).insert(obj, &#x27;after&#x27;);
       
   527             transitionObject(obj);
       
   528         } else if (this.hasClass(&#x27;done&#x27;)) {
       
   529             objList = Y.all(&#x27;.demo li&#x27;);
       
   530             myZIndex = objList.size();  &#x2F;&#x2F; for resetting z-index of burger parts
       
   531             
       
   532             &#x2F;&#x2F; Hide all the buttons when done
       
   533             btnList.setStyle(&#x27;display&#x27;, &#x27;none&#x27;);
       
   534             
       
   535             &#x2F;&#x2F; Show the &quot;Another Please&quot; button
       
   536             Y.one(&#x27;.buttons-list .another&#x27;).setStyle(&#x27;display&#x27;, &#x27;block&#x27;);
       
   537 
       
   538             &#x2F;&#x2F; The normal z-index of &lt;li&gt;s in a &lt;ul&gt; results in the
       
   539             &#x2F;&#x2F; bottom of the bun picture being on top
       
   540             &#x2F;&#x2F; The z-index of the burger elements must be reversed.
       
   541             for (i = 0; i &lt; objList.size(); i += 1) {
       
   542                 objList.item(i).setStyle(&#x27;zIndex&#x27;, myZIndex);
       
   543                 myZIndex -= 1;
       
   544                 objList.item(i).setStyle(&#x27;position&#x27;, &#x27;relative&#x27;);
       
   545                 &#x2F;&#x2F; transition the height of the elements proportionally smaller
       
   546                 &#x2F;&#x2F; so you could get your mouth around it
       
   547                 objList.item(i).transition({
       
   548                     duration: 0.5,
       
   549                     height: parseInt(objList.item(i).one(&#x27;img&#x27;).getStyle(&#x27;height&#x27;), 10) * 0.15 + &#x27;px&#x27;
       
   550                 });
       
   551             }    
       
   552         } else if (this.hasClass(&#x27;another&#x27;)) {
       
   553             &#x2F;&#x2F; Empty out the content of the burger image
       
   554             demo.setContent(&#x27;&#x27;);
       
   555 
       
   556             &#x2F;&#x2F; Insert just the buns
       
   557             demo.append(&#x27;&lt;li class=&quot;bun-top&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_bun_top.png&quot; width=&quot;271&quot; height=&quot;106&quot; alt=&quot;Burger bun top&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   558             demo.append(&#x27;&lt;li class=&quot;bun-bottom&quot;&gt;&lt;img src=&quot;&#x27; + imgPath + &#x27;burg_bun_bottom.png&quot; width=&quot;291&quot; height=&quot;115&quot; alt=&quot;Burger bun bottom&quot;&#x2F;&gt;&lt;&#x2F;li&gt;&#x27;);
       
   559 
       
   560             &#x2F;&#x2F; Disable the cheese button
       
   561             &#x2F;&#x2F; Cheese is inserted before first patty.
       
   562             &#x2F;&#x2F; The cheese button will be enabled when there&#x27;s a patty
       
   563             Y.one(&#x27;.buttons-list .cheese&#x27;)._node.disabled = true;
       
   564 
       
   565             &#x2F;&#x2F; Display all the buttons except the &quot;Another Please&quot;
       
   566             btnList.setStyle(&#x27;display&#x27;, &#x27;block&#x27;);
       
   567             Y.one(&#x27;.buttons-list .another&#x27;).setStyle(&#x27;display&#x27;, &#x27;none&#x27;);
       
   568         }
       
   569     }
       
   570     Y.on(&#x27;click&#x27;, buttonClicks, &#x27;.example .buttons-list .yui3-button&#x27;);
       
   571     Y.one(&#x27;.example .demo&#x27;).delegate(&#x27;click&#x27;, removeObject, &#x27;li&#x27;);
       
   572 });
       
   573 &lt;&#x2F;script&gt;</pre>
       
   574 
       
   575 </div>
       
   576             </div>
       
   577         </div>
       
   578 
       
   579         <div class="yui3-u-1-4">
       
   580             <div class="sidebar">
       
   581                 
       
   582 
       
   583                 
       
   584                     <div class="sidebox">
       
   585                         <div class="hd">
       
   586                             <h2 class="no-toc">Examples</h2>
       
   587                         </div>
       
   588 
       
   589                         <div class="bd">
       
   590                             <ul class="examples">
       
   591                                 
       
   592                                     
       
   593                                         <li data-description="Using selectors and property accessors with Node.">
       
   594                                             <a href="properties.html">Set and Get Properties</a>
       
   595                                         </li>
       
   596                                     
       
   597                                 
       
   598                                     
       
   599                                         <li data-description="Using DOM methods with Node.">
       
   600                                             <a href="dom-node.html">DOM Methods</a>
       
   601                                         </li>
       
   602                                     
       
   603                                 
       
   604                                     
       
   605                                         <li data-description="Building a simple store and shopping cart.">
       
   606                                             <a href="store.html">DOM Methods - Store</a>
       
   607                                         </li>
       
   608                                     
       
   609                                 
       
   610                                     
       
   611                                         <li data-description="Listening for DOM events with Node instances.">
       
   612                                             <a href="events.html">Handling DOM Events</a>
       
   613                                         </li>
       
   614                                     
       
   615                                 
       
   616                                     
       
   617                                         <li data-description="NodeList provides Node functionality for manipulating multiple nodes at once.">
       
   618                                             <a href="nodelist.html">Using NodeList - Simple</a>
       
   619                                         </li>
       
   620                                     
       
   621                                 
       
   622                                     
       
   623                                         <li data-description="How to use multiple NodeList features to build a simple game.">
       
   624                                             <a href="ducks.html">Using NodeList - Ducks Game</a>
       
   625                                         </li>
       
   626                                     
       
   627                                 
       
   628                                     
       
   629                                         <li data-description="Using a single event listener to handle events on multiple nodes.">
       
   630                                             <a href="node-evt-delegation.html">Delegating Node Events</a>
       
   631                                         </li>
       
   632                                     
       
   633                                 
       
   634                                     
       
   635                                         <li data-description="This example demonstrates how to position an element in page coordinates.">
       
   636                                             <a href="node-xy.html">Node Positioning</a>
       
   637                                         </li>
       
   638                                     
       
   639                                 
       
   640                                     
       
   641                                         <li data-description="This example demonstrates how to set styles and get style information.">
       
   642                                             <a href="node-style.html">Node Styling</a>
       
   643                                         </li>
       
   644                                     
       
   645                                 
       
   646                                     
       
   647                                         <li data-description="This example demonstrates how to insert content into a Node.">
       
   648                                             <a href="node-insert.html">Adding Node Content - Burger Builder</a>
       
   649                                         </li>
       
   650                                     
       
   651                                 
       
   652                                     
       
   653                                         <li data-description="This example demonstrates how to show and hide a Node.">
       
   654                                             <a href="node-view.html">Showing and Hiding</a>
       
   655                                         </li>
       
   656                                     
       
   657                                 
       
   658                                     
       
   659                                 
       
   660                                     
       
   661                                 
       
   662                                     
       
   663                                 
       
   664                                     
       
   665                                 
       
   666                                     
       
   667                                 
       
   668                                     
       
   669                                 
       
   670                                     
       
   671                                 
       
   672                             </ul>
       
   673                         </div>
       
   674                     </div>
       
   675                 
       
   676 
       
   677                 
       
   678                     <div class="sidebox">
       
   679                         <div class="hd">
       
   680                             <h2 class="no-toc">Examples That Use This Component</h2>
       
   681                         </div>
       
   682 
       
   683                         <div class="bd">
       
   684                             <ul class="examples">
       
   685                                 
       
   686                                     
       
   687                                 
       
   688                                     
       
   689                                 
       
   690                                     
       
   691                                 
       
   692                                     
       
   693                                 
       
   694                                     
       
   695                                 
       
   696                                     
       
   697                                 
       
   698                                     
       
   699                                 
       
   700                                     
       
   701                                 
       
   702                                     
       
   703                                 
       
   704                                     
       
   705                                 
       
   706                                     
       
   707                                 
       
   708                                     
       
   709                                         <li data-description="Creating an accessible toolbar using the Focus Manager Node Plugin and Node&#x27;s support for the WAI-ARIA Roles and States.">
       
   710                                             <a href="../node-focusmanager/node-focusmanager-toolbar.html">Accessible Toolbar</a>
       
   711                                         </li>
       
   712                                     
       
   713                                 
       
   714                                     
       
   715                                         <li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event&#x27;s delegation support and mouseenter event, along with the Overlay widget and Node&#x27;s support for the WAI-ARIA Roles and States.">
       
   716                                             <a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a>
       
   717                                         </li>
       
   718                                     
       
   719                                 
       
   720                                     
       
   721                                         <li data-description="Use the Event Utility to attach simple DOM event handlers.">
       
   722                                             <a href="../event/basic-example.html">Simple DOM Events</a>
       
   723                                         </li>
       
   724                                     
       
   725                                 
       
   726                                     
       
   727                                         <li data-description="Example Photo Browser application.">
       
   728                                             <a href="../dd/photo-browser.html">Photo Browser</a>
       
   729                                         </li>
       
   730                                     
       
   731                                 
       
   732                                     
       
   733                                         <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
       
   734                                             <a href="../dd/portal-drag.html">Portal Style Example</a>
       
   735                                         </li>
       
   736                                     
       
   737                                 
       
   738                                     
       
   739                                         <li data-description="Use IO to request XML data from a remote web service.">
       
   740                                             <a href="../io/weather.html">Request XML data from Yahoo! Weather</a>
       
   741                                         </li>
       
   742                                     
       
   743                                 
       
   744                                     
       
   745                                         <li data-description="Use IO to make a cross-domain request to Yahoo! Pipes, returning data from disparate sources.">
       
   746                                             <a href="../io/xdr.html">Request JSON using Yahoo! Pipes</a>
       
   747                                         </li>
       
   748                                     
       
   749                                 
       
   750                             </ul>
       
   751                         </div>
       
   752                     </div>
       
   753                 
       
   754             </div>
       
   755         </div>
       
   756     </div>
       
   757 </div>
       
   758 
       
   759 <script src="../assets/vendor/prettify/prettify-min.js"></script>
       
   760 <script>prettyPrint();</script>
       
   761 
       
   762 <script>
       
   763 YUI.Env.Tests = {
       
   764     examples: [],
       
   765     project: '../assets',
       
   766     assets: '../assets/node',
       
   767     name: 'node-insert',
       
   768     title: 'Adding Node Content - Burger Builder',
       
   769     newWindow: '',
       
   770     auto:  false 
       
   771 };
       
   772 YUI.Env.Tests.examples.push('properties');
       
   773 YUI.Env.Tests.examples.push('dom-node');
       
   774 YUI.Env.Tests.examples.push('store');
       
   775 YUI.Env.Tests.examples.push('events');
       
   776 YUI.Env.Tests.examples.push('nodelist');
       
   777 YUI.Env.Tests.examples.push('ducks');
       
   778 YUI.Env.Tests.examples.push('node-evt-delegation');
       
   779 YUI.Env.Tests.examples.push('node-xy');
       
   780 YUI.Env.Tests.examples.push('node-style');
       
   781 YUI.Env.Tests.examples.push('node-insert');
       
   782 YUI.Env.Tests.examples.push('node-view');
       
   783 YUI.Env.Tests.examples.push('node-focusmanager-toolbar');
       
   784 YUI.Env.Tests.examples.push('node-focusmanager-button');
       
   785 YUI.Env.Tests.examples.push('basic-example');
       
   786 YUI.Env.Tests.examples.push('photo-browser');
       
   787 YUI.Env.Tests.examples.push('portal-drag');
       
   788 YUI.Env.Tests.examples.push('weather');
       
   789 YUI.Env.Tests.examples.push('xdr');
       
   790 
       
   791 </script>
       
   792 <script src="../assets/yui/test-runner.js"></script>
       
   793 
       
   794 
       
   795 
       
   796 </body>
       
   797 </html>