5
<title>Example: Enhancing <button> nodes with button-plugin</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Enhancing <button> nodes with button-plugin</h1>
18
<a href="#toc" class="jump">Jump to Table of Contents</a>
22
<div class="yui3-u-3-4">
24
<div class="content"><div class="intro">
25
<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>
26
<p>This example uses 3 different ways of creating plugged node elements. Choose the one you are most comfortable with.</p>
30
<button id="myButton">A simple push button</button>
32
<button id="myEventButton">Toggle 'disabled' state of >></button>
34
<button id="myDisabledButton">Disabled</button>
37
YUI().use('button-plugin', 'cssbutton', function(Y){
39
// A basic push button
40
Y.one('#myButton').plug(Y.Plugin.Button);
44
var disabledButton = Y.one('#myDisabledButton');
45
disabledButton.plug(Y.Plugin.Button, {
49
disabledButton.on('click', function(){
50
var label = this.get('label');
51
alert("My label is '" + label + "'");
54
// An event button, listening for a click
55
var eventButton = Y.Plugin.Button.createNode({
56
srcNode:'#myEventButton'
59
eventButton.on('click', function(){
60
var disabled = disabledButton.get('disabled'),
61
newLabel = disabled ? 'Not disabled' : 'Disabled';
63
disabledButton.set('label', newLabel).set('disabled', !disabled);
69
<h4 id="source-html">Source: HTML</h4>
70
<pre class="code prettyprint"><button id="myButton">A simple push button</button>
72
<button id="myEventButton">Toggle 'disabled' state of >></button>
74
<button id="myDisabledButton">Disabled</button></pre>
77
<h4 id="source-javascript">Source: JavaScript</h4>
78
<pre class="code prettyprint">YUI().use('button-plugin', 'cssbutton', function(Y){
80
// A basic push button
81
Y.one('#myButton').plug(Y.Plugin.Button);
84
// A disabled button
85
var disabledButton = Y.one('#myDisabledButton');
86
disabledButton.plug(Y.Plugin.Button, {
90
disabledButton.on('click', function(){
91
var label = this.get('label');
92
alert("My label is '" + label + "'");
95
// An event button, listening for a click
96
var eventButton = Y.Plugin.Button.createNode({
97
srcNode:'#myEventButton'
100
eventButton.on('click', function(){
101
var disabled = disabledButton.get('disabled'),
102
newLabel = disabled ? 'Not disabled' : 'Disabled';
104
disabledButton.set('label', newLabel).set('disabled', !disabled);
112
<div class="yui3-u-1-4">
113
<div class="sidebar">
115
<div id="toc" class="sidebox">
117
<h2 class="no-toc">Table of Contents</h2>
123
<a href="#source-html">Source: HTML</a>
126
<a href="#source-javascript">Source: JavaScript</a>
134
<div class="sidebox">
136
<h2 class="no-toc">Examples</h2>
140
<ul class="examples">
143
<li data-description="This example shows how you can easily style button and non-button DOM elements to appear as buttons">
144
<a href="cssbutton.html">Styling elements with cssbutton</a>
149
<li data-description="This example shows a simple, light solution to enhance <button> nodes">
150
<a href="button-plugin.html">Enhancing <button> nodes with button-plugin</a>
155
<li data-description="This example demonstrates how to create button widgets">
156
<a href="button.html">Basic button widgets</a>
161
<li data-description="This example demonstrates how to create a widget containing a group of buttons">
162
<a href="button-group.html">Managing groups of buttons with button-group</a>
177
<script src="../assets/vendor/prettify/prettify-min.js"></script>
178
<script>prettyPrint();</script>