|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Enhancing <button> nodes with button-plugin</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: Enhancing <button> nodes with button-plugin</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p>In this example, we'll look at a few ways to create buttons using the <code>'button-plugin'</code> module, and use the <code>'cssbutton'</code> module for basic styles.</p> |
|
|
32 |
<p>This example uses 3 different ways of creating plugged node elements. Choose the one you are most comfortable with.</p> |
|
|
33 |
</div> |
|
|
34 |
|
|
|
35 |
<div class="example"> |
|
|
36 |
<button id="myButton">A simple push button</button> |
|
|
37 |
|
|
|
38 |
<button id="myEventButton">Toggle 'disabled' state of >></button> |
|
|
39 |
|
|
|
40 |
<button id="myDisabledButton">Disabled</button> |
|
|
41 |
|
|
|
42 |
<script> |
|
|
43 |
YUI().use('button-plugin', 'cssbutton', function(Y){ |
|
|
44 |
|
|
|
45 |
// A basic push button |
|
|
46 |
Y.one('#myButton').plug(Y.Plugin.Button); |
|
|
47 |
|
|
|
48 |
|
|
|
49 |
// A disabled button |
|
|
50 |
var disabledButton = Y.one('#myDisabledButton'); |
|
|
51 |
disabledButton.plug(Y.Plugin.Button, { |
|
|
52 |
disabled: true |
|
|
53 |
}); |
|
|
54 |
|
|
|
55 |
disabledButton.on('click', function(){ |
|
|
56 |
var label = this.get('label'); |
|
|
57 |
alert("My label is '" + label + "'"); |
|
|
58 |
}); |
|
|
59 |
|
|
|
60 |
// An event button, listening for a click |
|
|
61 |
var eventButton = Y.Plugin.Button.createNode({ |
|
|
62 |
srcNode:'#myEventButton' |
|
|
63 |
}); |
|
|
64 |
|
|
|
65 |
eventButton.on('click', function(){ |
|
|
66 |
var disabled = disabledButton.get('disabled'), |
|
|
67 |
newLabel = disabled ? 'Not disabled' : 'Disabled'; |
|
|
68 |
|
|
|
69 |
disabledButton.set('label', newLabel).set('disabled', !disabled); |
|
|
70 |
}); |
|
|
71 |
}); |
|
|
72 |
</script> |
|
|
73 |
</div> |
|
|
74 |
|
|
|
75 |
<h4 id="source-html">Source: HTML</h4> |
|
|
76 |
<p> |
|
|
77 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
78 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
79 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
80 |
</p> |
|
|
81 |
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre> |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
<pre class="code prettyprint"><button id="myButton">A simple push button</button> |
|
|
85 |
|
|
|
86 |
<button id="myEventButton">Toggle 'disabled' state of >></button> |
|
|
87 |
|
|
|
88 |
<button id="myDisabledButton">Disabled</button></pre> |
|
|
89 |
|
|
|
90 |
|
|
|
91 |
<h4 id="source-javascript">Source: JavaScript</h4> |
|
|
92 |
<pre class="code prettyprint">YUI().use('button-plugin', 'cssbutton', function(Y){ |
|
|
93 |
|
|
|
94 |
// A basic push button |
|
|
95 |
Y.one('#myButton').plug(Y.Plugin.Button); |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
// A disabled button |
|
|
99 |
var disabledButton = Y.one('#myDisabledButton'); |
|
|
100 |
disabledButton.plug(Y.Plugin.Button, { |
|
|
101 |
disabled: true |
|
|
102 |
}); |
|
|
103 |
|
|
|
104 |
disabledButton.on('click', function(){ |
|
|
105 |
var label = this.get('label'); |
|
|
106 |
alert("My label is '" + label + "'"); |
|
|
107 |
}); |
|
|
108 |
|
|
|
109 |
// An event button, listening for a click |
|
|
110 |
var eventButton = Y.Plugin.Button.createNode({ |
|
|
111 |
srcNode:'#myEventButton' |
|
|
112 |
}); |
|
|
113 |
|
|
|
114 |
eventButton.on('click', function(){ |
|
|
115 |
var disabled = disabledButton.get('disabled'), |
|
|
116 |
newLabel = disabled ? 'Not disabled' : 'Disabled'; |
|
|
117 |
|
|
|
118 |
disabledButton.set('label', newLabel).set('disabled', !disabled); |
|
|
119 |
}); |
|
|
120 |
});</pre> |
|
|
121 |
|
|
|
122 |
</div> |
|
|
123 |
</div> |
|
|
124 |
</div> |
|
|
125 |
|
|
|
126 |
<div class="yui3-u-1-4"> |
|
|
127 |
<div class="sidebar"> |
|
|
128 |
|
|
|
129 |
<div id="toc" class="sidebox"> |
|
|
130 |
<div class="hd"> |
|
|
131 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
132 |
</div> |
|
|
133 |
|
|
|
134 |
<div class="bd"> |
|
|
135 |
<ul class="toc"> |
|
|
136 |
<li> |
|
|
137 |
<a href="#source-html">Source: HTML</a> |
|
|
138 |
</li> |
|
|
139 |
<li> |
|
|
140 |
<a href="#source-javascript">Source: JavaScript</a> |
|
|
141 |
</li> |
|
|
142 |
</ul> |
|
|
143 |
</div> |
|
|
144 |
</div> |
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
<div class="sidebox"> |
|
|
149 |
<div class="hd"> |
|
|
150 |
<h2 class="no-toc">Examples</h2> |
|
|
151 |
</div> |
|
|
152 |
|
|
|
153 |
<div class="bd"> |
|
|
154 |
<ul class="examples"> |
|
|
155 |
|
|
|
156 |
|
|
|
157 |
<li data-description="This example shows how you can easily style button and non-button DOM elements to appear as buttons"> |
|
|
158 |
<a href="cssbutton.html">Styling elements with cssbutton</a> |
|
|
159 |
</li> |
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
<li data-description="This example shows a simple, light solution to enhance <button> nodes"> |
|
|
164 |
<a href="button-plugin.html">Enhancing <button> nodes with button-plugin</a> |
|
|
165 |
</li> |
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
<li data-description="This example demonstrates how to create button widgets"> |
|
|
170 |
<a href="button-basic.html">Basic button widgets</a> |
|
|
171 |
</li> |
|
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
|
175 |
<li data-description="This example demonstrates how to create a widget containing a group of buttons"> |
|
|
176 |
<a href="button-group.html">Managing groups of buttons with button-group</a> |
|
|
177 |
</li> |
|
|
178 |
|
|
|
179 |
|
|
|
180 |
</ul> |
|
|
181 |
</div> |
|
|
182 |
</div> |
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
</div> |
|
|
187 |
</div> |
|
|
188 |
</div> |
|
|
189 |
</div> |
|
|
190 |
|
|
|
191 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
192 |
<script>prettyPrint();</script> |
|
|
193 |
|
|
|
194 |
<script> |
|
|
195 |
YUI.Env.Tests = { |
|
|
196 |
examples: [], |
|
|
197 |
project: '../assets', |
|
|
198 |
assets: '../assets/button', |
|
|
199 |
name: 'button-plugin', |
|
|
200 |
title: 'Enhancing <button> nodes with button-plugin', |
|
|
201 |
newWindow: '', |
|
|
202 |
auto: false |
|
|
203 |
}; |
|
|
204 |
YUI.Env.Tests.examples.push('cssbutton'); |
|
|
205 |
YUI.Env.Tests.examples.push('button-plugin'); |
|
|
206 |
YUI.Env.Tests.examples.push('button-basic'); |
|
|
207 |
YUI.Env.Tests.examples.push('button-group'); |
|
|
208 |
|
|
|
209 |
</script> |
|
|
210 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
</body> |
|
|
215 |
</html> |