~bcsaller/juju-gui/charmFind

« back to all changes in this revision

Viewing changes to lib/yui/docs/widget/widget-parentchild-listbox.html

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Example: Creating a Hierarchical ListBox Widget</title>
6
 
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
 
    <link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
 
    <link rel="stylesheet" href="../assets/css/main.css">
9
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
 
    <script src="../../build/yui/yui-min.js"></script>
11
 
</head>
12
 
<body>
13
 
 
14
 
<div id="doc">
15
 
    <h1>Example: Creating a Hierarchical ListBox Widget</h1>
16
 
 
17
 
    
18
 
 
19
 
    <div class="yui3-g">
20
 
        <div class="yui3-u-3-4">
21
 
            <div id="main">
22
 
                <div class="content"><style type="text/css" scoped>
23
 
 
24
 
    #mylistbox em {
25
 
        font-style:normal;
26
 
    }
27
 
 
28
 
    #selected {
29
 
        border:1px solid #aaa;
30
 
        padding:2px;
31
 
        width:15em;
32
 
    }
33
 
 
34
 
    .yui3-listbox {
35
 
        padding:0;       
36
 
        margin: .25em;
37
 
        border: solid 1px #000;
38
 
        background-color:#fff;
39
 
        white-space:nowrap;
40
 
    }
41
 
 
42
 
    .yui3-listbox .yui3-listbox {
43
 
        margin-top: .25em;
44
 
        margin-bottom: .25em;
45
 
        border: none;
46
 
    }
47
 
 
48
 
    .yui3-listbox .yui3-option, 
49
 
    .yui3-listbox .yui3-listbox-option {
50
 
        margin:0;
51
 
        padding:0;
52
 
        cursor:default;
53
 
        list-style-image:none;
54
 
        list-style-position:outside;
55
 
        list-style-type:none;
56
 
    }
57
 
 
58
 
    .yui3-option-content,
59
 
    .yui3-listbox-label {
60
 
        display: block;
61
 
        padding: .25em .5em;
62
 
    }
63
 
 
64
 
    .yui3-listbox-content {
65
 
        margin:0;
66
 
        padding:0;
67
 
        overflow:auto;
68
 
    }
69
 
 
70
 
    .yui3-listbox .yui3-listbox .yui3-option-content {
71
 
        margin-left:.5em;
72
 
    }
73
 
 
74
 
    .yui3-listbox-label {
75
 
        font-weight: bold;
76
 
    }
77
 
 
78
 
    .yui3-option-selected {
79
 
        background-color: #cccccc;
80
 
    }
81
 
 
82
 
    .yui3-option-focused {
83
 
        outline: none;
84
 
        background-color: blue;
85
 
        color: #fff;
86
 
    }
87
 
</style>
88
 
 
89
 
<div class="intro">
90
 
    <p>This is an advanced example, in which we create a ListBox widget with nested Option widgets, by extending the base <code>Widget</code> class, and adding <code>WidgetParent</code> and <code>WidgetChild</code> extensions, through <code>Base.build</code>.</p>
91
 
    <p>The <a href="../tabview">TabView</a> component that is included in the YUI 3 library, is also built using the WidgetParent and WidgetChild extensions.</p>
92
 
</div>
93
 
 
94
 
<div class="example">
95
 
    <p id="selected">Selected: <span id="selection">None</span></p>
96
 
 
97
 
<div id="exampleContainer"></div>
98
 
 
99
 
