dd-proxy-debug.js revision aeb77d2edf9d5bb8a95885ad6ed90ca5ad0970d7
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippYUI.add('dd-proxy', function(Y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @module dd
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @submodule dd-proxy
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Plugin for dd-drag for creating a proxy drag node, instead of dragging the original node.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @class DDProxy
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @extends Base
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @constructor
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @namespace Plugin
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp var DDM = Y.DD.DDM,
a89ad754cce3cfc8aee71760e10217b54020360dTripp NODE = 'node',
a89ad754cce3cfc8aee71760e10217b54020360dTripp DRAG_NODE = 'dragNode',
a89ad754cce3cfc8aee71760e10217b54020360dTripp HOST = 'host',
a89ad754cce3cfc8aee71760e10217b54020360dTripp TRUE = true, proto,
a89ad754cce3cfc8aee71760e10217b54020360dTripp P = function(config) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp P.superclass.constructor.apply(this, arguments);
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp P.NAME = 'DDProxy';
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @property NS
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @default con
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @readonly
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @protected
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @static
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description The Proxy instance will be placed on the Drag instance under the proxy namespace.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type {String}
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp P.NS = 'proxy';
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp P.ATTRS = {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp host: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute moveOnEnd
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Move the original node at the end of the drag. Default: true
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @type Boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp moveOnEnd: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: TRUE
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute hideOnEnd
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Hide the drag node at the end of the drag. Default: true
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp hideOnEnd: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: TRUE
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute resizeFrame
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Make the Proxy node assume the size of the original node. Default: true
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp resizeFrame: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: TRUE
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute positionProxy
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Make the Proxy node appear in the same place as the original node. Default: true
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp positionProxy: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: TRUE
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute borderStyle
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description The default border style for the border of the proxy. Default: 1px solid #808080
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp borderStyle: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: '1px solid #808080'
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute cloneNode
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Should the node be cloned into the proxy for you. Default: false
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp cloneNode: {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp value: false
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp proto = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _hands
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @description Holds the event handles for setting the proxy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _hands: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _init
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @description Handler for the proxy config attribute
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp _init: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!DDM._proxy) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp DDM._createFrame();
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.on('domready', Y.bind(this._init, this));
a89ad754cce3cfc8aee71760e10217b54020360dTripp return;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!this._hands) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._hands = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var h, h1, host = this.get(HOST), dnode = host.get(DRAG_NODE);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (dnode.compareTo(host.get(NODE))) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (DDM._proxy) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp host.set(DRAG_NODE, DDM._proxy);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.each(this._hands, function(v) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp v.detach();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = DDM.on('ddm:start', Y.bind(function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (DDM.activeDrag === host) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp DDM._setFrame(host);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }, this));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h1 = DDM.on('ddm:end', Y.bind(function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (host.get('dragging')) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (this.get('moveOnEnd')) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp host.get(NODE).setXY(host.lastXY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (this.get('hideOnEnd')) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp host.get(DRAG_NODE).setStyle('display', 'none');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (this.get('cloneNode')) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp host.get(DRAG_NODE).remove();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp host.set(DRAG_NODE, DDM._proxy);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }, this));
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._hands = [h, h1];
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp initializer: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._init();
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp destructor: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var host = this.get(HOST);
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.each(this._hands, function(v) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp v.detach();
a89ad754cce3cfc8aee71760e10217b54020360dTripp });
a89ad754cce3cfc8aee71760e10217b54020360dTripp host.set(DRAG_NODE, host.get(NODE));
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp clone: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var host = this.get(HOST),
a89ad754cce3cfc8aee71760e10217b54020360dTripp n = host.get(NODE),
a89ad754cce3cfc8aee71760e10217b54020360dTripp c = n.cloneNode(true);
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp c.set('id', '');
a89ad754cce3cfc8aee71760e10217b54020360dTripp c.setStyle('position', 'absolute');
a89ad754cce3cfc8aee71760e10217b54020360dTripp delete c._yuid;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.stamp(c);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp n.get('parentNode').appendChild(c);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp host.set(DRAG_NODE, c);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return c;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.namespace('Plugin');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.extend(P, Y.Base, proto);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.Plugin.DDProxy = P;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //Add a couple of methods to the DDM
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.mix(DDM, {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @for DDM
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @namespace DD
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createFrame
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createFrame: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!DDM._proxy) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp DDM._proxy = TRUE;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var p = Y.Node.create('<div></div>'),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp b = Y.one('body');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp p.setStyles({
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp position: 'absolute',
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp display: 'none',
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp zIndex: '999',
a89ad754cce3cfc8aee71760e10217b54020360dTripp top: '-999px',
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp left: '-999px'
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp b.prepend(p);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp p.set('id', Y.guid());
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp p.addClass(DDM.CSS_PREFIX + '-proxy');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp DDM._proxy = p;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @for DDM
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @namespace DD
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _setFrame
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @description If resizeProxy is set to true (default) it will resize the proxy element to match the size of the Drag Element.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * If positionProxy is set to true (default) it will position the proxy element in the same location as the Drag Element.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _setFrame: function(drag) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var n = drag.get(NODE), d = drag.get(DRAG_NODE), ah, cur = 'auto';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (drag.proxy.get('resizeFrame')) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp DDM._proxy.setStyles({
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp height: n.get('offsetHeight') + 'px',
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp width: n.get('offsetWidth') + 'px'
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ah = DDM.activeDrag.get('activeHandle');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (ah) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cur = ah.getStyle('cursor');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (cur == 'auto') {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cur = DDM.get('dragCursor');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp d.setStyles({
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp visibility: 'hidden',
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp display: 'block',
a89ad754cce3cfc8aee71760e10217b54020360dTripp cursor: cur,
a89ad754cce3cfc8aee71760e10217b54020360dTripp border: drag.proxy.get('borderStyle')
a89ad754cce3cfc8aee71760e10217b54020360dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (drag.proxy.get('cloneNode')) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp d = drag.proxy.clone();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (drag.proxy.get('positionProxy')) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp d.setXY(drag.nodeXY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp d.setStyle('visibility', 'visible');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //Create the frame when DOM is ready
a89ad754cce3cfc8aee71760e10217b54020360dTripp //Y.on('domready', Y.bind(DDM._createFrame, DDM));
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp}, '@VERSION@' ,{requires:['dd-ddm', 'dd-drag'], skinnable:false});
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp