<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example: Enhancing <button> nodes with button-plugin</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<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>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>Example: Enhancing <button> nodes with button-plugin</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<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>
<p>This example uses 3 different ways of creating plugged node elements. Choose the one you are most comfortable with.</p>
</div>
<div class="example">
<button id="myButton">A simple push button</button>
<button id="myEventButton">Toggle 'disabled' state of >></button>
<button id="myDisabledButton">Disabled</button>
<script>
YUI().use('button-plugin', 'cssbutton', function(Y){
// A basic push button
Y.one('#myButton').plug(Y.Plugin.Button);
// A disabled button
var disabledButton = Y.one('#myDisabledButton');
disabledButton.plug(Y.Plugin.Button, {
disabled: true
});
disabledButton.on('click', function(){
var label = this.get('label');
alert("My label is '" + label + "'");
});
// An event button, listening for a click
var eventButton = Y.Plugin.Button.createNode({
srcNode:'#myEventButton'
});
eventButton.on('click', function(){
var disabled = disabledButton.get('disabled'),
newLabel = disabled ? 'Not disabled' : 'Disabled';
disabledButton.set('label', newLabel).set('disabled', !disabled);
});
});
</script>
</div>
<h4 id="source-html">Source: HTML</h4>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code><body></code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre>
<pre class="code prettyprint"><button id="myButton">A simple push button</button>
<button id="myEventButton">Toggle 'disabled' state of >></button>
<button id="myDisabledButton">Disabled</button></pre>
<h4 id="source-javascript">Source: JavaScript</h4>
<pre class="code prettyprint">YUI().use('button-plugin', 'cssbutton', function(Y){
// A basic push button
Y.one('#myButton').plug(Y.Plugin.Button);
// A disabled button
var disabledButton = Y.one('#myDisabledButton');
disabledButton.plug(Y.Plugin.Button, {
disabled: true
});
disabledButton.on('click', function(){
var label = this.get('label');
alert("My label is '" + label + "'");
});
// An event button, listening for a click
var eventButton = Y.Plugin.Button.createNode({
srcNode:'#myEventButton'
});
eventButton.on('click', function(){
var disabled = disabledButton.get('disabled'),
newLabel = disabled ? 'Not disabled' : 'Disabled';
disabledButton.set('label', newLabel).set('disabled', !disabled);
});
});</pre>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#source-html">Source: HTML</a>
</li>
<li>
<a href="#source-javascript">Source: JavaScript</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="This example shows how you can easily style button and non-button DOM elements to appear as buttons">
<a href="cssbutton.html">Styling elements with cssbutton</a>
</li>
<li data-description="This example shows a simple, light solution to enhance <button> nodes">
<a href="button-plugin.html">Enhancing <button> nodes with button-plugin</a>
</li>
<li data-description="This example demonstrates how to create button widgets">
<a href="button-basic.html">Basic button widgets</a>
</li>
<li data-description="This example demonstrates how to create a widget containing a group of buttons">
<a href="button-group.html">Managing groups of buttons with button-group</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/button',
name: 'button-plugin',
title: 'Enhancing <button> nodes with button-plugin',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('cssbutton');
YUI.Env.Tests.examples.push('button-plugin');
YUI.Env.Tests.examples.push('button-basic');
YUI.Env.Tests.examples.push('button-group');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>