drop.js revision ee4d8528357b157539bc45a7324cb16d46a88272
/**
* 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.
* @module dd
* @submodule dd-drop
*/
/**
* This class provides the ability to create a Drop Target.
* @class Drop
* @extends Base
* @constructor
*/
var NODE = 'node',
OFFSET_HEIGHT = 'offsetHeight',
OFFSET_WIDTH = 'offsetWidth',
/**
* @event drop:over
* @description Fires when a drag element is over this target.
* @bubbles DDM
* @type Event.Custom
*/
EV_DROP_OVER = 'drop:over',
/**
* @event drop:enter
* @description Fires when a drag element enters this target.
* @bubbles DDM
* @type Event.Custom
*/
EV_DROP_ENTER = 'drop:enter',
/**
* @event drop:exit
* @description Fires when a drag element exits this target.
* @bubbles DDM
* @type Event.Custom
*/
EV_DROP_EXIT = 'drop:exit';
/**
* @event drop:hit
* @description Fires when a draggable node is dropped on this Drop Target. (Fired from dd-ddm-drop)
* @bubbles DDM
* @type Event.Custom
*/
var Drop = function() {
this._createShim();
DDM._regTarget(this);
/* TODO
if (Dom.getStyle(this.el, 'position') == 'fixed') {
Event.on(window, 'scroll', function() {
this.activateShim();
}, this, true);
}
*/
};
/**
* @attribute node
* @description Y.Node instanace to use as the element to make a Drop Target
* @type Node
*/
node: {
if (!n) {
}
return n;
}
},
/**
* @attribute groups
* @description Array of groups to add this drop into.
* @type Array
*/
groups: {
value: ['default'],
set: function(g) {
this._groups = {};
Y.each(g, function(v, k) {
this._groups[v] = true;
}, this);
}
},
/**
* @attribute padding
* @description CSS style padding to make the Drop Target bigger than the node.
* @type String
*/
padding: {
value: '0',
set: function(p) {
return DDM.cssSizestoObject(p);
}
},
/**
* @attribute lock
* @description Set to lock this drop element.
* @type Boolean
*/
lock: {
value: false,
if (lock) {
} else {
}
}
},
/**
* @attribute bubbles
* @description Controls the default bubble parent for this Drop instance. Default: Y.DD.DDM. Set to false to disable bubbling.
* @type Object
*/
bubbles: {
writeOnce: true,
}
};
/**
* @private
* @method _createEvents
* @description This method creates all the events for this Event Target and publishes them so we get Event Bubbling.
*/
_createEvents: function() {
var ev = [
'drop:hit'
];
this.publish(v, {
type: v,
emitFacade: true,
preventable: false,
bubbles: true,
queuable: true
});
}, this);
if (this.get('bubbles')) {
}
},
/**
* @private
* @property _valid
* @description Flag for determining if the target is valid in this operation.
* @type Boolean
*/
_valid: null,
/**
* @private
* @property _groups
* @description The groups this target belongs to.
* @type Array
*/
_groups: null,
/**
* @property shim
* @description Node reference to the targets shim
* @type {Object}
*/
shim: null,
/**
* @property region
* @description A region object associated with this target, used for checking regions while dragging.
* @type Object
*/
region: null,
/**
* @property overTarget
* @description This flag is tripped when a drag element is over this target.
* @type Boolean
*/
overTarget: null,
/**
* @method inGroup
* @description Check if this target is in one of the supplied groups.
* @param {Array} groups The groups to check against
* @return Boolean
*/
this._valid = false;
var ret = false;
if (this._groups[v]) {
ret = true;
this._valid = true;
}
}, this);
return ret;
},
/**
* @private
* @method initializer
* @description Private lifecycle method
*/
initializer: function() {
this._createEvents();
}
},
/**
* @private
* @method destructor
* @description Lifecycle destructor, unreg the drag from the DDM and remove listeners
*/
destructor: function() {
DDM._unregTarget(this);
if (this.shim) {
this.shim = null;
}
},
/**
* @private
* @method _deactivateShim
* @description Removes classes from the target, resets some flags and sets the shims deactive position [-999, -999]
*/
_deactivateShim: function() {
top: '-999px',
left: '-999px'
});
this.overTarget = false;
},
/**
* @private
* @method _activateShim
* @description Activates the shim and adds some interaction CSS classes
*/
_activateShim: function() {
if (!DDM.activeDrag) {
return false; //Nothing is dragging, no reason to activate.
}
return false;
}
if (this.get('lock')) {
return false;
}
//TODO Visibility Check..
//if (this.inGroup(DDM.activeDrag.get('groups')) && this.get(NODE).isVisible()) {
this.overTarget = false;
this.sizeShim();
} else {
DDM._removeValid(this);
}
},
/**
* @method sizeShim
* @description Positions and sizes the shim with the raw data from the node, this can be used to programatically adjust the Targets shim for Animation..
*/
sizeShim: function() {
if (!DDM.activeDrag) {
return false; //Nothing is dragging, no reason to activate.
}
return false;
}
if (this.get('lock')) {
return false;
}
p = this.get('padding');
//Apply padding
//Intersect Mode, make the shim bigger
}
//Set the style on the shim
});
//Create the region to be used by intersect when a drag node is over us.
this.region = {
area: 0,
};
},
/**
* @private
* @method _createShim
* @description Creates the Target shim and adds it to the DDM's playground..
*/
_createShim: function() {
//var s = Y.Node.create(['div', { id: this.get(NODE).get('id') + '_shim' }]);
s.setStyles({
backgroundColor: 'yellow',
opacity: '.5',
zIndex: 999,
overflow: 'hidden',
top: '-900px',
left: '-900px',
position: 'absolute'
});
this.shim = s;
},
/**
* @private
* @method _handleOverTarget
* @description This handles the over target call made from this object or from the DDM
*/
_handleTargetOver: function() {
if (DDM.isOverTarget(this)) {
DDM.activeDrop = this;
DDM.otherDrops[this] = this;
if (this.overTarget) {
} else {
this.overTarget = true;
}
} else {
this._handleOut();
}
},
/**
* @private
* @method _handleOverEvent
* @description Handles the mouseover DOM event on the Target Shim
*/
_handleOverEvent: function() {
DDM._addActiveShim(this);
},
/**
* @private
* @method _handleOut
* @description Handles the mouseout DOM event on the Target Shim
*/
_handleOutEvent: function() {
DDM._removeActiveShim(this);
},
/**
* @private
* @method _handleOut
*/
_handleOut: function() {
if (!DDM.isOverTarget(this)) {
if (this.overTarget) {
this.overTarget = false;
DDM._removeActiveShim(this);
if (DDM.activeDrag) {
this.fire(EV_DROP_EXIT);
delete DDM.otherDrops[this];
}
}
}
}
});