src/cm/media/js/lib/yui/yui_3.10.3/docs/graphics/graphics-drag.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 drag with graphic object</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: Basic drag with graphic object</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><style scoped>
#custom-doc { width: 95%; min-width: 950px; }
#pagetitle {background-image: url(../../assets/bg_hd.gif);}
#mygraphiccontainer {
    position: relative;
    width: 700px;
    height:200px;
}
</style>
<div class="intro">
<p>
This example shows how to drag a Shape instance. When using <code>DD-Drag</code>, you normally assign an HTMLElement to the Drag's <code>node</code> attribute. Since Shape instances act as a normalization layer across browsers, you never directly interact with their
underlying Dom elements. This is true when using Drag as well. When creating a Drag, assign the Shape instance to the Drag's <code>node</code> attribute.
a shape.
</p>
</div>
<div class="example">
<div id="mygraphiccontainer"></div>
<script>
    YUI().use('graphics', 'dd-drag', function (Y) 
    { 
        var mygraphic = new Y.Graphic({render: "#mygraphiccontainer"}); 
        var myrect = mygraphic.addShape({
            type: "rect",
            stroke: {
                color:"#000",
                weight: 1
            },
            fill: {
                color: "#fc0"
            },
            width:40,
            height:50
        });
    
        var mydrag = new Y.DD.Drag({
            node: myrect
        });
    });
</script>

</div>

<h2>HTML</h2>
<pre class="code prettyprint">&lt;div id=&quot;mygraphiccontainer&quot;&gt;&lt;&#x2F;div&gt;</pre>


<h2>CSS</h2>
<pre class="code prettyprint">#mygraphiccontainer {
    position: relative;
    width: 700px;
    height:200px;
}</pre>


<h2>Javascript</h2>

<p>Create a <code>Graphic</code> instance.</p>
<pre class="code prettyprint">var mygraphic = new Y.Graphic({render: &quot;#mygraphiccontainer&quot;});</pre>


<p>Create a <code>Rect</code> instance with the <code>addShape</code> method.</p>
<pre class="code prettyprint">var myrect = mygraphic.addShape({
    type: &quot;rect&quot;,
    stroke: {
        color:&quot;#000&quot;,
        weight: 1
    },
    fill: {
        color: &quot;#fc0&quot;
    },
    width:40,
    height:50
});</pre>


<p>Create a drag instance for the shape.</p>

<pre class="code prettyprint">var mydrag = new Y.DD.Drag({
    node: myrect
});</pre>


<h2>Complete Example Source</h2>

<pre class="code prettyprint">&lt;div id=&quot;mygraphiccontainer&quot;&gt;&lt;&#x2F;div&gt;
&lt;script&gt;
    YUI().use(&#x27;graphics&#x27;, &#x27;dd-drag&#x27;, function (Y) 
    { 
        var mygraphic = new Y.Graphic({render: &quot;#mygraphiccontainer&quot;}); 
        var myrect = mygraphic.addShape({
            type: &quot;rect&quot;,
            stroke: {
                color:&quot;#000&quot;,
                weight: 1
            },
            fill: {
                color: &quot;#fc0&quot;
            },
            width:40,
            height:50
        });
    
        var mydrag = new Y.DD.Drag({
            node: myrect
        });
    });
&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="Shows how to create a Graphic instance and add shapes.">
                                            <a href="graphics-simple.html">Basic Graphics Implementation</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to draw lines and polygons.">
                                            <a href="graphics-path.html">Basic Path</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to create linear and radial gradient fills.">
                                            <a href="graphics-gradients.html">Create Gradient Fills</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to add drag to a shape.">
                                            <a href="graphics-drag.html">Basic drag with graphic object</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to apply transforms to shape.">
                                            <a href="graphics-transforms.html">Using Transforms</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows how to use a custom shape with the Graphics module.">
                                            <a href="graphics-customshape.html">Custom Shape</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows to use the graphics api to draw a realistic glass.">
                                            <a href="graphics-muddyglass.html">Transparent Glass with Shadow</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Shows to use the graphics api to draw a violin.">
                                            <a href="graphics-violin.html">Complex Drawing: Violin</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="This example demonstrates animating an element along a curved path using bezier control points.">
                                            <a href="../anim/curve.html">Animating Along a Curved Path</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/graphics',
    name: 'graphics-drag',
    title: 'Basic drag with graphic object',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('graphics-simple');
YUI.Env.Tests.examples.push('graphics-path');
YUI.Env.Tests.examples.push('graphics-gradients');
YUI.Env.Tests.examples.push('graphics-drag');
YUI.Env.Tests.examples.push('graphics-transforms');
YUI.Env.Tests.examples.push('graphics-customshape');
YUI.Env.Tests.examples.push('graphics-muddyglass');
YUI.Env.Tests.examples.push('graphics-violin');
YUI.Env.Tests.examples.push('curve');

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



</body>
</html>