src/cm/media/js/lib/yui/yui_3.10.3/docs/button/button-basic.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Basic button widgets</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: Basic button widgets</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><link rel="stylesheet" href='../../build/cssbutton/cssbutton.css'></link>
<div class="intro">
    <p>In this example, we'll look at a few ways to create button widgets using the <code>&#x27;button&#x27;</code> module and listen for events on one to manipulate an attribute of another.</p>
</div>

<div class="example yui3-skin-sam">
    <button id="myPushButton">This push button</button>
<p>can toggle the <code>pressed</code> attribute of</p>
<button id="myToggleButton">this depressed button :(</button>

<style>
.example {
    text-align:center;
}
.example .yui3-button{
    width: 200px;
}
</style>

    <script>
    YUI().use('button', function(Y){
    
    // A toggle button with a state change listener
    var toggleButton = new Y.ToggleButton({
        srcNode:'#myToggleButton',
        
        // 'after', because 'on' would trigger before the attribute update
        after: {
            'pressedChange': function () {
                var button = this,
                    pressed = button.get('pressed'),
                    newLabel = 'this ' + (pressed ? 'pressed ' : 'depressed') + ' button :' + (pressed ? ')' : '(');
                
                button.set('label', newLabel);
            }
        }
    }).render();
    
    
    var button = new Y.Button({
        srcNode:'#myPushButton',
        on: {
            'click': function(){
                var pressed = toggleButton.get('pressed');
                toggleButton.set('pressed', !pressed);
            }
        }
    }).render();
    
    
});
    </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>&lt;body&gt;</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">&lt;body class=&quot;yui3-skin-sam&quot;&gt; &lt;!-- You need this skin class --&gt;</pre>


<pre class="code prettyprint">&lt;button id=&quot;myPushButton&quot;&gt;This push button&lt;&#x2F;button&gt;
&lt;p&gt;can toggle the &#x60;pressed&#x60; attribute of&lt;&#x2F;p&gt;
&lt;button id=&quot;myToggleButton&quot;&gt;this depressed button :(&lt;&#x2F;button&gt;

&lt;style&gt;
.example {
    text-align:center;
}
.example .yui3-button{
    width: 200px;
}
&lt;&#x2F;style&gt;</pre>


<h4 id="source-javascript">Source: JavaScript</h4>
<pre class="code prettyprint">YUI().use(&#x27;button&#x27;, function(Y){
    
    &#x2F;&#x2F; A toggle button with a state change listener
    var toggleButton = new Y.ToggleButton({
        srcNode:&#x27;#myToggleButton&#x27;,
        
        &#x2F;&#x2F; &#x27;after&#x27;, because &#x27;on&#x27; would trigger before the attribute update
        after: {
            &#x27;pressedChange&#x27;: function () {
                var button = this,
                    pressed = button.get(&#x27;pressed&#x27;),
                    newLabel = &#x27;this &#x27; + (pressed ? &#x27;pressed &#x27; : &#x27;depressed&#x27;) + &#x27; button :&#x27; + (pressed ? &#x27;)&#x27; : &#x27;(&#x27;);
                
                button.set(&#x27;label&#x27;, newLabel);
            }
        }
    }).render();
    
    
    var button = new Y.Button({
        srcNode:&#x27;#myPushButton&#x27;,
        on: {
            &#x27;click&#x27;: function(){
                var pressed = toggleButton.get(&#x27;pressed&#x27;);
                toggleButton.set(&#x27;pressed&#x27;, !pressed);
            }
        }
    }).render();
    
    
});</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 &lt;button&gt; nodes">
                                            <a href="button-plugin.html">Enhancing &lt;button&gt; 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-basic',
    title: 'Basic button widgets',
    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>