src/cm/media/js/lib/yui/yui_3.10.3/docs/dd/delegate-plugins.html
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 <!DOCTYPE html>
       
     2 <html lang="en">
       
     3 <head>
       
     4     <meta charset="utf-8">
       
     5     <title>Example: Using Drag Plugins with Delegate</title>
       
     6     <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
       
     7     <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
       
     8     <link rel="stylesheet" href="../assets/css/main.css">
       
     9     <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
       
    10     <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
       
    11     <script src="../../build/yui/yui-min.js"></script>
       
    12     
       
    13 </head>
       
    14 <body>
       
    15 <!--
       
    16 <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>
       
    17 -->
       
    18 <div id="doc">
       
    19     <div id="hd">
       
    20         <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
       
    21     </div>
       
    22     
       
    23         <a href="#toc" class="jump">Jump to Table of Contents</a>
       
    24     
       
    25 
       
    26             <h1>Example: Using Drag Plugins with Delegate</h1>
       
    27     <div class="yui3-g">
       
    28         <div class="yui3-u-3-4">
       
    29             <div id="main">
       
    30                 <div class="content"><div class="intro">
       
    31 <p>This example is the same as the "Drag Delegation with Drop Target" example except we add some plugins.</p>
       
    32 </div>
       
    33 
       
    34 <div class="example">
       
    35     <style>
       
    36     #demo {
       
    37     }
       
    38     #demo ul li {
       
    39         border: 1px solid black;
       
    40         background-color: #8DD5E7;
       
    41         cursor: move;
       
    42         margin: 3px;
       
    43         list-style-type: none;
       
    44         z-index: 2;
       
    45         width: 200px;
       
    46         height: 20px;
       
    47         padding: 2px;
       
    48         zoom: 1;
       
    49     }
       
    50     #play {
       
    51         border: 1px solid black;
       
    52         zoom: 1;
       
    53         padding: 2em;
       
    54     }
       
    55     #drop {
       
    56         border: 1px solid black;
       
    57         background-color: #eee;
       
    58         height: 50px;
       
    59         width: 200px;
       
    60         float: right;
       
    61         bottom: 50px;
       
    62         position: relative;
       
    63     }
       
    64     #drop strong {
       
    65         font-weight: bold;
       
    66     }
       
    67     #drop.yui3-dd-drop-over {
       
    68         background-color: #ccc;
       
    69     }
       
    70     #example-canvas {
       
    71         position: static;
       
    72     }
       
    73 
       
    74 
       
    75 </style>
       
    76 
       
    77 <div id="play">
       
    78 
       
    79     <div id="demo">
       
    80         <ul>
       
    81             <li>Item #1</li>
       
    82             <li>Item #2</li>
       
    83             <li>Item #3</li>
       
    84             <li>Item #4</li>
       
    85             <li>Item #5</li>
       
    86             <li>Item #6</li>
       
    87             <li>Item #7</li>
       
    88             <li>Item #8</li>
       
    89             <li>Item #9</li>
       
    90             <li>Item #10</li>
       
    91         </ul>
       
    92     </div>
       
    93     
       
    94     <div id="drop">Drop on me</div>
       
    95 </div>
       
    96 
       
    97 
       
    98 
       
    99 <script>
       
   100     YUI().use('dd-delegate', 'dd-drop-plugin', 'dd-constrain', 'dd-proxy', function(Y) {
       
   101         var del = new Y.DD.Delegate({
       
   102             container: '#demo',
       
   103             nodes: 'li'
       
   104         });
       
   105 
       
   106         del.on('drag:start', function(e) {
       
   107             e.target.get('node').setStyle('opacity', '.5');
       
   108         });
       
   109         del.on('drag:end', function(e) {
       
   110             e.target.get('node').setStyle('opacity', '1');
       
   111         });
       
   112         
       
   113         del.dd.plug(Y.Plugin.DDConstrained, {
       
   114             constrain2node: '#play'
       
   115         });
       
   116 
       
   117         del.dd.plug(Y.Plugin.DDProxy, {
       
   118             moveOnEnd: false,
       
   119             cloneNode: true
       
   120         });
       
   121 
       
   122         var drop = Y.one('#drop').plug(Y.Plugin.Drop);
       
   123         drop.drop.on('drop:hit', function(e) {
       
   124             drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
       
   125         });
       
   126         
       
   127 
       
   128     });
       
   129 
       
   130 
       
   131 </script>
       
   132 
       
   133 
       
   134 </div>
       
   135 
       
   136 <h3 id="adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</h3>
       
   137 <p><code>DD.Delegate</code> provides a reference to the <code>dd</code> instance so you can plug into the underlying <code>dd</code> with <code>del.dd.plug()</code>.
       
   138 This allows you to use DD plugins on a Delegate instance, as well as provides the ability to write plugins for Delegate itself.
       
   139 </p>
       
   140 
       
   141 <h3 id="constrain-plugin">Constrain Plugin</h3>
       
   142 <p>Here is how you would add the constrain plugin to a <code>DD.Delegate</code> instance.</p>
       
   143 
       
   144 <pre class="code prettyprint">YUI().use(&#x27;dd-delegate&#x27;, &#x27;dd-constrain&#x27;, function(Y) {
       
   145     var del = new Y.DD.Delegate({
       
   146         container: &#x27;#demo&#x27;,
       
   147         nodes: &#x27;li&#x27;
       
   148     });
       
   149 
       
   150     del.dd.plug(Y.Plugin.DDConstrained, {
       
   151         constrain2node: &#x27;#play&#x27;
       
   152     });
       
   153 });</pre>
       
   154 
       
   155 
       
   156 <h3 id="ddproxy-plugin">DDProxy Plugin</h3>
       
   157 <p>Here is how you would add the dd-proxy plugin to a <code>DD.Delegate</code> instance.</p>
       
   158 
       
   159 <pre class="code prettyprint">YUI().use(&#x27;dd-delegate&#x27;, &#x27;dd-proxy&#x27;, function(Y) {
       
   160     var del = new Y.DD.Delegate({
       
   161         container: &#x27;#demo&#x27;,
       
   162         nodes: &#x27;li&#x27;
       
   163     });
       
   164 
       
   165     del.dd.plug(Y.Plugin.DDProxy, {
       
   166         moveOnEnd: false,
       
   167         cloneNode: true
       
   168     });
       
   169 
       
   170 });</pre>
       
   171 
       
   172 
       
   173 <h3 id="full-example-source">Full Example Source</h3>
       
   174 
       
   175 <h4 id="html">HTML</h4>
       
   176 <pre class="code prettyprint">&lt;div id=&quot;play&quot;&gt;
       
   177 
       
   178     &lt;div id=&quot;demo&quot;&gt;
       
   179         &lt;ul&gt;
       
   180             &lt;li&gt;Item #1&lt;&#x2F;li&gt;
       
   181             &lt;li&gt;Item #2&lt;&#x2F;li&gt;
       
   182             &lt;li&gt;Item #3&lt;&#x2F;li&gt;
       
   183             &lt;li&gt;Item #4&lt;&#x2F;li&gt;
       
   184             &lt;li&gt;Item #5&lt;&#x2F;li&gt;
       
   185             &lt;li&gt;Item #6&lt;&#x2F;li&gt;
       
   186             &lt;li&gt;Item #7&lt;&#x2F;li&gt;
       
   187             &lt;li&gt;Item #8&lt;&#x2F;li&gt;
       
   188             &lt;li&gt;Item #9&lt;&#x2F;li&gt;
       
   189             &lt;li&gt;Item #10&lt;&#x2F;li&gt;
       
   190         &lt;&#x2F;ul&gt;
       
   191     &lt;&#x2F;div&gt;
       
   192     
       
   193     &lt;div id=&quot;drop&quot;&gt;Drop on me&lt;&#x2F;div&gt;
       
   194 &lt;&#x2F;div&gt;</pre>
       
   195 
       
   196 <h4 id="css">CSS</h4>
       
   197 <pre class="code prettyprint">#demo {
       
   198 }
       
   199 #demo ul li {
       
   200     border: 1px solid black;
       
   201     background-color: #8DD5E7;
       
   202     cursor: move;
       
   203     margin: 3px;
       
   204     list-style-type: none;
       
   205     z-index: 2;
       
   206     width: 200px;
       
   207     height: 20px;
       
   208     padding: 2px;
       
   209     zoom: 1;
       
   210 }
       
   211 #play {
       
   212     border: 1px solid black;
       
   213     zoom: 1;
       
   214     padding: 2em;
       
   215 }
       
   216 #drop {
       
   217     border: 1px solid black;
       
   218     background-color: #eee;
       
   219     height: 50px;
       
   220     width: 200px;
       
   221     float: right;
       
   222     bottom: 50px;
       
   223     position: relative;
       
   224 }
       
   225 #drop strong {
       
   226     font-weight: bold;
       
   227 }
       
   228 #drop.yui3-dd-drop-over {
       
   229     background-color: #ccc;
       
   230 }
       
   231 #example-canvas {
       
   232     position: static;
       
   233 }</pre>
       
   234 
       
   235 <h4 id="javascript">Javascript</h4>
       
   236 <pre class="code prettyprint">YUI().use(&#x27;dd-delegate&#x27;, &#x27;dd-drop-plugin&#x27;, &#x27;dd-constrain&#x27;, &#x27;dd-proxy&#x27;, function(Y) {
       
   237     var del = new Y.DD.Delegate({
       
   238         container: &#x27;#demo&#x27;,
       
   239         nodes: &#x27;li&#x27;
       
   240     });
       
   241 
       
   242     del.on(&#x27;drag:start&#x27;, function(e) {
       
   243         e.target.get(&#x27;node&#x27;).setStyle(&#x27;opacity&#x27;, &#x27;.5&#x27;);
       
   244     });
       
   245     del.on(&#x27;drag:end&#x27;, function(e) {
       
   246         e.target.get(&#x27;node&#x27;).setStyle(&#x27;opacity&#x27;, &#x27;1&#x27;);
       
   247     });
       
   248     
       
   249     del.dd.plug(Y.Plugin.DDConstrained, {
       
   250         constrain2node: &#x27;#play&#x27;
       
   251     });
       
   252 
       
   253     del.dd.plug(Y.Plugin.DDProxy, {
       
   254         moveOnEnd: false,
       
   255         cloneNode: true
       
   256     });
       
   257 
       
   258     var drop = Y.one(&#x27;#drop&#x27;).plug(Y.Plugin.Drop);
       
   259     drop.drop.on(&#x27;drop:hit&#x27;, function(e) {
       
   260         drop.set(&#x27;innerHTML&#x27;, &#x27;You dropped: &lt;strong&gt;&#x27; + e.drag.get(&#x27;node&#x27;).get(&#x27;innerHTML&#x27;) + &#x27;&lt;&#x2F;strong&gt;&#x27;);
       
   261     });
       
   262     
       
   263 
       
   264 });</pre>
       
   265 
       
   266 </div>
       
   267             </div>
       
   268         </div>
       
   269 
       
   270         <div class="yui3-u-1-4">
       
   271             <div class="sidebar">
       
   272                 
       
   273                     <div id="toc" class="sidebox">
       
   274                         <div class="hd">
       
   275                             <h2 class="no-toc">Table of Contents</h2>
       
   276                         </div>
       
   277 
       
   278                         <div class="bd">
       
   279                             <ul class="toc">
       
   280 <li>
       
   281 <a href="#adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</a>
       
   282 </li>
       
   283 <li>
       
   284 <a href="#constrain-plugin">Constrain Plugin</a>
       
   285 </li>
       
   286 <li>
       
   287 <a href="#ddproxy-plugin">DDProxy Plugin</a>
       
   288 </li>
       
   289 <li>
       
   290 <a href="#full-example-source">Full Example Source</a>
       
   291 <ul class="toc">
       
   292 <li>
       
   293 <a href="#html">HTML</a>
       
   294 </li>
       
   295 <li>
       
   296 <a href="#css">CSS</a>
       
   297 </li>
       
   298 <li>
       
   299 <a href="#javascript">Javascript</a>
       
   300 </li>
       
   301 </ul>
       
   302 </li>
       
   303 </ul>
       
   304                         </div>
       
   305                     </div>
       
   306                 
       
   307 
       
   308                 
       
   309                     <div class="sidebox">
       
   310                         <div class="hd">
       
   311                             <h2 class="no-toc">Examples</h2>
       
   312                         </div>
       
   313 
       
   314                         <div class="bd">
       
   315                             <ul class="examples">
       
   316                                 
       
   317                                     
       
   318                                         <li data-description="A simple drag interaction that doesn&#x27;t require a drop interaction.">
       
   319                                             <a href="simple-drag.html">Simple Drag</a>
       
   320                                         </li>
       
   321                                     
       
   322                                 
       
   323                                     
       
   324                                         <li data-description="How to apply the Drag Plugin to a node.">
       
   325                                             <a href="drag-plugin.html">Drag - Node plugin</a>
       
   326                                         </li>
       
   327                                     
       
   328                                 
       
   329                                     
       
   330                                         <li data-description="A simple proxy drag interaction that doesn&#x27;t require a drop interaction.">
       
   331                                             <a href="proxy-drag.html">Drag - Proxy</a>
       
   332                                         </li>
       
   333                                     
       
   334                                 
       
   335                                     
       
   336                                         <li data-description="How to constrain a draggable Node to another Node&#x27;s region.">
       
   337                                             <a href="constrained-drag.html">Drag - Constrained to a Region</a>
       
   338                                         </li>
       
   339                                     
       
   340                                 
       
   341                                     
       
   342                                         <li data-description="Using interaction groups, this example demonstrates how to tie into the Drag &amp; Drop Utility&#x27;s interesting moments to provide visual affordances for the current drag operation.">
       
   343                                             <a href="groups-drag.html">Drag - Interaction Groups</a>
       
   344                                         </li>
       
   345                                     
       
   346                                 
       
   347                                     
       
   348                                         <li data-description="The use of the drag shim when dragging nodes over other troublesome nodes.">
       
   349                                             <a href="shim-drag.html">Using the Drag Shim</a>
       
   350                                         </li>
       
   351                                     
       
   352                                 
       
   353                                     
       
   354                                         <li data-description="How to use the Drop Target events to code your application.">
       
   355                                             <a href="drop-code.html">Using Drop Based Coding</a>
       
   356                                         </li>
       
   357                                     
       
   358                                 
       
   359                                     
       
   360                                         <li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag.">
       
   361                                             <a href="winscroll.html">Window Scrolling</a>
       
   362                                         </li>
       
   363                                     
       
   364                                 
       
   365                                     
       
   366                                         <li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items.">
       
   367                                             <a href="delegate.html">Drag Delegation</a>
       
   368                                         </li>
       
   369                                     
       
   370                                 
       
   371                                     
       
   372                                         <li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target.">
       
   373                                             <a href="delegate-drop.html">Drag Delegation with a Drop Target</a>
       
   374                                         </li>
       
   375                                     
       
   376                                 
       
   377                                     
       
   378                                         <li data-description="How to use Drag plugins with a DD Delegate based solution.">
       
   379                                             <a href="delegate-plugins.html">Using Drag Plugins with Delegate</a>
       
   380                                         </li>
       
   381                                     
       
   382                                 
       
   383                                     
       
   384                                         <li data-description="This example shows how to make a sortable list using Custom Event Bubbling.">
       
   385                                             <a href="list-drag.html">List Reorder w/Bubbling</a>
       
   386                                         </li>
       
   387                                     
       
   388                                 
       
   389                                     
       
   390                                         <li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling.">
       
   391                                             <a href="scroll-list.html">List Reorder w/Scrolling</a>
       
   392                                         </li>
       
   393                                     
       
   394                                 
       
   395                                     
       
   396                                         <li data-description="How to make an animated node a Drop target.">
       
   397                                             <a href="anim-drop.html">Animated Drop Targets</a>
       
   398                                         </li>
       
   399                                     
       
   400                                 
       
   401                                     
       
   402                                         <li data-description="Example Photo Browser application.">
       
   403                                             <a href="photo-browser.html">Photo Browser</a>
       
   404                                         </li>
       
   405                                     
       
   406                                 
       
   407                                     
       
   408                                         <li data-description="Portal style example using Drag &amp; Drop Event Bubbling and Animation.">
       
   409                                             <a href="portal-drag.html">Portal Style Example</a>
       
   410                                         </li>
       
   411                                     
       
   412                                 
       
   413                                     
       
   414                                 
       
   415                                     
       
   416                                 
       
   417                             </ul>
       
   418                         </div>
       
   419                     </div>
       
   420                 
       
   421 
       
   422                 
       
   423                     <div class="sidebox">
       
   424                         <div class="hd">
       
   425                             <h2 class="no-toc">Examples That Use This Component</h2>
       
   426                         </div>
       
   427 
       
   428                         <div class="bd">
       
   429                             <ul class="examples">
       
   430                                 
       
   431                                     
       
   432                                 
       
   433                                     
       
   434                                 
       
   435                                     
       
   436                                 
       
   437                                     
       
   438                                 
       
   439                                     
       
   440                                 
       
   441                                     
       
   442                                 
       
   443                                     
       
   444                                 
       
   445                                     
       
   446                                 
       
   447                                     
       
   448                                 
       
   449                                     
       
   450                                 
       
   451                                     
       
   452                                 
       
   453                                     
       
   454                                 
       
   455                                     
       
   456                                 
       
   457                                     
       
   458                                 
       
   459                                     
       
   460                                 
       
   461                                     
       
   462                                 
       
   463                                     
       
   464                                         <li data-description="Working with multiple YUI instances.">
       
   465                                             <a href="../yui/yui-multi.html">Multiple Instances</a>
       
   466                                         </li>
       
   467                                     
       
   468                                 
       
   469                                     
       
   470                                         <li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input">
       
   471                                             <a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a>
       
   472                                         </li>
       
   473                                     
       
   474                                 
       
   475                             </ul>
       
   476                         </div>
       
   477                     </div>
       
   478                 
       
   479             </div>
       
   480         </div>
       
   481     </div>
       
   482 </div>
       
   483 
       
   484 <script src="../assets/vendor/prettify/prettify-min.js"></script>
       
   485 <script>prettyPrint();</script>
       
   486 
       
   487 <script>
       
   488 YUI.Env.Tests = {
       
   489     examples: [],
       
   490     project: '../assets',
       
   491     assets: '../assets/dd',
       
   492     name: 'delegate-plugins',
       
   493     title: 'Using Drag Plugins with Delegate',
       
   494     newWindow: '',
       
   495     auto:  false 
       
   496 };
       
   497 YUI.Env.Tests.examples.push('simple-drag');
       
   498 YUI.Env.Tests.examples.push('drag-plugin');
       
   499 YUI.Env.Tests.examples.push('proxy-drag');
       
   500 YUI.Env.Tests.examples.push('constrained-drag');
       
   501 YUI.Env.Tests.examples.push('groups-drag');
       
   502 YUI.Env.Tests.examples.push('shim-drag');
       
   503 YUI.Env.Tests.examples.push('drop-code');
       
   504 YUI.Env.Tests.examples.push('winscroll');
       
   505 YUI.Env.Tests.examples.push('delegate');
       
   506 YUI.Env.Tests.examples.push('delegate-drop');
       
   507 YUI.Env.Tests.examples.push('delegate-plugins');
       
   508 YUI.Env.Tests.examples.push('list-drag');
       
   509 YUI.Env.Tests.examples.push('scroll-list');
       
   510 YUI.Env.Tests.examples.push('anim-drop');
       
   511 YUI.Env.Tests.examples.push('photo-browser');
       
   512 YUI.Env.Tests.examples.push('portal-drag');
       
   513 YUI.Env.Tests.examples.push('yui-multi');
       
   514 YUI.Env.Tests.examples.push('stylesheet-theme');
       
   515 
       
   516 </script>
       
   517 <script src="../assets/yui/test-runner.js"></script>
       
   518 
       
   519 
       
   520 
       
   521 </body>
       
   522 </html>