src/cm/media/js/lib/yui/yui_3.10.3/docs/node/node-style.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: Node Styling</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>
    

            <h1>Example: Node Styling</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><link href="../assets/node/node.css" rel="stylesheet" type="text/css">
<div class="intro">
    <p>This example shows how to style an element using Node.</p>
</div>

<div class="example">
<style>
.example #demo {
    background-color: #D4D8EB;
    border: 1px solid #9EA8C6;
    border-radius: 3px 3px 3px 3px;
    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
    width: 20em;
    margin-bottom: 1em;
}
.example #demo em{
    font-size: 150%;
    font-style: normal;
    margin-right: 0.3em;
}
.example dt {
    font-weight: normal;
}
.example dd {
    font-size: 150%;
    line-height: 0.5em;
}
</style>

<div id="demo">
    <p><em>Click me</em> to change my text color and show some style information.</p>
</div>
<dl>
    <dt>style.color</dt>
    <dd>black</dd>
    <dt>computedStyle.color</dt>
    <dd>rgb(0, 0, 0)</dd>
</dl>

<script type="text/javascript">
YUI().use('node', function(Y) {
    var onClick = function(e) {
        var node = e.currentTarget;
            node.setStyle('color', 'red');
            var styleColor = node.getStyle('color'),
                computedColor = node.getComputedStyle('color');

            Y.one('.example dl').setContent('<dt>style.color</dt><dd>' +
            styleColor + '</dd>' +
            '<dt>computedStyle.color</dt><dd>' +
            computedColor + '</dd>');
    };

    Y.one('#demo').on('click', onClick);
});
</script>

</div>

<h2>Setting up the HTML</h2>
<p>First we need some HTML to work with.</p>
<pre class="code prettyprint">&lt;div id=&quot;demo&quot;&gt;
    &lt;p&gt;Click me to change my color and show some style information.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;</pre>

