2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('dd-proxy', function (Y, NAME) {
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',
29 P.superclass.constructor.apply(this, arguments);
34 * The Proxy instance will be placed on the Drag instance under the proxy namespace.
48 * Move the original node at the end of the drag. Default: true
49 * @attribute moveOnEnd
56 * Hide the drag node at the end of the drag. Default: true
57 * @attribute hideOnEnd
64 * Make the Proxy node assume the size of the original node. Default: true
65 * @attribute resizeFrame
72 * Make the Proxy node appear in the same place as the original node. Default: true
73 * @attribute positionProxy
80 * The default border style for the border of the proxy. Default: 1px solid #808080
81 * @attribute borderStyle
85 value: '1px solid #808080'
88 * Should the node be cloned into the proxy for you. Default: false
89 * @attribute cloneNode
99 * Holds the event handles for setting the proxy
105 * 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.Array.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.Array.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
179 * Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
183 * @method _createFrame
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');
207 * If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
208 * 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');
221 if (cur === 'auto') {
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));
256 }, '3.13.0', {"requires": ["dd-drag"]});