3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('dd-proxy', function (Y, NAME) {
11 * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
16 * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
24 DRAG_NODE = 'dragNode',
27 P = function(config) {
28 P.superclass.constructor.apply(this, arguments);
38 * @description The Proxy instance will be placed on the Drag instance under the proxy namespace.
47 * @attribute moveOnEnd
48 * @description Move the original node at the end of the drag. Default: true
55 * @attribute hideOnEnd
56 * @description Hide the drag node at the end of the drag. Default: true
63 * @attribute resizeFrame
64 * @description Make the Proxy node assume the size of the original node. Default: true
71 * @attribute positionProxy
72 * @description Make the Proxy node appear in the same place as the original node. Default: true
79 * @attribute borderStyle
80 * @description The default border style for the border of the proxy. Default: 1px solid #808080
84 value: '1px solid #808080'
87 * @attribute cloneNode
88 * @description Should the node be cloned into the proxy for you. Default: false
100 * @description Holds the event handles for setting the proxy
106 * @description Handler for the proxy config attribute
111 Y.on('domready', Y.bind(this._init, this));
117 var h, h1, host = this.get(HOST), dnode = host.get(DRAG_NODE);
118 if (dnode.compareTo(host.get(NODE))) {
120 host.set(DRAG_NODE, DDM._proxy);
123 Y.each(this._hands, function(v) {
126 h = DDM.on('ddm:start', Y.bind(function() {
127 if (DDM.activeDrag === host) {
131 h1 = DDM.on('ddm:end', Y.bind(function() {
132 if (host.get('dragging')) {
133 if (this.get('moveOnEnd')) {
134 host.get(NODE).setXY(host.lastXY);
136 if (this.get('hideOnEnd')) {
137 host.get(DRAG_NODE).setStyle('display', 'none');
139 if (this.get('cloneNode')) {
140 host.get(DRAG_NODE).remove();
141 host.set(DRAG_NODE, DDM._proxy);
145 this._hands = [h, h1];
147 initializer: function() {
150 destructor: function() {
151 var host = this.get(HOST);
152 Y.each(this._hands, function(v) {
155 host.set(DRAG_NODE, host.get(NODE));
158 var host = this.get(HOST),
160 c = n.cloneNode(true);
163 c.setAttribute('id', Y.guid());
164 c.setStyle('position', 'absolute');
165 n.get('parentNode').appendChild(c);
166 host.set(DRAG_NODE, c);
171 Y.namespace('Plugin');
172 Y.extend(P, Y.Base, proto);
173 Y.Plugin.DDProxy = P;
175 //Add a couple of methods to the DDM
181 * @method _createFrame
182 * @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
184 _createFrame: function() {
188 var p = Y.Node.create('<div></div>'),
192 position: 'absolute',
200 p.set('id', Y.guid());
201 p.addClass(DDM.CSS_PREFIX + '-proxy');
210 * @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
211 * If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
213 _setFrame: function(drag) {
214 var n = drag.get(NODE), d = drag.get(DRAG_NODE), ah, cur = 'auto';
216 ah = DDM.activeDrag.get('activeHandle');
218 cur = ah.getStyle('cursor');
221 cur = DDM.get('dragCursor');
225 visibility: 'hidden',
228 border: drag.proxy.get('borderStyle')
231 if (drag.proxy.get('cloneNode')) {
232 d = drag.proxy.clone();
235 if (drag.proxy.get('resizeFrame')) {
237 height: n.get('offsetHeight') + 'px',
238 width: n.get('offsetWidth') + 'px'
242 if (drag.proxy.get('positionProxy')) {
243 d.setXY(drag.nodeXY);
245 d.setStyle('visibility', 'visible');
249 //Create the frame when DOM is ready
250 //Y.on('domready', Y.bind(DDM._createFrame, DDM));
255 }, '3.7.2', {"requires": ["dd-drag"]});