dd-proxy-debug.js revision 09ab44e129e6795eed34adfc06f7b741034e88a4
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnellYUI.add('dd-proxy', function(Y) {
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * 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.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @module dd
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @submodule dd-proxy
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * This class extends dd-drag to allow for creating a proxy drag node, instead of dragging the original node.
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @class Proxy
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @extends Drag
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @constructor
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell var DDM = Y.DD.DDM,
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell NODE = 'node',
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell DRAG_NODE = 'dragNode',
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell PROXY = 'proxy';
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell var Proxy = function() {
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott Proxy.superclass.constructor.apply(this, arguments);
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell };
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell Proxy.NAME = 'dragProxy';
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell Proxy.ATTRS = {
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @attribute moveOnEnd
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @description Move the original node at the end of the drag. Default: true
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @type Boolean
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell moveOnEnd: {
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell value: true
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell },
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @attribute resizeFrame
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @description Make the Proxy node assume the size of the original node. Default: true
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @type Boolean
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell resizeFrame: {
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott value: true
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott },
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott /**
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @attribute proxy
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @description Make this Draggable instance a Proxy instance. Default: false
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @type Boolean
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell proxy: {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell value: false,
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell set: function(v) {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell this._setProxy(v);
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell }
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott },
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @attribute positionProxy
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @description Make the Proxy node appear in the same place as the original node. Default: true
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @type Boolean
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell */
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell positionProxy: {
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell value: true
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell },
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell /**
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @attribute borderStyle
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @description The default border style for the border of the proxy. Default: 1px solid #808080
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell * @type Boolean
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell */
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell borderStyle: {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell value: '1px solid #808080'
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell }
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell };
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell var proto = {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell /**
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell * @private
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * @method _setProxy
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * @description Handler for the proxy config attribute
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott */
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott _setProxy: function(v) {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell if (v) {
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott if (this.get(DRAG_NODE).compareTo(this.get(NODE))) {
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell this._createFrame();
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott this.set(DRAG_NODE, DDM._proxy);
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott }
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott } else {
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott this.set(DRAG_NODE, this.get(NODE));
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell }
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott },
415243fbc81341293a852ff6aa14e9608d08685cCraig McDonnell /**
91f0e3cb60de3eba8cbb70c7e36cc0df22d71f5bRobert Wapshott * @private
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell * @method _createFrame
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell * @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell */
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell _createFrame: function() {
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell if (!DDM._proxy) {
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell DDM._proxy = true;
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell var p = Y.Node.create('<div></div>');
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell p.setStyles({
a3970d0ea62388e4ede01470a6436eb5c6c92353Craig McDonnell position: 'absolute',
2beebed98b4fc7f018fb224a1e4a3ab6103a4c0bCraig McDonnell display: 'none',
zIndex: '999',
top: '-999px',
left: '-999px',
border: this.get('borderStyle')
});
var b = Y.Node.get('body');
b.insertBefore(p, b.get('firstChild'));
p.set('id', Y.stamp(p));
p.addClass(DDM.CSS_PREFIX + '-proxy');
DDM._proxy = p;
}
},
/**
* @private
* @method _setFrame
* @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
* If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
*/
_setFrame: function() {
var n = this.get(NODE);
if (this.get('resizeFrame')) {
DDM._proxy.setStyles({
height: n.get('offsetHeight') + 'px',
width: n.get('offsetWidth') + 'px'
});
}
var ah = DDM.activeDrag.get('activeHandle'),
cur = ah.getStyle('cursor');
if (cur == 'auto') {
cur = DDM.get('dragCursor');
}
this.get(DRAG_NODE).setStyles({
visibility: 'hidden',
display: 'block',
cursor: cur,
border: this.get('borderStyle')
});
if (this.get('positionProxy')) {
this.get(DRAG_NODE).setXY(this.nodeXY);
}
this.get(DRAG_NODE).setStyle('visibility', 'visible');
},
/**
* @private
* @method initializer
* @description Lifecycle method
*/
initializer: function() {
if (this.get(PROXY)) {
this._createFrame();
}
},
/**
* @method start
* @description Starts the drag operation and sets the dragNode config option.
*/
start: function() {
if (!this.get('lock')) {
/*
if (this.get(PROXY)) {
if (this.get(DRAG_NODE).compareTo(this.get(NODE))) {
this.set(DRAG_NODE, DDM._proxy);
}
} else {
this.set(DRAG_NODE, this.get(NODE));
}
*/
}
Proxy.superclass.start.apply(this);
if (this.get(PROXY)) {
this._setFrame();
}
},
/**
* @method end
* @description Ends the drag operation, if moveOnEnd is set it will position the Drag Element to the new location of the proxy.
*/
end: function() {
if (this.get(PROXY) && this.get('dragging')) {
if (this.get('moveOnEnd')) {
this.get(NODE).setXY(this.lastXY);
}
this.get(DRAG_NODE).setStyle('display', 'none');
}
Proxy.superclass.end.apply(this);
}
};
//Extend DD.Drag
Y.extend(Proxy, Y.DD.Drag, proto);
//Set this new class as DD.Drag for other extensions
Y.DD.Drag = Proxy;
}, '@VERSION@' ,{requires:['dd-ddm', 'dd-drag'], skinnable:false});