2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('dd-proxy', function(Y) {
12 * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
17 * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
25 DRAG_NODE = 'dragNode',
28 P = function(config) {
29 P.superclass.constructor.apply(this, arguments);
39 * @description The Proxy instance will be placed on the Drag instance under the proxy namespace.
48 * @attribute moveOnEnd
49 * @description Move the original node at the end of the drag. Default: true
56 * @attribute hideOnEnd
57 * @description Hide the drag node at the end of the drag. Default: true
64 * @attribute resizeFrame
65 * @description Make the Proxy node assume the size of the original node. Default: true
72 * @attribute positionProxy
73 * @description Make the Proxy node appear in the same place as the original node. Default: true
80 * @attribute borderStyle
81 * @description The default border style for the border of the proxy. Default: 1px solid #808080
85 value: '1px solid #808080'
88 * @attribute cloneNode
89 * @description Should the node be cloned into the proxy for you. Default: false
101 * @description Holds the event handles for setting the proxy
107 * @description Handler for the proxy config attribute
112 Y.on('domready', Y.bind(this._init, this));
118 var h, h1, host = this.get(HOST), dnode = host.get(DRAG_NODE);
119 if (dnode.compareTo(host.get(NODE))) {
121 host.set(DRAG_NODE, DDM._proxy);
124 Y.each(this._hands, function(v) {
127 h = DDM.on('ddm:start', Y.bind(function() {
128 if (DDM.activeDrag === host) {
132 h1 = DDM.on('ddm:end', Y.bind(function() {
133 if (host.get('dragging')) {
134 if (this.get('moveOnEnd')) {
135 host.get(NODE).setXY(host.lastXY);
137 if (this.get('hideOnEnd')) {
138 host.get(DRAG_NODE).setStyle('display', 'none');
140 if (this.get('cloneNode')) {
141 host.get(DRAG_NODE).remove();
142 host.set(DRAG_NODE, DDM._proxy);
146 this._hands = [h, h1];
148 initializer: function() {
151 destructor: function() {
152 var host = this.get(HOST);
153 Y.each(this._hands, function(v) {
156 host.set(DRAG_NODE, host.get(NODE));
159 var host = this.get(HOST),
161 c = n.cloneNode(true);
164 c.setAttribute('id', Y.guid());
165 c.setStyle('position', 'absolute');
166 n.get('parentNode').appendChild(c);
167 host.set(DRAG_NODE, c);
172 Y.namespace('Plugin');
173 Y.extend(P, Y.Base, proto);
174 Y.Plugin.DDProxy = P;
176 //Add a couple of methods to the DDM
182 * @method _createFrame
183 * @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
185 _createFrame: function() {
189 var p = Y.Node.create('<div></div>'),
193 position: 'absolute',
201 p.set('id', Y.guid());
202 p.addClass(DDM.CSS_PREFIX + '-proxy');
211 * @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
212 * If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
214 _setFrame: function(drag) {
215 var n = drag.get(NODE), d = drag.get(DRAG_NODE), ah, cur = 'auto';
217 ah = DDM.activeDrag.get('activeHandle');
219 cur = ah.getStyle('cursor');
222 cur = DDM.get('dragCursor');
226 visibility: 'hidden',
229 border: drag.proxy.get('borderStyle')
232 if (drag.proxy.get('cloneNode')) {
233 d = drag.proxy.clone();
236 if (drag.proxy.get('resizeFrame')) {
238 height: n.get('offsetHeight') + 'px',
239 width: n.get('offsetWidth') + 'px'
243 if (drag.proxy.get('positionProxy')) {
244 d.setXY(drag.nodeXY);
246 d.setStyle('visibility', 'visible');
250 //Create the frame when DOM is ready
251 //Y.on('domready', Y.bind(DDM._createFrame, DDM));
255 }, '3.3.0' ,{requires:['dd-ddm', 'dd-drag'], skinnable:false});