MenuNav Node Plugin: Left Nav With Submenus With Rounded Corners
+ ++This example demonstrates how to add rounded corners to submenus of a menu built using the +MenuNav Node Plugin. +
++ + + View example in new window. + + +
+ + +Creating the Rounded Corner HTML
++One way to add rounded corners to submenus is to append decorator elements to the node representing +a submenu's bounding box. As the name implies, decorator elements add no semantic value to the +markup, but enable additional styles to be applied. When adding any decorator elements to create +effects like shadows or rounded corners, always add those elements via JavaScript, since it is only +when JavaScript is enabled that a menu's markup is transformed in a drop-down menu system via the +MenuNav Node Plugin. +
+ +
+Each rounded corner is created by applying a background image to a <div>.
+A class name identifying the corner will be added to each <div>.
+The <div>s used to create the right corners will be nested inside the
+<div>s used to create the left corners, and each <div>
+for the left corners will have an additional class name of yui-menu-corner. The
+template for each set of rounded corners comes together as follows:
+
<!-- top-left and top-right corners --> <div class="yui-menu-corner yui-menu-corner-tl"><div class="yui-menu-corner-tr"></div></div> <!-- bottom-left and bottom-right corners --> <div class="yui-menu-corner yui-menu-corner-bl"><div class="yui-menu-corner-br"></div></div>
<!-- top-left and top-right corners --> +<div class="yui-menu-corner yui-menu-corner-tl"><div class="yui-menu-corner-tr"></div></div> + +<!-- bottom-left and bottom-right corners --> +<div class="yui-menu-corner yui-menu-corner-bl"><div class="yui-menu-corner-br"></div></div>
+The <div>s for each corner is created by passing a string
+of HTML to Node's create method. Use
+the all method to
+retrieve Node instances for each submenu, and the
+append and
+prepend
+methods to add the rounded corners <div>s to the bounding box of each submenu.
+
// Call the "use" method, passing in "node-menunav". This will load the // script and CSS for the MenuNav Node Plugin and all of the required // dependencies. YUI({base:"../../build/", timeout: 10000}).use("node-menunav", function(Y) { // Retrieve the Node instance representing the root menu // (<div id="productsandservices">) var menu = Y.one("#productsandservices"); // Use the "all" method to retrieve the // Node instances representing each submenu. menu.all(".yui-menu").each(function (node) { // Add decorator elements used to create the rounded corners to the // bounding box of each submenu. // Insert the first decorator before the submenu's content box node.prepend('<div class="yui-menu-corner yui-menu-corner-tl"><div class="yui-menu-corner-tr"></div></div>'); // Insert the second decorator after the submenu's content box node.append('<div class="yui-menu-corner yui-menu-corner-bl"><div class="yui-menu-corner-br"></div></div>'); }); // Call the "plug" method of the Node instance, passing in a reference to the // MenuNav Node Plugin. menu.plug(Y.Plugin.NodeMenuNav); // Show the menu now that it is ready menu.get("ownerDocument").get("documentElement").removeClass("yui-loading"); });
// Call the "use" method, passing in "node-menunav". This will load the +// script and CSS for the MenuNav Node Plugin and all of the required +// dependencies. + +YUI({base:"../../build/", timeout: 10000}).use("node-menunav", function(Y) { + + // Retrieve the Node instance representing the root menu + // (<div id="productsandservices">) + + var menu = Y.one("#productsandservices"); + + + // Use the "all" method to retrieve the + // Node instances representing each submenu. + + menu.all(".yui-menu").each(function (node) { + + // Add decorator elements used to create the rounded corners to the + // bounding box of each submenu. + + // Insert the first decorator before the submenu's content box + node.prepend('<div class="yui-menu-corner yui-menu-corner-tl"><div class="yui-menu-corner-tr"></div></div>'); + + // Insert the second decorator after the submenu's content box + node.append('<div class="yui-menu-corner yui-menu-corner-bl"><div class="yui-menu-corner-br"></div></div>'); + + }); + + + // Call the "plug" method of the Node instance, passing in a reference to the + // MenuNav Node Plugin. + + menu.plug(Y.Plugin.NodeMenuNav); + + // Show the menu now that it is ready + + menu.get("ownerDocument").get("documentElement").removeClass("yui-loading"); + +});
