Learning the Yahoo! User Interface library: Develop your next generation web applications with the YUI JavaScript development library

Learning the Yahoo! User Interface Library Get started and get to grips with the YUI JavaScript development library! ...
Author:  Dan Wellman

27 downloads 547 Views 5MB Size Report

This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!

Report copyright / DMCA form

HTML & JavaScript Text Editor v 1.0
[ 211 ]

Navigation and AutoComplete

The MenuBar can be created from underlying mark up. Add the mark up for it to the hd section of the page:

Structurally, it's exactly the same as the standard vertical navigation menu. All that's changed are the class names for the top-level menu items where yuimenubar, yuimenubaritem, and yuimenubaritemlabel are used instead of yuimenu, yuimenuitem, and yuimenuitemlabel. Now let's add the JavaScript that will transform our mark up into an application style menu bar. We need to define a callback function that will generate the menu, as well as a handler to call this function. Add the following <script> block to the of the document directly after the underlying mark up for the MenuBar: <script type="text/javascript"> //set up the namespace object for this example YAHOO.namespace("yuibook.menu"); //define the initmenu function YAHOO.yuibook.menu.initMenu = function() { //create the MenuBar object var menu = new YAHOO.widget.MenuBar("appmenu", { autosubmenudisplay: true }); //draw the menu on screen menu.render(); } //create the menubar object when the DOM is ready YAHOO.util.Event.onDOMReady(YAHOO.yuibook.menu.initMenu); [ 213 ]

Navigation and AutoComplete

We specified another literal configuration object in the constructor for our MenuBar, this time making use of the autosubmenudisplay property. This means that the submenus on our MenuBar will automatically display when the mouse pointer hovers over them. Other configuration properties can be set in the same way. Save the file in your yuisite folder as textEditor.html or similar and view it in a browser. At this point it should appear like this:

We need to tidy the page up a little, which we can do with the following CSS, which should be added to a blank page in your text editor: .yui-skin-sam .ed { margin-top:-2px; width:748px; *width:749px; border:1px solid #7f9db9; height:200px; overflow:auto; } .yui-skin-sam #ft { margin-top:-2px; width:748px; *width:749px; border:1px solid #7f9db9; height:22px; background:url(yui/build/assets/skins/sam/sprite.png) repeat-x; }

[ 214 ]

Chapter 7

Save this new file as texteditor.css in your yuisite folder. These two selectors will style the page so that the