OS-Style Programs Menu : Menu MenuItem « YUI Library « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » YUI Library » Menu MenuItem 
OS-Style Programs Menu
 


<!--
Software License Agreement (BSD License)
Copyright (c2009, Yahoo! Inc.
All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the
      following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTIONHOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISEARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sources of Intellectual Property Included in the YUI Library

YUI is issued by Yahoo! under the BSD license above. Below is a list of certain publicly available software that is the source of intellectual property in YUI, along with the licensing terms that pertain to thosesources of IP. This list is for informational purposes only and is not intended to represent an exhaustive list of third party contributions to the YUI.

    * Douglas Crockford's JSON parsing and stringifying methods: In the JSON Utility, Douglas Crockford's JSON parsing and stringifying methods are adapted from work published at JSON.org. The adapted work is in the public domain.
    * Robert Penner's animation-easing algorithms: In the Animation Utility, YUI makes use of Robert Penner's algorithms for easing.
    * Geoff Stearns's SWFObject: In the Charts Control and the Uploader versions through 2.7.0, YUI makes use of Geoff Stearns's SWFObject v1.5 for Flash Player detection and embedding. More information on SWFObject can be found here (http://blog.deconcept.com/swfobject/). SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License (http://www.opensource.org/licenses/mit-license.php).
    * Diego Perini's IEContentLoaded technique: The Event Utility employs a technique developed by Diego Perini and licensed under GPL. YUI's use of this technique is included under our BSD license with the author's permission.

-->

<!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: OS-Style Programs Menu (YUI Library)</title>

        <!-- Standard reset and fonts -->

        <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/reset/reset.css">
        <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/fonts/fonts.css">
        <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/container/assets/skins/sam/container.css">


        <!-- CSS for Menu -->

        <link rel="stylesheet" type="text/css" href="yui_2.7.0b-lib/menu/assets/skins/sam/menu.css"


        <!-- Page-specific styles -->

        <style type="text/css">

            html {
            
                overflow: hidden;
                background-color: #dfb8df;
            
            }

            h1 

                font-weight: bold; 

            }

            body {

                overflow: hidden;
            
            }


            /* Define a style for the <H1> "toolbar" */

            .ytoolbar {

                border-top-width: 2px;
                border-top-color: #ddd;
                border-top-style: solid;
                background-color: #ccc;
                position: absolute;
                bottom: 0;
                width: 100%;
            
            }


            /* Style the "Yahoo!" anchor to look like a button */

            .ytoolbar #yahoo {
            
                border-width: 2px;
                border-color: #ddd #666 #666 #ddd;
                border-style: solid;
                float: left;
                *float: none;   /* For IE */
                *display: inline-block; /* For IE */
                padding: 4px 12px 4px 28px;
                margin: 4px;
                background-color: #ccc;
                color: #000;
                text-decoration: none;
                background: url(http://us.i1.yimg.com/us.yimg.com/i/us/nt/b/purpley.1.0.gif) 10% 50% no-repeat;
            
            }

            .ytoolbar #yahoo: active {

                border-color: #666 #ddd #ddd #666;
            
            }


            /* Define a new style for each menu */

            .yui-skin-sam .yuimenu {
            
                line-height: 2;  /* ~24px */
                *line-height: 1.9/* For IE */
            
            }

            .yui-skin-sam .yuimenu .bd {

                border-width: 2px;
                border-color: #ddd #666 #666 #ddd;
                border-style: solid;
                background-color: #ccc;
            
            }


            /* Define a new style for each MenuItem instance. */

            .yui-skin-sam #yproducts li.yuimenuitem .yuimenuitemlabel {

                background: url(http://us.i1.yimg.com/us.yimg.com/i/us/nt/b/purpley.1.0.gif) no-repeat 4px;
                padding: 0 20px 0 24px;

            }

            .yui-skin-sam #yproducts li.yuimenuitem {
            
                /*
                    For IE 7 Quirks and IE 6 Strict Mode and Quirks Mode:
                    Used to collapse superfluous white space between <li> 
                    elements that is triggered by the "display" property of the
                    <a> elements being set to "block."
                */
            
                _border-bottom: solid 1px #ccc;
            
            }


            /* Define a new style for a MenuItem instance's "selected" state. */

            .yui-skin-sam #yproducts .yuimenuitem-selected {

                background-color: #039;

            }

            .yui-skin-sam #yproducts .yuimenuitemlabel-selected {

                color: #fff;

            }
            

            /* Add unique icons to some of the MenuItem instances. */

            .yui-skin-sam #yproducts li#help .yuimenuitemlabel {

                background-image: url(http://us.i1.yimg.com/us.yimg.com/i/nt/ic/ut/bsc/hlp16_1.gif);
            
            }

            .yui-skin-sam #yproducts li#search .yuimenuitemlabel {

                background-image: url(http://us.i1.yimg.com/us.yimg.com/i/nt/ic/ut/bsc/srch16_1.gif);
            
            }

            .yui-skin-sam #yproducts li#goto .yuimenuitemlabel {

                background-image: url(http://us.i1.yimg.com/us.yimg.com/i/nt/ic/ut/bsc/arorght16_1.gif);

            }

        </style>

        <!-- Dependency source files -->

        <script type="text/javascript" src="yui_2.7.0b-lib/utilities/utilities.js"></script>
        <script type="text/javascript" src="yui_2.7.0b-lib/container/container.js"></script>


        <!-- Menu source file -->

        <script type="text/javascript" src="yui_2.7.0b-lib/menu/menu.js"></script>


        <!-- Page-specific script -->

        <script type="text/javascript">

            /*
                 Initialize and render the MenuBar when its elements are ready 
                 to be scripted.
            */

            YAHOO.util.Event.onContentReady("yproducts"function () {

                var oPanel = new YAHOO.widget.Panel(
                                    "exampleinfo"
                                    
                                        constraintoviewport: true,
                                        fixedcenter: true,
                                        width: "400px",
                                        zindex: 1
                                    }
                                );

                 oPanel.setHeader("OS-Style Programs Menu Example");
                 oPanel.setBody("This example demonstrates how to transform existing markup on the page into an operating-system-like menu.");

                 oPanel.render(document.body);            

            

                /*
                    Apply the "ytoolbar" class to the <H1> so that it is styled 
                    like an application toolbar.
                */

                var oH1 = document.getElementsByTagName("h1")[0];

                YAHOO.util.Dom.addClass(oH1, "ytoolbar");


                /*
                     Instantiate a Menu:  The first argument passed to the 
                     constructor is the id of the element in the page 
                     representing the Menu; the second is an object literal 
                     of configuration properties.
                */

                var oMenu = new YAHOO.widget.Menu("yproducts"zindex: });


                /*
                     Aligns the bottom-left corner of Menu instance to the  
                     top-left corner of the Yahoo! anchor element that is 
                     its context element.
                */

                function positionMenu() {

                    oMenu.align("bl""tl");

                }


                // "click" handler for the "Go to..." menu item
    
                function onGotoClick() {
                
                    var sURL = window.prompt("Enter a URL: ","");
    
                    if (sURL && sURL.length > 0) {
                        
                        document.location = sURL;
    
                    }
                
                }


                /*
                      Add an additional item to the Menu instance.  Unlike the 
                      other items in the Menu instance, this item is added via 
                      script since its functionality requires JavaScript.
                */

                oMenu.addItem({ text: "Go to...", id: "goto", onclick: fn: onGotoClick } });


                /*
                    "beforeShow" event listener - used to position the 
                    root Menu instance when it is displayed.
                */

                oMenu.subscribe("beforeShow"function () {
                
                    if (this.getRoot() == this) {

                        positionMenu();

                    }
                
                });


                /*
                     Call the "render" method with no arguments since the 
                     markup for this menu already exists in the pages.
                */

                oMenu.render();


                /*
                    Position the bottom-left corner of the root menu to the 
                    top-left corner of the "Yahoo!" anchor element.
                */

                oMenu.cfg.setProperty("context"["yahoo""bl""tl"]);


                // "click" event handler for "Yahoo!" button
    
                function onYahooClick(p_oEvent) {
    
                    // Position and display the menu
                    
                    positionMenu();

                    oMenu.show();

  
                    // Stop propagation and prevent the default "click" behavior
    
                    YAHOO.util.Event.stopEvent(p_oEvent);
                    
                }


                /*
                    Assign a "click" event handler to the "Yahoo!" anchor that 
                    will display the menu
                */
                
                YAHOO.util.Event.addListener("yahoo""click", onYahooClick);


                /*
                    Add a "resize" event handler for the window that will 
                    reposition the H1 "toolbar" to the bottom of the viewport
                */

                YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionMenu);
            
            });

        </script>

    </head>
    <body class="yui-skin-sam">
        
        <h1><a id="yahoo" href="http://www.yahoo.com">Yahoo!</a></h1>

        <div id="yproducts">
            <div class="bd">
                <ul>
                    <li><a href="#">Products</a>
                        <div id="products">
                            <div class="bd">
                                <ul>
                                  <li><a href="http://mail.yahoo.com">Yahoo! Mail</a></li>
                                  <li><a href="http://addressbook.yahoo.com">Yahoo! Address Book</a></li>
                                  <li><a href="http://calendar.yahoo.com">Yahoo! Calender</a></li>
                                  <li><a href="http://notepad.yahoo.com">Yahoo! Notepad</a></li>
                                  <li><a href="http://messenger.yahoo.com">Yahoo! Messenger</a></li>
                                  <li><a href="http://360.yahoo.com">Yahoo! 360</a></li>
                                  <li><a href="http://www.flickr.com">Flickr Photo Sharing</a></li>
                                    <li><a href="http://finance.yahoo.com/">Finance</a></li>
                                    <li><a href="http://entertainment.yahoo.com/">Entertainment</a>
                                        <div id="entertainmentproducts">
                                            <div class="bd">
                                                <ul>
                                                  <li><a href="http://music.yahoo.com/">Yahoo! Music</a></li>
                                                  <li><a href="http://movies.yahoo.com/">Yahoo! Movies</a></li>
                                                  <li><a href="http://tv.yahoo.com/">Yahoo! TV</a></li>
                                                </ul>
                                            </div>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </li>
                    <li id="search"><a href="http://search.yahoo.com/">Search</a>
                        <div id="searchproducts">
                            <div class="bd">
                                <ul>
                                  <li><a href="http://images.search.yahoo.com/images">Yahoo! Image Search</a></li>
                                  <li><a href="http://dir.yahoo.com/">Yahoo! Directory</a></li>
                                  <li><a href="http://local.yahoo.com">Yahoo! Local</a></li>
                                  <li><a href="http://news.search.yahoo.com/news">Yahoo! News Search</a></li>
                                  <li><a href="http://search.yahoo.com/people">Yahoo! People Search</a></li>
                                  <li><a href="http://search.yahoo.com/products">Yahoo! Product Search</a></li>
                                </ul>
                            </div>
                        </div>                    
                    </li>
                    <li id="help"><a href="http://help.yahoo.com/">Help</a></li>
                </ul>
            </div>
        </div>
        
    </body>
</html><!-- presentbright.corp.yahoo.com uncompressed/chunked Thu Feb 19 10:53:17 PST 2009 -->

   
  
yui_2.7.0b.zip( 4,431 k)
Related examples in the same category
1. Icon on a Menu bar
2. Disabled menuitem
3. Add shortcut key to menuitem
4. Add submenu to menuitem
5. Add menuitem separator to menu
6. Create a Menu instance using existing markup on the page.
7. Create a Menu instance using nothing but JavaScript.
8. Grouped Menu Items Using Markup
9. Grouped Menu Items Using JavaScript
10. Grouped Menu Items With Titles From Markup
11. Grouped Menu Items With Titles From JavaScript
12. Multi-tiered Menu(sub menu) From Markup
13. Multi-tiered Menu (sun menu) From JavaScript
14. Handling Menu Click Events
15. Listening For Menu Events
16. Set MenuItem configuration properties when adding items to a Menu instance.
17. Setting Menu Configuration Properties At Runtime
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.