2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('dd-proxy', function(Y) {
10
* 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.
15
* This class extends dd-drag to allow for creating a proxy drag node, instead of dragging the original node.
22
DRAG_NODE = 'dragNode',
26
var Proxy = function() {
27
Proxy.superclass.constructor.apply(this, arguments);
31
Proxy.NAME = 'dragProxy';
35
* @attribute moveOnEnd
36
* @description Move the original node at the end of the drag. Default: true
43
* @attribute resizeFrame
44
* @description Make the Proxy node assume the size of the original node. Default: true
52
* @description Make this Draggable instance a Proxy instance. Default: false
60
* @attribute positionProxy
61
* @description Make the Proxy node appear in the same place as the original node. Default: true
68
* @attribute borderStyle
69
* @description The default border style for the border of the proxy. Default: 1px solid #808080
73
value: '1px solid #808080'
80
* @method _createFrame
81
* @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
83
_createFrame: function() {
86
var p = Y.Node.create('<div></div>');
94
border: this.get('borderStyle')
97
var b = Y.Node.get('body');
98
b.insertBefore(p, b.get('firstChild'));
99
p.set('id', Y.stamp(p));
100
p.addClass(DDM.CSS_PREFIX + '-proxy');
107
* @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
108
* If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
110
_setFrame: function() {
111
var n = this.get(NODE);
112
if (this.get('resizeFrame')) {
113
DDM._proxy.setStyles({
114
height: n.get('offsetHeight') + 'px',
115
width: n.get('offsetWidth') + 'px'
118
this.get(DRAG_NODE).setStyles({
119
visibility: 'hidden',
121
border: this.get('borderStyle')
124
if (this.get('positionProxy')) {
125
this.get(DRAG_NODE).setXY(this.nodeXY);
127
this.get(DRAG_NODE).setStyle('visibility', 'visible');
131
* @method initializer
132
* @description Lifecycle method
134
initializer: function() {
135
if (this.get(PROXY)) {
141
* @description Starts the drag operation and sets the dragNode config option.
144
if (!this.get('lock')) {
145
if (this.get(PROXY)) {
146
if (this.get(DRAG_NODE).compareTo(this.get(NODE))) {
147
this.set(DRAG_NODE, DDM._proxy);
151
Proxy.superclass.start.apply(this);
152
if (this.get(PROXY)) {
158
* @description Ends the drag operation, if moveOnEnd is set it will position the Drag Element to the new location of the proxy.
161
if (this.get(PROXY) && this.get('dragging')) {
162
if (this.get('moveOnEnd')) {
163
this.get(NODE).setXY(this.lastXY);
165
this.get(DRAG_NODE).setStyle('display', 'none');
167
Proxy.superclass.end.apply(this);
171
Y.extend(Proxy, Y.DD.Drag, proto);
172
//Set this new class as DD.Drag for other extensions
177
}, '3.0.0pr1' ,{requires:['dd-ddm', 'dd-drag'], skinnable:false});