File: contextmenu_source.html

package info (click to toggle)
yui 2.9.0.dfsg.0.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 89,324 kB
  • sloc: php: 52,404; java: 4,329; xml: 748; makefile: 37
file content (413 lines) | stat: -rw-r--r-- 12,077 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"><html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Example: Context Menu (YUI Library)</title>

        <!-- Standard reset and fonts -->

        <link rel="stylesheet" type="text/css" href="../../build/reset/reset.css">
        <link rel="stylesheet" type="text/css" href="../../build/fonts/fonts.css">
 

        <!-- CSS for Menu -->

        <link rel="stylesheet" type="text/css" href="../../build/menu/assets/skins/sam/menu.css"> 


        <!-- Page-specific styles -->

        <style type="text/css">

            h1 { 

                font-weight: bold; 
                margin: 0 0 1em 0;
            }

            body {
            
                padding: 1em;
            
            }

            p, ul {

                margin: 1em 0;

            }

            p em,
            #operainstructions li em {

                font-weight: bold;

            }

            #operainstructions {

                list-style-type: square;
                margin-left: 2em;

            }

            #clones {

                background: #99cc66 url(assets/grass.png);

                /* Hide the alpha PNG from IE 6 */
                _background-image: none;

                width: 450px;
                height: 400px;
                overflow: auto;
         
            }
            
            #clones li {
            
                float: left;
                display: inline;
                border: solid 1px #000;
                background-color: #fff;
                margin: 10px;
                text-align: center;
                zoom: 1;
            
            }

            #clones li img {
            
                border: solid 1px #000;
                margin: 5px;
            
            }
            
            #clones li cite {
            
                display: block;
                text-align: center;
                margin: 0 0 5px 0;
                padding: 0 5px;

            }
            
        </style>

        <!-- Namespace source file -->

        <script type="text/javascript" src="../../build/yahoo/yahoo.js"></script>


        <!-- Dependency source files -->

        <script type="text/javascript" src="../../build/event/event.js"></script>
        <script type="text/javascript" src="../../build/dom/dom.js"></script>
        <script type="text/javascript" src="../../build/animation/animation.js"></script>
        

        <!-- Container source file -->

        <script type="text/javascript" src="../../build/container/container_core.js"></script>


        <!-- Menu source file -->

        <script type="text/javascript" src="../../build/menu/menu.js"></script>


        <!-- Page-specific script -->

        <script type="text/javascript">

            /*
                 Initialize the ContextMenu instances when the the elements 
                 that trigger their display are ready to be scripted.
            */

            YAHOO.util.Event.onContentReady("clones", function () {

                // Maintain a reference to the "clones" <ul>

                var oClones = this;


                // Clone the first ewe so that we can create more later

                var oLI = oClones.getElementsByTagName("li")[0];
                var oEweTemplate = oLI.cloneNode(true);


                // Renames an "ewe"
    
                function editEweName(p_oLI) {
    
                    var oCite = p_oLI.lastChild;
    

                    if (oCite.nodeType != 1) {
                    
                        oCite = oCite.previousSibling;
    
                    }
                
                    var oTextNode = oCite.firstChild;
    
                    var sName = window.prompt("Enter a new name for ", 
                                oTextNode.nodeValue);
    

                    if (sName && sName.length > 0) {
                        
                        oTextNode.nodeValue = sName;
    
                    }
                
                }
                
    
                // Clones an "ewe"
    
                function cloneEwe(p_oLI, p_oMenu) {

                    var oClone = p_oLI.cloneNode(true);
    
                    p_oLI.parentNode.appendChild(oClone);

                    p_oMenu.cfg.setProperty("trigger", oClones.childNodes);
                
                }
                
    
                // Deletes an "ewe"
    
                function deleteEwe(p_oLI) {
    
                    var oUL = p_oLI.parentNode;
    
                    oUL.removeChild(p_oLI);
                
                }
                
    
                // "click" event handler for each item in the ewe context menu
                
                function onEweContextMenuClick(p_sType, p_aArgs) {
    
                    /*
                         The second item in the arguments array (p_aArgs) 
                         passed back to the "click" event handler is the 
                         MenuItem instance that was the target of the 
                         "click" event.
                    */

                    var oItem = p_aArgs[1], // The MenuItem that was clicked
                    	oTarget = this.contextEventTarget,
                        oLI;


                    if (oItem) {

						oLI = oTarget.nodeName.toUpperCase() == "LI" ? 
								oTarget : YAHOO.util.Dom.getAncestorByTagName(oTarget, "LI");


                        switch (oItem.index) {
                        
                            case 0:     // Edit name
        
                                editEweName(oLI);
                            
                            break;
        
        
                            case 1:     // Clone
        
                                cloneEwe(oLI, this);
        
                            break;
                            
        
                            case 2:     // Delete
        
                                deleteEwe(oLI);
        
                            break;                    
                        
                        }
                    
                    }
                
                }


                /*
                     Array of text labels for the MenuItem instances to be
                     added to the ContextMenu instanc.
                */

                var aMenuItems = ["Edit Name", "Clone", "Delete" ]; 


                /*
					Instantiate a ContextMenu:  The first argument passed to the constructor
					is the id for the Menu element to be created, the second is an 
					object literal of configuration properties.
                */

                var oEweContextMenu = new YAHOO.widget.ContextMenu(
                                            "ewecontextmenu", 
                                            {
                                                trigger: oClones.childNodes,
                                                itemdata: aMenuItems,
                                                lazyload: true                                    
                                            } 
                                        );


                // "render" event handler for the ewe context menu

                function onContextMenuRender(p_sType, p_aArgs) {
    
                    //  Add a "click" event handler to the ewe context menu
    
                    this.subscribe("click", onEweContextMenuClick);
                
                }


                // Add a "render" event handler to the ewe context menu

                oEweContextMenu.subscribe("render", onContextMenuRender);


                // Deletes an ewe from the field

                function deleteEwes() {

                    oEweContextMenu.cfg.setProperty("target", null);

                    oClones.innerHTML = "";


                    function onHide(p_sType, p_aArgs, p_oItem) {

                        p_oItem.cfg.setProperty("disabled", true);
                    
                        p_oItem.parent.unsubscribe("hide", onHide, p_oItem);
                    
                    }

                    this.parent.subscribe("hide", onHide, this);

                }


                // Creates a new ewe and appends it to the field

                function createNewEwe() {
                
                    var oLI = oEweTemplate.cloneNode(true);
                    
                    oClones.appendChild(oLI);

                    this.parent.getItem(1).cfg.setProperty("disabled", false);

                    oEweContextMenu.cfg.setProperty("trigger", oClones.childNodes);
                
                }


                // Sets the color of the grass in the field

                function setFieldColor(p_sType, p_aArgs, p_sColor) {

                    var oCheckedItem = this.parent.checkedItem;

                    if (oCheckedItem != this) {

                        YAHOO.util.Dom.setStyle("clones", "backgroundColor", p_sColor);
                        
                        this.cfg.setProperty("checked", true);


                        oCheckedItem.cfg.setProperty("checked", false);

                        this.parent.checkedItem = this;
                    
                    }

                }


                // "render" event handler for the field context menu

                function onFieldMenuRender(p_sType, p_aArgs) {

                    if (this.parent) {  // submenu

                        this.checkedItem = this.getItem(0);

                    }

                }


                /*
                     Array of object literals - each containing configuration 
                     properties for the items for the context menu.
                */

                var oFieldContextMenuItemData = [
                
                    {
                        text: "Field color", 
                        submenu: { 
                            id: "fieldcolors", 
                            itemdata: [
                                { text: "Light Green", onclick: { fn: setFieldColor, obj: "#99cc66" }, checked: true }, 
                                { text: "Medium Green", onclick: { fn: setFieldColor, obj: "#669933" } }, 
                                { text: "Dark Green", onclick: { fn: setFieldColor, obj: "#336600" } }
                            ] 
                        } 
                    },
                    { text: "Delete all", onclick: { fn: deleteEwes } },
                    { text: "New Ewe", onclick: { fn: createNewEwe } }
                
                ];


                /*
					Instantiate a ContextMenu:  The first argument passed to the constructor
					is the id for the Menu element to be created, the second is an 
					object literal of configuration properties.
                */

                var oFieldContextMenu = new YAHOO.widget.ContextMenu(
                                                "fieldcontextmenu",
                                                {
                                                    trigger: "clones",
                                                    itemdata: oFieldContextMenuItemData,
                                                    lazyload: true
                                                }
                                            );


                // Add a "render" event handler to the field context menu

                oFieldContextMenu.subscribe("render", onFieldMenuRender);
            
            
            });
                    
        </script>

    </head>
    <body class="yui-skin-sam">

        <ul id="clones">
            <li><a href="http://en.wikipedia.org/wiki/Dolly_%28clone%29"><img src="assets/dolly.jpg" width="100" height="100" alt="Dolly, a ewe, the first mammal to have been successfully cloned from an adult cell."></a><cite>Dolly</cite></li>
        </ul>

    </body>
</html>