<script type="text/javascript">
100
 
    YUI({ 
101
 
        modules: {
102
 
            "listbox": {
103
 
                fullpath: "../assets/widget/listbox.js",
104
 
                requires: ["substitute", "widget", "widget-parent", "widget-child", "node-focusmanager"]
105
 
            }
106
 
        }
107
 
     }).use("listbox", function (Y) {
108
 
 
109
 
        var listbox = new Y.ListBox({  
110
 
            id:"mylistbox", 
111
 
            width:"13em", 
112
 
            height:"15em", 
113
 
            children: [ 
114
 
                { label: "Item One" },
115
 
                { label: "Item Two" } 
116
 
            ]
117
 
        });
118
 
 
119
 
        listbox.add({ 
120
 
            type: "ListBox", 
121
 
            label: "Item Three", 
122
 
            children: [ 
123
 
                { label: "Item Three - One" },
124
 
                { label: "Item Three - Two" } 
125
 
            ]
126
 
        });
127
 
 
128
 
        listbox.add({ label: "Item Four" });
129
 
 
130
 
        listbox.add(
131
 
            new Y.Option({ label: "Item Five" })
132
 
        );
133
 
 
134
 
        listbox.add({ 
135
 
            type: "ListBox", 
136
 
            label: "Item Six", 
137
 
            children: [ 
138
 
                { label: "Item Six - One" },
139
 
                { label: "Item Six - Two" }
140
 
            ]
141
 
        });
142
 
 
143
 
        listbox.after("selectionChange", function(e) {
144
 
 
145
 
            var selection = this.get("selection");
146
 
            if (selection instanceof Y.ListBox) {
147
 
                selection = selection.get("selection");
148
 
            }
149
 
 
150
 
            if (selection) {
151
 
                Y.one("#selection").setContent(selection.get("label"));
152
 
            }
153
 
        });
154
 
 
155
 
        listbox.render("#exampleContainer");
156
 
    });
157
 
</script>
158
 
</div>
159
 
 
160
 
<h3>The WidgetParent and WidgetChild Extensions</h3>
161
 
 
162
 
<p><a href="http://yuilibrary.com/yui/docs/api/WidgetParent.html">WidgetParent</a> is an extension, designed to be used with <code>Base.build</code> to create a class of Widget which is designed to contain child Widgets (for example a Tree widget, which contains TreeNode children). 
163
 
WidgetParent itself augments <a href="http://yuilibrary.com/yui/docs/api/ArrayList.html">ArrayList</a> providing a convenient set of array iteration and convenience methods, allowing users of your class to easily work with parent's list of children.</p>
164
 
 
165
 
<p><a href="http://yuilibrary.com/yui/docs/api/WidgetChild.html">WidgetChild</a> is also an extension, designed to be used with <code>Base.build</code> to create a class of Widget which is designed to nested inside parent Widgets (for example a TreeNode widget, which sits inside a Tree widget).</p>
166
 
 
167
 
<p>A Widget can be built with both the WidgetParent and WidgetChild extensions (it can be both a Parent and a Child), in cases where we want to support multi-level hierarchies, such as the ListBox example below.</p>
168
 
 
169
 
<p>In addition to providing the basic support to manage (add/remove/iterate/render) children the Widget Parent/Child implementations also provides support for both single and multiple selection models.</p>
170
 
 
171
 
<h3>Using WidgetParent and WidgetChild to Create the ListBox Class</h3>
172
 
 
173
 
<p>For ListBox, since we're creating a new class from scratch, we use the sugar version of <code>Base.build</code>, called <code>Base.create</code>, which allows us to easily create a new class and define it's prototype and static properties/methods, in a single call, as shown below:</p>
174
 
 
175
 
<pre class="code prettyprint">&#x2F;&#x2F; Create a new class, ListBox, which extends Widget, and mixes in both the WidgetParent and WidgetChild 
176
 
&#x2F;&#x2F; extensions since we want to be able to nest one ListBox inside another, to create heirarchical listboxes
177
 
 
178
 
Y.ListBox = Y.Base.create(&quot;listbox&quot;, Y.Widget, [Y.WidgetParent, Y.WidgetChild], {
179
 
        &#x2F;&#x2F; Prototype Properties for ListBox
180
 
    }, {
181
 
        &#x2F;&#x2F; Static Properties for ListBox
182
 
    });</pre>
183
 
 
184
 
 
185
 
<p>We can then go ahead and fill out the prototype and static properties we want to override in our ListBox implementation, while Widget, WidgetParent and WidgetChild provide the basic Widget rendering and parent-child relationship support. Comments inline below provide the background:</p>
186
 
 
187
 
<h4>Prototype Method and Properties</h4>
188
 
 
189
 
