|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Split Button Top Nav</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Split Button Top Nav</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><div class="intro"> |
|
|
29 |
<p> |
|
|
30 |
This example demonstrates how to create a traditional, two-column page layout |
|
|
31 |
(<a href="../cssgrids/index.html">using Grids</a>) with top navigation rendered like split buttons. |
|
|
32 |
</p> |
|
|
33 |
</div> |
|
|
34 |
|
|
|
35 |
<div class="example newwindow"> |
|
|
36 |
<a href="node-menunav-4-example.html" target="_blank" class="button"> |
|
|
37 |
View Example in New Window |
|
|
38 |
</a> |
|
|
39 |
</div> |
|
|
40 |
|
|
|
41 |
<h2>Setting Up the HTML</h2> |
|
|
42 |
<p> |
|
|
43 |
Begin by including the <a href="../cssgrids/index.html#dependencies">CSS Grids dependencies</a> and grid |
|
|
44 |
markup (this example uses a 2 column version of the |
|
|
45 |
<a href="../cssgrids/cssgrids-fluid.html">Fluid Page Template</a> with a 160px left column). |
|
|
46 |
Add the markup for the menu to the left column of the grid. |
|
|
47 |
</p> |
|
|
48 |
<p> |
|
|
49 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
50 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
51 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
52 |
</p> |
|
|
53 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
54 |
|
|
|
55 |
|
|
|
56 |
<p> |
|
|
57 |
The root menu of menus built using the MenuNav Node Plugin can have a verical or horizontal |
|
|
58 |
orientation. The default orientation for menus is vertical, but can be easily switched to |
|
|
59 |
horizontal by applying a class of <code>yui3-menu-horizontal</code> to the node representing the |
|
|
60 |
root menu's bounding box, as illustrated below: |
|
|
61 |
</p> |
|
|
62 |
|
|
|
63 |
<pre class="code prettyprint"><div id="productsandservices" class="yui3-menu yui3-menu-horizontal"><!-- Bounding box --> |
|
|
64 |
<div class="yui3-menu-content"><!-- Content box --> |
|
|
65 |
<ul> |
|
|
66 |
<!-- Menu items --> |
|
|
67 |
</ul> |
|
|
68 |
</div> |
|
|
69 |
</div></pre> |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
<p> |
|
|
73 |
To render each menu label in the horizontal menu as a split button, add the class |
|
|
74 |
<code>yui3-splitbuttonnav</code> to the node representing the root menu's bounding box, as |
|
|
75 |
illustrated below: |
|
|
76 |
</p> |
|
|
77 |
|
|
|
78 |
<pre class="code prettyprint"><div id="menu-1" class="yui3-menu yui3-menu-horizontal yui3-splitbuttonnav"><!-- Bounding box --> |
|
|
79 |
<div class="yui3-menu-content"><!-- Content box --> |
|
|
80 |
<ul> |
|
|
81 |
<!-- Menu items --> |
|
|
82 |
</ul> |
|
|
83 |
</div> |
|
|
84 |
</div></pre> |
|
|
85 |
|
|
|
86 |
|
|
|
87 |
<p> |
|
|
88 |
Next, define the markup for each menu label. Start with a <code><span></code> with a class |
|
|
89 |
of <code>yui3-menu-label</code> applied. Inside the <code><span></code>, place two |
|
|
90 |
<code><a></code> elements — one for each of the label's two clickable regions. |
|
|
91 |
Each <code><a></code> has separate, but related responsibilities: The first |
|
|
92 |
<code><a></code> represents the label's default action. The second <code><a></code> |
|
|
93 |
toggles the display of a submenu whose content contains other options related to, or in the same |
|
|
94 |
category of the default action. Therefore to configure the first <code><a></code>, |
|
|
95 |
simply set its <code>href</code> attribute to any URL. For the second <code><a></code>, |
|
|
96 |
apply a class name of <code>yui3-menu-toggle</code>, and set the value of the <code>href</code> |
|
|
97 |
attribute to the id of the label's corresponding submenu. Lastly, the text node of the second |
|
|
98 |
<code><a></code> should label the contents of its corresponding submenu. |
|
|
99 |
</p> |
|
|
100 |
|
|
|
101 |
<pre class="code prettyprint"><div id="menu-1" class="yui3-menu yui3-menu-horizontal yui3-splitbuttonnav"><!-- Bounding box --> |
|
|
102 |
<div class="yui3-menu-content"><!-- Content box --> |
|
|
103 |
<ul> |
|
|
104 |
<li> |
|
|
105 |
|
|
|
106 |
<span class="yui3-menu-label"><!-- menu label root node --> |
|
|
107 |
<a href="http://answers.yahoo.com">Answers</a><!-- menu label default action --> |
|
|
108 |
<a href="#answers-options" class="yui3-menu-toggle">Answers Options</a><!-- menu label submenu toggle --> |
|
|
109 |
</span> |
|
|
110 |
|
|
|
111 |
<div id="answers-options" class="yui3-menu"> |
|
|
112 |
<div class="yui3-menu-content"> |
|
|
113 |
<ul> |
|
|
114 |
<li class="yui3-menuitem"><a class="yui3-menuitem-content" href="http://answers.yahoo.com/dir/">Answer</a></li> |
|
|
115 |
<li class="yui3-menuitem"><a class="yui3-menuitem-content" href="http://answersonthestreet.yahoo.com/">Answers on the Street</a></li> |
|
|
116 |
<li class="yui3-menuitem"><a class="yui3-menuitem-content" href="http://answers.yahoo.com/question/;_ylt=Av3Nt22Mr7YNs651NWFv8YUPzKIX;_ylv=3?link=ask">Ask</a></li> |
|
|
117 |
<li class="yui3-menuitem"><a class="yui3-menuitem-content" href="http://answers.yahoo.com/dir/;_ylt=Aqp_jJlsYDP7urcq2WGC6HBJxQt.;_ylv=3?link=over&amp;amp;more=y">Discover</a></li> |
|
|
118 |
</ul> |
|
|
119 |
</div> |
|
|
120 |
</div> |
|
|
121 |
|
|
|
122 |
</li> |
|
|
123 |
</ul> |
|
|
124 |
</div> |
|
|
125 |
</div></pre> |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
<h2>Initializing the Menu</h2> |
|
|
129 |
<p> |
|
|
130 |
With the menu markup in place, retrieve the Node instance representing the root |
|
|
131 |
menu (<code><div id="productsandservices"></code>) and call the |
|
|
132 |
<a href="http://yuilibrary.com/yui/docs/api/classes/Node.html#method_plug"><code>plug</code></a> |
|
|
133 |
passing in a reference to the MenuNav Node Plugin. |
|
|
134 |
</p> |
|
|
135 |
|
|
|
136 |
<p> |
|
|
137 |
Use the |
|
|
138 |
<a href="http://yuilibrary.com/yui/docs/api/classes/plugin.NodeMenuNav.html#attr_autoSubmenuDisplay"><code>autoSubmenuDisplay</code></a> |
|
|
139 |
and <a href="http://yuilibrary.com/yui/docs/api/classes/plugin.NodeMenuNav.html#attr_mouseOutHideDelay"><code>mouseOutHideDelay</code></a> |
|
|
140 |
configuration attributes to configure the menu labels to behave like split buttons. Set the |
|
|
141 |
<code>autoSubmenuDisplay</code> to <code>false</code>, so that each menu label's submenu isn't |
|
|
142 |
made visible until the menu trigger is clicked. Set the <code>mouseOutHideDelay</code> to |
|
|
143 |
<code>0</code> so that a label's submenu is only hidden when the user mouses down on an area |
|
|
144 |
outside of the submenu. |
|
|
145 |
</p> |
|
|
146 |
|
|
|
147 |
<pre class="code prettyprint"><!-- YUI Seed --> |
|
|
148 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
149 |
|
|
|
150 |
<script> |
|
|
151 |
// Call the "use" method, passing in "node-menunav". This will load the |
|
|
152 |
// script and CSS for the MenuNav Node Plugin and all of the required |
|
|
153 |
// dependencies. |
|
|
154 |
|
|
|
155 |
YUI().use('node-menunav', function(Y) { |
|
|
156 |
|
|
|
157 |
// Retrieve the Node instance representing the root menu |
|
|
158 |
// (<div id="productsandservices">) and call the "plug" method |
|
|
159 |
// passing in a reference to the MenuNav Node Plugin. |
|
|
160 |
|
|
|
161 |
var menu = Y.one("#productsandservices"); |
|
|
162 |
|
|
|
163 |
menu.plug(Y.Plugin.NodeMenuNav, { autoSubmenuDisplay: false, mouseOutHideDelay: 0 }); |
|
|
164 |
|
|
|
165 |
}); |
|
|
166 |
</script></pre> |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
<p> |
|
|
170 |
<em>Note:</em> In keeping with the |
|
|
171 |
<a href="http://developer.yahoo.com/performance/">Exceptional Performance</a> |
|
|
172 |
team's recommendation, the script block used to instantiate the menu will be |
|
|
173 |
<a href="http://developer.yahoo.com/performance/rules.html#js_bottom">placed at the bottom of the page</a>. |
|
|
174 |
This not only improves performance, it helps ensure that the DOM subtree of the |
|
|
175 |
element representing the root menu |
|
|
176 |
(<code><div id="productsandservices"></code>) is ready to be scripted. |
|
|
177 |
</p> |
|
|
178 |
</div> |
|
|
179 |
</div> |
|
|
180 |
</div> |
|
|
181 |
|
|
|
182 |
<div class="yui3-u-1-4"> |
|
|
183 |
<div class="sidebar"> |
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
<div class="sidebox"> |
|
|
188 |
<div class="hd"> |
|
|
189 |
<h2 class="no-toc">Examples</h2> |
|
|
190 |
</div> |
|
|
191 |
|
|
|
192 |
<div class="bd"> |
|
|
193 |
<ul class="examples"> |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
<li data-description="Creating left navigation using the MenuNav Node Plugin."> |
|
|
197 |
<a href="menunav-leftnav.html">Basic Left Nav</a> |
|
|
198 |
</li> |
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
<li data-description="Creating top navigation using the MenuNav Node Plugin"> |
|
|
203 |
<a href="node-menunav-2.html">Basic Top Nav</a> |
|
|
204 |
</li> |
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
<li data-description="Creating menu button navigation using the MenuNav Node Plugin"> |
|
|
209 |
<a href="node-menunav-3.html">Menu Button Top Nav</a> |
|
|
210 |
</li> |
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
<li data-description="Creating split button navigation using the MenuNav Node Plugin"> |
|
|
215 |
<a href="node-menunav-4.html">Split Button Top Nav</a> |
|
|
216 |
</li> |
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
<li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
221 |
<a href="node-menunav-5.html">Left Nav with Submenus with Shadows</a> |
|
|
222 |
</li> |
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
<li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin"> |
|
|
227 |
<a href="node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a> |
|
|
228 |
</li> |
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
<li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr"> |
|
|
233 |
<a href="node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a> |
|
|
234 |
</li> |
|
|
235 |
|
|
|
236 |
|
|
|
237 |
</ul> |
|
|
238 |
</div> |
|
|
239 |
</div> |
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
</div> |
|
|
244 |
</div> |
|
|
245 |
</div> |
|
|
246 |
</div> |
|
|
247 |
|
|
|
248 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
249 |
<script>prettyPrint();</script> |
|
|
250 |
|
|
|
251 |
<script> |
|
|
252 |
YUI.Env.Tests = { |
|
|
253 |
examples: [], |
|
|
254 |
project: '../assets', |
|
|
255 |
assets: '../assets/node-menunav', |
|
|
256 |
name: 'node-menunav-4', |
|
|
257 |
title: 'Split Button Top Nav', |
|
|
258 |
newWindow: 'true', |
|
|
259 |
auto: false |
|
|
260 |
}; |
|
|
261 |
YUI.Env.Tests.examples.push('menunav-leftnav'); |
|
|
262 |
YUI.Env.Tests.examples.push('node-menunav-2'); |
|
|
263 |
YUI.Env.Tests.examples.push('node-menunav-3'); |
|
|
264 |
YUI.Env.Tests.examples.push('node-menunav-4'); |
|
|
265 |
YUI.Env.Tests.examples.push('node-menunav-5'); |
|
|
266 |
YUI.Env.Tests.examples.push('node-menunav-6'); |
|
|
267 |
YUI.Env.Tests.examples.push('node-menunav-7'); |
|
|
268 |
|
|
|
269 |
</script> |
|
|
270 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
</body> |
|
|
275 |
</html> |