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