<pre class="code prettyprint">Y.ListBox = Y.Base.create(&quot;listbox&quot;, Y.Widget, [Y.WidgetParent, Y.WidgetChild], {
190
 
 
191
 
    &#x2F;&#x2F; The default content box for ListBoxes will be a UL (Widget uses a DIV by default)
192
 
    CONTENT_TEMPLATE : &quot;&lt;ul&gt;&lt;&#x2F;ul&gt;&quot;,
193
 
 
194
 
    &#x2F;&#x2F; Setup Custom Listeners
195
 
    bindUI: function() {
196
 
 
197
 
        if (this.isRoot()) {
198
 
 
199
 
            &#x2F;&#x2F; Setup custom focus handling, using the NodeFocusManager plugin
200
 
            &#x2F;&#x2F; This will help us easily crete next&#x2F;previous item handling using the arrow keys
201
 
        
202
 
            this.get(&quot;boundingBox&quot;).plug(Y.Plugin.NodeFocusManager, {
203
 
                descendants: &quot;.yui3-option&quot;,
204
 
                keys: {
205
 
                    next: &quot;down:40&quot;,    &#x2F;&#x2F; Down arrow
206
 
                    previous: &quot;down:38&quot; &#x2F;&#x2F; Up arrow 
207
 
                },
208
 
                circular: true
209
 
            });
210
 
        }
211
 
 
212
 
        this.get(&quot;boundingBox&quot;).on(&quot;contextmenu&quot;, function (event) {
213
 
            event.preventDefault();
214
 
        });
215
 
 
216
 
        &#x2F;&#x2F; Setup listener to control keyboard based single&#x2F;multiple item selection
217
 
        this.on(&quot;option:keydown&quot;, function (event) {
218
 
 
219
 
            var item = event.target,
220
 
                domEvent = event.domEvent,
221
 
                keyCode = domEvent.keyCode,
222
 
                direction = (keyCode == 40);
223
 
 
224
 
            if (this.get(&quot;multiple&quot;)) {
225
 
                if (keyCode == 40 || keyCode == 38) {
226
 
                    if (domEvent.shiftKey) {
227
 
                        this._selectNextSibling(item, direction);
228
 
                    } else {
229
 
                        this.deselectAll();
230
 
                        this._selectNextSibling(item, direction);
231
 
                    }
232
 
                }
233
 
            } else {
234
 
                if (keyCode == 13 || keyCode == 32) {
235
 
                    domEvent.preventDefault();
236
 
                    item.set(&quot;selected&quot;, 1);
237
 
                }
238
 
            }
239
 
        });
240
 
 
241
 
        &#x2F;&#x2F; Setup listener to control mouse based single&#x2F;multiple item selection
242
 
        this.on(&quot;option:mousedown&quot;, function (event) {
243
 
 
244
 
            var item = event.target,
245
 
                domEvent = event.domEvent,
246
 
                selection;
247
 
 
248
 
            if (this.get(&quot;multiple&quot;)) {
249
 
                if (domEvent.metaKey) {
250
 
                    item.set(&quot;selected&quot;, 1);
251
 
                } else {
252
 
                    this.deselectAll();
253
 
                    item.set(&quot;selected&quot;, 1);
254
 
                }
255
 
            } else {
256
 
                item.set(&quot;selected&quot;, 1);
257
 
            }
258
 
 
259
 
        });
260
 
    },
261
 
 
262
 
    &#x2F;&#x2F; Helper Method, to find the correct next sibling, taking into account nested ListBoxes    
263
 
    _selectNextSibling : function(item, direction) {
264
 
 
265
 
        var parent = item.get(&quot;parent&quot;),
266
 
            method =  (direction) ? &quot;next&quot; : &quot;previous&quot;,
267
 
 
268
 
            &#x2F;&#x2F; Only go circular for the root listbox
269
 
            circular = (parent === this),
270
 
            sibling = item[method](circular);
271
 
 
272
 
        if (sibling) {
273
 
            &#x2F;&#x2F; If we found a sibling, it&#x27;s either an Option or a ListBox
274
 
            if (sibling instanceof Y.ListBox) {
275
 
                &#x2F;&#x2F; If it&#x27;s a ListBox, select it&#x27;s first child (in the direction we&#x27;re headed)
276
 
                sibling.selectChild((direction) ? 0 : sibling.size() - 1);
277
 
            } else {
278
 
                &#x2F;&#x2F; If it&#x27;s an Option, select it
279
 
                sibling.set(&quot;selected&quot;, 1);
280
 
            }
281
 
        } else {
282
 
            &#x2F;&#x2F; If we didn&#x27;t find a sibling, we&#x27;re at the last leaf in a nested ListBox
283
 
            parent[method](true).set(&quot;selected&quot;, 1);
284
 
        }
285
 
    },
286
 
 
287
 
    &#x2F;&#x2F; The markup template we use internally to render nested ListBox children    
288
 
    NESTED_TEMPLATE : &#x27;&lt;li class=&quot;{nestedOptionClassName}&quot;&gt;&lt;em class=&quot;{labelClassName}&quot;&gt;{label}&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;&#x27;,
289
 
 
290
 
    renderUI: function () {
291
 
 
292
 
        &#x2F;&#x2F; Handling Nested Child Element Rendering
293
 
        if (this.get(&quot;depth&quot;) &gt; -1) {
294
 
 
295
 
            var tokens = {
296
 
                    labelClassName : this.getClassName(&quot;label&quot;),
297
 
                    nestedOptionClassName : this.getClassName(&quot;option&quot;),
298
 
                    label : this.get(&quot;label&quot;)
299
 
                },
300
 
                liHtml = Y.substitute(this.NESTED_TEMPLATE, tokens),
301
 
                li = Y.Node.create(liHtml),
302
 
 
303
 
                boundingBox = this.get(&quot;boundingBox&quot;),
304
 
                parent = boundingBox.get(&quot;parentNode&quot;);
305
 
 
306
 
            li.appendChild(boundingBox);
307
 
            parent.appendChild(li);
308
 
        }
309
 
    }
310
 
 
311
 
} { &#x2F;* static properties *&#x2F; });</pre>
312
 
 
313
 
 
314
 
<h4>Static Properties</h4>
315
 
 
316
 
<p>The only static property we're interested in defining for the ListBox class is the <code>ATTRS</code> property. Comments inline below provide the background:</p>
317
 
 
318
 
<pre class="code prettyprint">{ 
319
 
    &#x2F;&#x2F; Define any new attributes, or override existing ones
320
 
    ATTRS : {
321
 
 
322
 
        &#x2F;&#x2F; We need to define the default child class to use,
323
 
        &#x2F;&#x2F; when we need to create children from the configuration 
324
 
        &#x2F;&#x2F; object passed to add or to the &quot;children&quot; attribute (which is provided by WidgetParent)
325
 
 
326
 
        &#x2F;&#x2F; In this case, when a configuration object (e.g. { label:&quot;My Option&quot; }),
327
 
        &#x2F;&#x2F; is passed into the add method,or as the value of the &quot;children&quot;
328
 
        &#x2F;&#x2F; attribute, we want to create instances of Y.Option
329
 
        defaultChildType: {  
330
 
            value: &quot;Option&quot;
331
 
        },
332
 
 
333
 
        &#x2F;&#x2F; Setup Label Attribute
334
 
        label : {
335
 
            validator: Y.Lang.isString
336
 
        }
337
 
    }
338
 
}</pre>
339
 
 
340
 
 
341
 
<h3>Using WidgetChild to Create the Option (leaf) Class</h3>
342
 
 
343
 
<p>The Option class is pretty simple, and largely just needs the attribute and API provided by WidgetChild. We only need to over-ride the default templates and tabIndex handling:</p>
344
 
 
345
 
<pre class="code prettyprint">Y.Option = Y.Base.create(&quot;option&quot;, Y.Widget, [Y.WidgetChild], {
346
 
 
347
 
    &#x2F;&#x2F; Override the default DIVs used for rendering the bounding box and content box.
348
 
    CONTENT_TEMPLATE : &quot;&lt;em&gt;&lt;&#x2F;em&gt;&quot;,
349
 
    BOUNDING_TEMPLATE : &quot;&lt;li&gt;&lt;&#x2F;li&gt;&quot;,
350
 
 
351
 
    &#x2F;&#x2F; Handle rendering the label attribute
352
 
    renderUI: function () {
353
 
        this.get(&quot;contentBox&quot;).setContent(this.get(&quot;label&quot;));
354
 
    }
355
 
 
356
 
}, {
357
 
 
358
 
    ATTRS : {
359
 
 
360
 
        &#x2F;&#x2F; Setup Label Attribute
361
 
        label : {
362
 
            validator: Y.Lang.isString
363
 
        },
364
 
 
365
 
        &#x2F;&#x2F; Override the default tabIndex for an Option,
366
 
        &#x2F;&#x2F; since we want FocusManager to control keboard
367
 
        &#x2F;&#x2F; based focus
368
 
        tabIndex: {
369
 
            value: -1
370
 
        }
371
 
    }
372
 
 
373
 
});</pre>
374
 
 
375
 
 
376
 
<h3>Adding The Code As A "listbox" Custom Module</h3>
377
 
 
378
 
<p>This example also shows how you can package code for re-use as a module, by registering it through the <code>YUI.add</code> method, specifying any requirements it has (the packaged code is available in ./assets/listbox.js).</p>
379
 
 
380
 
<pre class="code prettyprint">YUI.add(&#x27;listbox&#x27;, function(Y) {
381
 
 
382
 
  Y.ListBox = ...
383
 
 
384
 
  Y.Option = ...
385
 
 
386
 
}, &#x27;3.1.0&#x27; ,{requires:[&#x27;substitute&#x27;, &#x27;widget&#x27;, &#x27;widget-parent&#x27;, &#x27;widget-child&#x27;, &#x27;node-focusmanager&#x27;]});</pre>
387
 
 
388
 
 
389
 
<h3>Using the Custom "listbox" Module</h3>
390
 
 
391
 
<p>To create an instance of a ListBox, we ask for the "listbox" module we packaged in the previous step, through <code>YUI().use(&quot;listbox&quot;)</code>:</p>
392
 
 
393
 
<pre class="code prettyprint">YUI({ 
394
 
    modules: {
395
 
        &quot;listbox&quot;: {
396
 
            fullpath: &quot;listbox.js&quot;,
397
 
            requires: [&quot;substitute&quot;, &quot;widget&quot;, &quot;widget-parent&quot;, &quot;widget-child&quot;, &quot;node-focusmanager&quot;]
398
 
        }
399
 
    }
400
 
 }).use(&quot;listbox&quot;, function (Y) {
401
 
 
402
 
    &#x2F;&#x2F; Create the top level ListBox instance, and start it off with
403
 
    &#x2F;&#x2F; 2 children (the defaultChildType will be used to create instances of Y.Option with the 
404
 
    &#x2F;&#x2F; children configuration passed in below).
405
 
 
406
 
    var listbox = new Y.ListBox({  
407
 
        id:&quot;mylistbox&quot;, 
408
 
        width:&quot;13em&quot;, 
409
 
        height:&quot;15em&quot;, 
410
 
        children: [ 
411
 
            { label: &quot;Item One&quot; },
412
 
            { label: &quot;Item Two&quot; } 
413
 
        ]
414
 
    });
415
 
 
416
 
    ...
417
 
});</pre>
418
 
 
419
 
 
420
 
<p>We can also use the <code>add</code> method provided by WidgetParent, to add children after contruction, and then render to the DOM:</p>
421
 
 
422
 
<pre class="code prettyprint">&#x2F;&#x2F; Then we add a nested ListBox which itself has 2 children, using 
423
 
&#x2F;&#x2F; the add API provided by WidgetParent
424
 
 
425
 
listbox.add({ 
426
 
    type: &quot;ListBox&quot;, 
427
 
    label: &quot;Item Three&quot;, 
428
 
    children: [ 
429
 
        { label: &quot;Item Three - One&quot; },
430
 
        { label: &quot;Item Three - Two&quot; } 
431
 
    ]
432
 
});
433
 
 
434
 
&#x2F;&#x2F; One more Option child
435
 
 
436
 
listbox.add({ label: &quot;Item Four&quot; });
437
 
 
438
 
&#x2F;&#x2F; One more Option child, using providing an actual
439
 
&#x2F;&#x2F; instance, as opposed to just the configuration
440
 
 
441
 
listbox.add(
442
 
    new Y.Option({ label: &quot;Item Five&quot; })
443
 
);
444
 
 
445
 
&#x2F;&#x2F; And finally, a last nested ListBox, again with
446
 
&#x2F;&#x2F; 2 children
447
 
 
448
 
listbox.add({ 
449
 
    type: &quot;ListBox&quot;, 
450
 
    label: &quot;Item Six&quot;, 
451
 
    children: [ 
452
 
        { label: &quot;Item Six - One&quot; },
453
 
        { label: &quot;Item Six - Two&quot; }
454
 
    ]
455
 
});
456
 
 
457
 
&#x2F;&#x2F; Render it, using Widget&#x27;s render method,
458
 
&#x2F;&#x2F; to the &quot;#exampleContainer&quot; element.
459
 
listbox.render(&quot;#exampleContainer&quot;);</pre>
460
 
 
461
 
 
462
 
<p>The ListBox fires selectionChange events, every time it's selection state changes (provided by WidgetParent), which we can listen and respond to:</p>
463
 
 
464
 
<pre class="code prettyprint">listbox.after(&quot;selectionChange&quot;, function(e) {
465
 
 
466
 
    var selection = this.get(&quot;selection&quot;);
467
 
    if (selection instanceof Y.ListBox) {
468
 
        selection = selection.get(&quot;selection&quot;);
469
 
    }
470
 
 
471
 
    if (selection) {
472
 
        Y.one(&quot;#selection&quot;).setContent(selection.get(&quot;label&quot;));
473
 
    }
474
 
 
475
 
});</pre>
476
 
 
477
 
 
478
 
<h3>The CSS</h3>
479
 
 
480
 
<pre class="code prettyprint">.yui3-listbox {
481
 
    padding:0;       
482
 
    margin: .25em;
483
 
    border: solid 1px #000;
484
 
    background-color:#fff;
485
 
    white-space:nowrap;
486
 
}
487
 
 
488
 
.yui3-listbox .yui3-listbox {
489
 
    margin-top: .25em;
490
 
    margin-bottom: .25em;
491
 
    border: none;
492
 
}
493
 
 
494
 
.yui3-listbox .yui3-option, 
495
 
.yui3-listbox .yui3-listbox-option {
496
 
    margin:0;
497
 
    padding:0;
498
 
    cursor:default;
499
 
    list-style-image:none;
500
 
    list-style-position:outside;
501
 
    list-style-type:none;
502
 
}
503
 
 
504
 
.yui3-option-content,
505
 
.yui3-listbox-label {
506
 
    display: block;
507
 
    padding: .25em .5em;
508
 
}
509
 
 
510
 
.yui3-listbox-content {
511
 
    margin:0;
512
 
    padding:0;
513
 
    overflow:auto;
514
 
}
515
 
 
516
 
.yui3-listbox .yui3-listbox .yui3-option-content {
517
 
    margin-left:.5em;
518
 
}
519
 
 
520
 
.yui3-listbox-label {
521
 
    font-weight: bold;
522
 
}
523
 
 
524
 
.yui3-option-selected {
525
 
    background-color: #cccccc;
526
 
}
527
 
 
528
 
.yui3-option-focused {
529
 
    outline: none;
530
 
    background-color: blue;
531
 
    color: #fff;
532
 
}</pre>
533
 
 
534
 
 
535
 
<h2>Complete Example Source</h2>
536
 
<pre class="code prettyprint">&lt;p id=&quot;selected&quot;&gt;Selected: &lt;span id=&quot;selection&quot;&gt;None&lt;&#x2F;span&gt;&lt;&#x2F;p&gt;
537
 
 
538
 
&lt;div id=&quot;exampleContainer&quot;&gt;&lt;&#x2F;div&gt;
539
 
 
540
 
&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
541
 
    YUI({ 
542
 
        modules: {
543
 
            &quot;listbox&quot;: {
544
 
                fullpath: &quot;..&#x2F;assets&#x2F;widget&#x2F;listbox.js&quot;,
545
 
                requires: [&quot;substitute&quot;, &quot;widget&quot;, &quot;widget-parent&quot;, &quot;widget-child&quot;, &quot;node-focusmanager&quot;]
546
 
            }
547
 
        }
548
 
     }).use(&quot;listbox&quot;, function (Y) {
549
 
 
550
 
        var listbox = new Y.ListBox({  
551
 
            id:&quot;mylistbox&quot;, 
552
 
            width:&quot;13em&quot;, 
553
 
            height:&quot;15em&quot;, 
554
 
            children: [ 
555
 
                { label: &quot;Item One&quot; },
556
 
                { label: &quot;Item Two&quot; } 
557
 
            ]
558
 
        });
559
 
 
560
 
        listbox.add({ 
561
 
            type: &quot;ListBox&quot;, 
562
 
            label: &quot;Item Three&quot;, 
563
 
            children: [ 
564
 
                { label: &quot;Item Three - One&quot; },
565
 
                { label: &quot;Item Three - Two&quot; } 
566
 
            ]
567
 
        });
568
 
 
569
 
        listbox.add({ label: &quot;Item Four&quot; });
570
 
 
571
 
        listbox.add(
572
 
            new Y.Option({ label: &quot;Item Five&quot; })
573
 
        );
574
 
 
575
 
        listbox.add({ 
576
 
            type: &quot;ListBox&quot;, 
577
 
            label: &quot;Item Six&quot;, 
578
 
            children: [ 
579
 
                { label: &quot;Item Six - One&quot; },
580
 
                { label: &quot;Item Six - Two&quot; }
581
 
            ]
582
 
        });
583
 
 
584
 
        listbox.after(&quot;selectionChange&quot;, function(e) {
585
 
 
586
 
            var selection = this.get(&quot;selection&quot;);
587
 
            if (selection instanceof Y.ListBox) {
588
 
                selection = selection.get(&quot;selection&quot;);
589
 
            }
590
 
 
591
 
            if (selection) {
592
 
                Y.one(&quot;#selection&quot;).setContent(selection.get(&quot;label&quot;));
593
 
            }
594
 
        });
595
 
 
596
 
        listbox.render(&quot;#exampleContainer&quot;);
597
 
    });
598
 
&lt;&#x2F;script&gt;</pre>
599
 
 
600
 
</div>
601
 
            </div>
602
 
        </div>
603
 
 
604
 
        <div class="yui3-u-1-4">
605
 
            <div class="sidebar">
606
 
                
607
 
 
608
 
                
609
 
                    <div class="sidebox">
610
 
                        <div class="hd">
611
 
                            <h2 class="no-toc">Examples</h2>
612
 
                        </div>
613
 
 
614
 
                        <div class="bd">
615
 
                            <ul class="examples">
616
 
                                
617
 
                                    
618
 
                                        <li data-description="Shows how to extend the base widget class, to create your own Widgets.">
619
 
                                            <a href="widget-extend.html">Extending the Base Widget Class</a>
620
 
                                        </li>
621
 
                                    
622
 
                                
623
 
                                    
624
 
                                        <li data-description="Shows how to use Base.create and mix/match extensions to create custom Widget classes.">
625
 
                                            <a href="widget-build.html">Creating Custom Widget Classes With Extensions</a>
626
 
                                        </li>
627
 
                                    
628
 
                                
629
 
                                    
630
 
                                        <li data-description="Shows how to create an IO plugin for Widget.">
631
 
                                            <a href="widget-plugin.html">Creating a Widget Plugin</a>
632
 
                                        </li>
633
 
                                    
634
 
                                
635
 
                                    
636
 
                                        <li data-description="Shows how to extend the Widget class, and add WidgetPosition and WidgetStack to create a Tooltip widget class.">
637
 
                                            <a href="widget-tooltip.html">Creating a Simple Tooltip Widget With Extensions</a>
638
 
                                        </li>
639
 
                                    
640
 
                                
641
 
                                    
642
 
                                        <li data-description="Shows how to extend the Widget class, and add WidgetParent and WidgetChild to create a simple ListBox widget.">
643
 
                                            <a href="widget-parentchild-listbox.html">Creating a Hierarchical ListBox Widget</a>
644
 
                                        </li>
645
 
                                    
646
 
                                
647
 
                            </ul>
648
 
                        </div>
649
 
                    </div>
650
 
                
651
 
 
652
 
                
653
 
            </div>
654
 
        </div>
655
 
    </div>
656
 
</div>
657
 
 
658
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
659
 
<script>prettyPrint();</script>
660
 
 
661
 
</body>
662
 
</html>