proxy.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>dd <span class="subtitle">3.00PR1</span></h3>
<p>
> proxy.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre> <span class="c">/**</span>
<span class="c"> * The Drag & Drop Utility allows you to create a draggable interface efficiently, buffering you from browser-level abnormalities and enabling you to focus on the interesting logic surrounding your particular implementation. This component enables you to create a variety of standard draggable objects with just a few lines of code and then, using its extensive API, add your own specific implementation logic.</span>
<span class="c"> * @module dd</span>
<span class="c"> * @submodule dd-proxy</span>
<span class="c"> */</span>
<span class="c">/**</span>
<span class="c"> * This class extends dd-drag to allow for creating a proxy drag node, instead of dragging the original node.</span>
<span class="c"> * @class Proxy</span>
<span class="c"> * @extends Drag</span>
<span class="c"> * @constructor</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">DDM</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DD</span><span class="o">.</span><span class="nx">DDM</span><span class="o">,</span>
<span class="nx">NODE</span> <span class="o">=</span> <span class="s1">'node'</span><span class="o">,</span>
<span class="nx">DRAG_NODE</span> <span class="o">=</span> <span class="s1">'dragNode'</span><span class="o">,</span>
<span class="nx">PROXY</span> <span class="o">=</span> <span class="s1">'proxy'</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">Proxy</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="nx">Proxy</span><span class="o">.</span><span class="nx">superclass</span><span class="o">.</span><span class="nx">constructor</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">};</span>
<span class="nx">Proxy</span><span class="o">.</span><span class="nx">NAME</span> <span class="o">=</span> <span class="s1">'dragProxy'</span><span class="o">;</span>
<span class="nx">Proxy</span><span class="o">.</span><span class="nx">ATTRS</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * @attribute moveOnEnd</span>
<span class="c"> * @description Move the original node at the end of the drag. Default: true</span>
<span class="c"> * @type Boolean</span>
<span class="c"> */</span>
<span class="nx">moveOnEnd</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">value</span><span class="o">:</span> <span class="kc">true</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @attribute resizeFrame</span>
<span class="c"> * @description Make the Proxy node assume the size of the original node. Default: true</span>
<span class="c"> * @type Boolean</span>
<span class="c"> */</span>
<span class="nx">resizeFrame</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">value</span><span class="o">:</span> <span class="kc">true</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @attribute proxy</span>
<span class="c"> * @description Make this Draggable instance a Proxy instance. Default: false</span>
<span class="c"> * @type Boolean</span>
<span class="c"> */</span>
<span class="nx">proxy</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">writeOnce</span><span class="o">:</span> <span class="kc">true</span><span class="o">,</span>
<span class="nx">value</span><span class="o">:</span> <span class="kc">false</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @attribute positionProxy</span>
<span class="c"> * @description Make the Proxy node appear in the same place as the original node. Default: true</span>
<span class="c"> * @type Boolean</span>
<span class="c"> */</span>
<span class="nx">positionProxy</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">value</span><span class="o">:</span> <span class="kc">true</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @attribute borderStyle</span>
<span class="c"> * @description The default border style for the border of the proxy. Default: 1px solid #808080</span>
<span class="c"> * @type Boolean</span>
<span class="c"> */</span>
<span class="nx">borderStyle</span><span class="o">:</span> <span class="o">{</span>
<span class="nx">value</span><span class="o">:</span> <span class="s1">'1px solid #808080'</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">proto</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * @private</span>
<span class="c"> * @method _createFrame</span>
<span class="c"> * @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value</span>
<span class="c"> */</span>
<span class="nx">_createFrame</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">DDM</span><span class="o">.</span><span class="nx">_proxy</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">DDM</span><span class="o">.</span><span class="nx">_proxy</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">create</span><span class="o">(</span><span class="s1">'<div></div>'</span><span class="o">);</span>
<span class="nx">p</span><span class="o">.</span><span class="nx">setStyles</span><span class="o">({</span>
<span class="nx">position</span><span class="o">:</span> <span class="s1">'absolute'</span><span class="o">,</span>
<span class="nx">display</span><span class="o">:</span> <span class="s1">'none'</span><span class="o">,</span>
<span class="nx">zIndex</span><span class="o">:</span> <span class="s1">'999'</span><span class="o">,</span>
<span class="nx">top</span><span class="o">:</span> <span class="s1">'-999px'</span><span class="o">,</span>
<span class="nx">left</span><span class="o">:</span> <span class="s1">'-999px'</span><span class="o">,</span>
<span class="nx">border</span><span class="o">:</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'borderStyle'</span><span class="o">)</span>
<span class="o">});</span>
<span class="k">var</span> <span class="nx">b</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'body'</span><span class="o">);</span>
<span class="nx">b</span><span class="o">.</span><span class="nx">insertBefore</span><span class="o">(</span><span class="nx">p</span><span class="o">,</span> <span class="nx">b</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'firstChild'</span><span class="o">));</span>
<span class="nx">p</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="s1">'id'</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="nx">p</span><span class="o">));</span>
<span class="nx">p</span><span class="o">.</span><span class="nx">addClass</span><span class="o">(</span><span class="nx">DDM</span><span class="o">.</span><span class="nx">CSS_PREFIX</span> <span class="o">+</span> <span class="s1">'-proxy'</span><span class="o">);</span>
<span class="nx">DDM</span><span class="o">.</span><span class="nx">_proxy</span> <span class="o">=</span> <span class="nx">p</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @private</span>
<span class="c"> * @method _setFrame</span>
<span class="c"> * @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.</span>
<span class="c"> * If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.</span>
<span class="c"> */</span>
<span class="nx">_setFrame</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">n</span> <span class="o">=</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">NODE</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'resizeFrame'</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">DDM</span><span class="o">.</span><span class="nx">_proxy</span><span class="o">.</span><span class="nx">setStyles</span><span class="o">({</span>
<span class="nx">height</span><span class="o">:</span> <span class="nx">n</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'offsetHeight'</span><span class="o">)</span> <span class="o">+</span> <span class="s1">'px'</span><span class="o">,</span>
<span class="nx">width</span><span class="o">:</span> <span class="nx">n</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'offsetWidth'</span><span class="o">)</span> <span class="o">+</span> <span class="s1">'px'</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">).</span><span class="nx">setStyles</span><span class="o">({</span>
<span class="nx">visibility</span><span class="o">:</span> <span class="s1">'hidden'</span><span class="o">,</span>
<span class="nx">display</span><span class="o">:</span> <span class="s1">'block'</span><span class="o">,</span>
<span class="nx">border</span><span class="o">:</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'borderStyle'</span><span class="o">)</span>
<span class="o">});</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'positionProxy'</span><span class="o">))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">).</span><span class="nx">setXY</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">nodeXY</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">).</span><span class="nx">setStyle</span><span class="o">(</span><span class="s1">'visibility'</span><span class="o">,</span> <span class="s1">'visible'</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @private</span>
<span class="c"> * @method initializer</span>
<span class="c"> * @description Lifecycle method</span>
<span class="c"> */</span>
<span class="nx">initializer</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">PROXY</span><span class="o">))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_createFrame</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @method start</span>
<span class="c"> * @description Starts the drag operation and sets the dragNode config option.</span>
<span class="c"> */</span>
<span class="nx">start</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'lock'</span><span class="o">))</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">PROXY</span><span class="o">))</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">).</span><span class="nx">compareTo</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">NODE</span><span class="o">)))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">,</span> <span class="nx">DDM</span><span class="o">.</span><span class="nx">_proxy</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">Proxy</span><span class="o">.</span><span class="nx">superclass</span><span class="o">.</span><span class="nx">start</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">PROXY</span><span class="o">))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_setFrame</span><span class="o">();</span>
<span class="o">}</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * @method end</span>
<span class="c"> * @description Ends the drag operation, if moveOnEnd is set it will position the Drag Element to the new location of the proxy.</span>
<span class="c"> */</span>
<span class="nx">end</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">PROXY</span><span class="o">)</span> <span class="o">&&</span> <span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'dragging'</span><span class="o">))</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'moveOnEnd'</span><span class="o">))</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">NODE</span><span class="o">).</span><span class="nx">setXY</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="nx">lastXY</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">this</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">DRAG_NODE</span><span class="o">).</span><span class="nx">setStyle</span><span class="o">(</span><span class="s1">'display'</span><span class="o">,</span> <span class="s1">'none'</span><span class="o">);</span>
<span class="o">}</span>
<span class="nx">Proxy</span><span class="o">.</span><span class="nx">superclass</span><span class="o">.</span><span class="nx">end</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">extend</span><span class="o">(</span><span class="nx">Proxy</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DD</span><span class="o">.</span><span class="nx">Drag</span><span class="o">,</span> <span class="nx">proto</span><span class="o">);</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DD</span><span class="o">.</span><span class="nx">Drag</span> <span class="o">=</span> <span class="nx">Proxy</span><span class="o">;</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>