|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Managing groups of buttons with button-group</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 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Example: Managing groups of buttons with button-group</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><link rel="stylesheet" href='../../build/cssbutton/cssbutton.css'></link> |
|
|
31 |
<div class="intro"> |
|
|
32 |
<p>In this example, we'll look at a few ways to create groups of buttons using the <code>'button-group'</code> module.</p> |
|
|
33 |
</div> |
|
|
34 |
|
|
|
35 |
<div class="example"> |
|
|
36 |
<div class='yui3-skin-sam'> <!-- You need this skin class --> |
|
|
37 |
<div id='checkboxContainer'> |
|
|
38 |
<h2 id="checkbox-group">Checkbox Group</h2> |
|
|
39 |
<button class='checkbox'>Button 1</button> |
|
|
40 |
<button class='checkbox'>Button 2</button> |
|
|
41 |
<button class='checkbox'>Button 3</button> |
|
|
42 |
</div> |
|
|
43 |
|
|
|
44 |
<div id='radioContainer'> |
|
|
45 |
<h2 id="radio-group">Radio Group</h2> |
|
|
46 |
<button class='radio'>Button A</button> |
|
|
47 |
<button class='radio'>Button B</button> |
|
|
48 |
<button class='radio'>Button C</button> |
|
|
49 |
</div> |
|
|
50 |
</div> |
|
|
51 |
|
|
|
52 |
<script> |
|
|
53 |
YUI().use('button-group', function(Y){ |
|
|
54 |
|
|
|
55 |
// A group of checkbox-like buttons |
|
|
56 |
var buttonGroupCB = new Y.ButtonGroup({ |
|
|
57 |
srcNode: '#checkboxContainer', |
|
|
58 |
type: 'checkbox', |
|
|
59 |
on: { |
|
|
60 |
'selectionChange': function(e){ |
|
|
61 |
var selection = buttonGroupCB.getSelectedButtons(); |
|
|
62 |
Y.log('buttonGroup2 selected count = ' + selection.length); |
|
|
63 |
} |
|
|
64 |
} |
|
|
65 |
}).render(); |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
// A group of radio-like buttons |
|
|
69 |
var buttonGroupRadio = new Y.ButtonGroup({ |
|
|
70 |
srcNode: '#radioContainer', |
|
|
71 |
type: 'radio' |
|
|
72 |
}) |
|
|
73 |
|
|
|
74 |
buttonGroupRadio.render(); |
|
|
75 |
|
|
|
76 |
buttonGroupRadio.on('selectionChange', function(e){ |
|
|
77 |
Y.log('buttonGroup selection changed'); |
|
|
78 |
}); |
|
|
79 |
|
|
|
80 |
}); |
|
|
81 |
</script> |
|
|
82 |
</div> |
|
|
83 |
|
|
|
84 |
<h4 id="source-html">Source: HTML</h4> |
|
|
85 |
<p> |
|
|
86 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
87 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
88 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
89 |
</p> |
|
|
90 |
<pre class="code prettyprint"><div class='yui3-skin-sam'> <!-- You need this skin class --> |
|
|
91 |
<div id='checkboxContainer'> |
|
|
92 |
<h2>Checkbox Group</h2> |
|
|
93 |
<button class='checkbox'>Button 1</button> |
|
|
94 |
<button class='checkbox'>Button 2</button> |
|
|
95 |
<button class='checkbox'>Button 3</button> |
|
|
96 |
</div> |
|
|
97 |
|
|
|
98 |
<div id='radioContainer'> |
|
|
99 |
<h2>Radio Group</h2> |
|
|
100 |
<button class='radio'>Button A</button> |
|
|
101 |
<button class='radio'>Button B</button> |
|
|
102 |
<button class='radio'>Button C</button> |
|
|
103 |
</div> |
|
|
104 |
</div></pre> |
|
|
105 |
|
|
|
106 |
<h4 id="source-javascript">Source: JavaScript</h4> |
|
|
107 |
<pre class="code prettyprint">YUI().use('button-group', function(Y){ |
|
|
108 |
|
|
|
109 |
// A group of checkbox-like buttons |
|
|
110 |
var buttonGroupCB = new Y.ButtonGroup({ |
|
|
111 |
srcNode: '#checkboxContainer', |
|
|
112 |
type: 'checkbox', |
|
|
113 |
on: { |
|
|
114 |
'selectionChange': function(e){ |
|
|
115 |
var selection = buttonGroupCB.getSelectedButtons(); |
|
|
116 |
Y.log('buttonGroup2 selected count = ' + selection.length); |
|
|
117 |
} |
|
|
118 |
} |
|
|
119 |
}).render(); |
|
|
120 |
|
|
|
121 |
|
|
|
122 |
// A group of radio-like buttons |
|
|
123 |
var buttonGroupRadio = new Y.ButtonGroup({ |
|
|
124 |
srcNode: '#radioContainer', |
|
|
125 |
type: 'radio' |
|
|
126 |
}) |
|
|
127 |
|
|
|
128 |
buttonGroupRadio.render(); |
|
|
129 |
|
|
|
130 |
buttonGroupRadio.on('selectionChange', function(e){ |
|
|
131 |
Y.log('buttonGroup selection changed'); |
|
|
132 |
}); |
|
|
133 |
|
|
|
134 |
});</pre> |
|
|
135 |
|
|
|
136 |
</div> |
|
|
137 |
</div> |
|
|
138 |
</div> |
|
|
139 |
|
|
|
140 |
<div class="yui3-u-1-4"> |
|
|
141 |
<div class="sidebar"> |
|
|
142 |
|
|
|
143 |
<div id="toc" class="sidebox"> |
|
|
144 |
<div class="hd"> |
|
|
145 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
146 |
</div> |
|
|
147 |
|
|
|
148 |
<div class="bd"> |
|
|
149 |
<ul class="toc"> |
|
|
150 |
<li> |
|
|
151 |
<a href="#checkbox-group">Checkbox Group</a> |
|
|
152 |
</li> |
|
|
153 |
<li> |
|
|
154 |
<a href="#radio-group">Radio Group</a> |
|
|
155 |
<ul class="toc"> |
|
|
156 |
<li> |
|
|
157 |
<a href="#source-html">Source: HTML</a> |
|
|
158 |
</li> |
|
|
159 |
<li> |
|
|
160 |
<a href="#source-javascript">Source: JavaScript</a> |
|
|
161 |
</li> |
|
|
162 |
</ul> |
|
|
163 |
</li> |
|
|
164 |
</ul> |
|
|
165 |
</div> |
|
|
166 |
</div> |
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
<div class="sidebox"> |
|
|
171 |
<div class="hd"> |
|
|
172 |
<h2 class="no-toc">Examples</h2> |
|
|
173 |
</div> |
|
|
174 |
|
|
|
175 |
<div class="bd"> |
|
|
176 |
<ul class="examples"> |
|
|
177 |
|
|
|
178 |
|
|
|
179 |
<li data-description="This example shows how you can easily style button and non-button DOM elements to appear as buttons"> |
|
|
180 |
<a href="cssbutton.html">Styling elements with cssbutton</a> |
|
|
181 |
</li> |
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
<li data-description="This example shows a simple, light solution to enhance <button> nodes"> |
|
|
186 |
<a href="button-plugin.html">Enhancing <button> nodes with button-plugin</a> |
|
|
187 |
</li> |
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
<li data-description="This example demonstrates how to create button widgets"> |
|
|
192 |
<a href="button-basic.html">Basic button widgets</a> |
|
|
193 |
</li> |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
<li data-description="This example demonstrates how to create a widget containing a group of buttons"> |
|
|
198 |
<a href="button-group.html">Managing groups of buttons with button-group</a> |
|
|
199 |
</li> |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
</ul> |
|
|
203 |
</div> |
|
|
204 |
</div> |
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
</div> |
|
|
209 |
</div> |
|
|
210 |
</div> |
|
|
211 |
</div> |
|
|
212 |
|
|
|
213 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
214 |
<script>prettyPrint();</script> |
|
|
215 |
|
|
|
216 |
<script> |
|
|
217 |
YUI.Env.Tests = { |
|
|
218 |
examples: [], |
|
|
219 |
project: '../assets', |
|
|
220 |
assets: '../assets/button', |
|
|
221 |
name: 'button-group', |
|
|
222 |
title: 'Managing groups of buttons with button-group', |
|
|
223 |
newWindow: '', |
|
|
224 |
auto: false |
|
|
225 |
}; |
|
|
226 |
YUI.Env.Tests.examples.push('cssbutton'); |
|
|
227 |
YUI.Env.Tests.examples.push('button-plugin'); |
|
|
228 |
YUI.Env.Tests.examples.push('button-basic'); |
|
|
229 |
YUI.Env.Tests.examples.push('button-group'); |
|
|
230 |
|
|
|
231 |
</script> |
|
|
232 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
</body> |
|
|
237 |
</html> |