<h2>Using Style Methods</h2>
<p>In this example, we will set the node's color and compare the style and computedStyle values when our demo node is clicked.</p>
<pre class="code prettyprint">var onClick = function(e) {
    var node = e.currentTarget;
        node.setStyle(&#x27;color&#x27;, &#x27;red&#x27;);
        var styleColor = node.getStyle(&#x27;color&#x27;),
            computedColor = node.getComputedStyle(&#x27;color&#x27;);

        Y.one(&#x27;.example dl&#x27;).setContent(&#x27;&lt;dt&gt;style.color&lt;&#x2F;dt&gt;&lt;dd&gt;&#x27; +
        styleColor + &#x27;&lt;&#x2F;dd&gt;&#x27; +
        &#x27;&lt;dt&gt;computedStyle.color&lt;&#x2F;dt&gt;&lt;dd&gt;&#x27; +
        computedColor + &#x27;&lt;&#x2F;dd&gt;&#x27;);
};</pre>


<p>The last step is to assign the click handler.</p>
<pre class="code prettyprint">Y.one(&#x27;#demo&#x27;).on(&#x27;click&#x27;, onClick);</pre>


<h2>Complete Example Source</h2>
<pre class="code prettyprint">&lt;style&gt;
.example #demo {
    background-color: #D4D8EB;
    border: 1px solid #9EA8C6;
    border-radius: 3px 3px 3px 3px;
    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
    width: 20em;
    margin-bottom: 1em;
}
.example #demo em{
    font-size: 150%;
    font-style: normal;
    margin-right: 0.3em;
}
.example dt {
    font-weight: normal;
}
.example dd {
    font-size: 150%;
    line-height: 0.5em;
}
&lt;&#x2F;style&gt;

&lt;div id=&quot;demo&quot;&gt;
    &lt;p&gt;&lt;em&gt;Click me&lt;&#x2F;em&gt; to change my text color and show some style information.&lt;&#x2F;p&gt;
&lt;&#x2F;div&gt;
&lt;dl&gt;
    &lt;dt&gt;style.color&lt;&#x2F;dt&gt;
    &lt;dd&gt;black&lt;&#x2F;dd&gt;
    &lt;dt&gt;computedStyle.color&lt;&#x2F;dt&gt;
    &lt;dd&gt;rgb(0, 0, 0)&lt;&#x2F;dd&gt;
&lt;&#x2F;dl&gt;

&lt;script type=&quot;text&#x2F;javascript&quot;&gt;
YUI().use(&#x27;node&#x27;, function(Y) {
    var onClick = function(e) {
        var node = e.currentTarget;
            node.setStyle(&#x27;color&#x27;, &#x27;red&#x27;);
            var styleColor = node.getStyle(&#x27;color&#x27;),
                computedColor = node.getComputedStyle(&#x27;color&#x27;);

            Y.one(&#x27;.example dl&#x27;).setContent(&#x27;&lt;dt&gt;style.color&lt;&#x2F;dt&gt;&lt;dd&gt;&#x27; +
            styleColor + &#x27;&lt;&#x2F;dd&gt;&#x27; +
            &#x27;&lt;dt&gt;computedStyle.color&lt;&#x2F;dt&gt;&lt;dd&gt;&#x27; +
            computedColor + &#x27;&lt;&#x2F;dd&gt;&#x27;);
    };

    Y.one(&#x27;#demo&#x27;).on(&#x27;click&#x27;, onClick);
});
&lt;&#x2F;script&gt;</pre>

</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="Using selectors and property accessors with Node.">
                                            <a href="properties.html">Set and Get Properties</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Using DOM methods with Node.">
                                            <a href="dom-node.html">DOM Methods</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Building a simple store and shopping cart.">
                                            <a href="store.html">DOM Methods - Store</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Listening for DOM events with Node instances.">
                                            <a href="events.html">Handling DOM Events</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="NodeList provides Node functionality for manipulating multiple nodes at once.">
                                            <a href="nodelist.html">Using NodeList - Simple</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="How to use multiple NodeList features to build a simple game.">
                                            <a href="ducks.html">Using NodeList - Ducks Game</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Using a single event listener to handle events on multiple nodes.">
                                            <a href="node-evt-delegation.html">Delegating Node Events</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="This example demonstrates how to position an element in page coordinates.">
                                            <a href="node-xy.html">Node Positioning</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="This example demonstrates how to set styles and get style information.">
                                            <a href="node-style.html">Node Styling</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="This example demonstrates how to insert content into a Node.">
                                            <a href="node-insert.html">Adding Node Content - Burger Builder</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="This example demonstrates how to show and hide a Node.">
                                            <a href="node-view.html">Showing and Hiding</a>
                                        </li>
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples That Use This Component</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                        <li data-description="Creating an accessible toolbar using the Focus Manager Node Plugin and Node&#x27;s support for the WAI-ARIA Roles and States.">
                                            <a href="../node-focusmanager/node-focusmanager-toolbar.html">Accessible Toolbar</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event&#x27;s delegation support and mouseenter event, along with the Overlay widget and Node&#x27;s support for the WAI-ARIA Roles and States.">
                                            <a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Use the Event Utility to attach simple DOM event handlers.">
                                            <a href="../event/basic-example.html">Simple DOM Events</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Example Photo Browser application.">
                                            <a href="../dd/photo-browser.html">Photo Browser</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
                                            <a href="../dd/portal-drag.html">Portal Style Example</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Use IO to request XML data from a remote web service.">
                                            <a href="../io/weather.html">Request XML data from Yahoo! Weather</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Use IO to make a cross-domain request to Yahoo! Pipes, returning data from disparate sources.">
                                            <a href="../io/xdr.html">Request JSON using Yahoo! Pipes</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/node',
    name: 'node-style',
    title: 'Node Styling',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('properties');
YUI.Env.Tests.examples.push('dom-node');
YUI.Env.Tests.examples.push('store');
YUI.Env.Tests.examples.push('events');
YUI.Env.Tests.examples.push('nodelist');
YUI.Env.Tests.examples.push('ducks');
YUI.Env.Tests.examples.push('node-evt-delegation');
YUI.Env.Tests.examples.push('node-xy');
YUI.Env.Tests.examples.push('node-style');
YUI.Env.Tests.examples.push('node-insert');
YUI.Env.Tests.examples.push('node-view');
YUI.Env.Tests.examples.push('node-focusmanager-toolbar');
YUI.Env.Tests.examples.push('node-focusmanager-button');
YUI.Env.Tests.examples.push('basic-example');
YUI.Env.Tests.examples.push('photo-browser');
YUI.Env.Tests.examples.push('portal-drag');
YUI.Env.Tests.examples.push('weather');
YUI.Env.Tests.examples.push('xdr');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>