dd.js revision ee4d8528357b157539bc45a7324cb16d46a88272
/**
* Provides the base Drag Drop Manger required for making a Node draggable.
* @module dd
* @submodule dd-ddm-base
*/
/**
* Provides the base Drag Drop Manger required for making a Node draggable.
* @class DDM
* @extends Base
* @constructor
*/
var DDMBase = function() {
//debugger;
};
/**
* @attribute clickPixelThresh
* @description The number of pixels to move to start a drag operation, default is 3.
* @type Number
*/
value: 3
},
/**
* @attribute clickTimeThresh
* @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
* @type Number
*/
value: 1000
},
/**
* @attribute dragMode
* @description This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of all future Drag instances.
* @type String
*/
dragMode: {
value: 'point',
this._setDragMode(mode);
}
}
};
/**
* @private
* @method _setDragMode
* @description Handler for dragMode attribute setter.
* @param String/Number The Number value or the String for the DragMode to default all future drag instances to.
* @return Number The Mode to be set
*/
_setDragMode: function(mode) {
if (mode === null) {
}
switch (mode) {
case 1:
case 'intersect':
return 1;
case 2:
case 'strict':
return 2;
case 0:
case 'point':
return 0;
}
return 0;
},
/**
* @property CSS_PREFIX
* @description The PREFIX to attach to all DD CSS class names
* @type {String}
*/
CSS_PREFIX: 'yui-dd',
_activateTargets: function() {},
/**
* @private
* @property _drags
* @description Holder for all registered drag elements.
* @type {Array}
*/
_drags: [],
/**
* @property activeDrag
* @description A reference to the currently active draggable object.
* @type {Drag}
*/
activeDrag: false,
/**
* @private
* @method _regDrag
* @description Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
* @param {Drag} d The Drag object
*/
_regDrag: function(d) {
},
/**
* @private
* @method _unregDrag
* @description Remove this drag object from the DDM._drags array.
* @param {Drag} d The drag object.
*/
_unregDrag: function(d) {
var tmp = [];
if (n !== d) {
}
});
},
/**
* @private
* @method _init
* @description DDM's init method
*/
initializer: function() {
},
/**
* @private
* @method _start
* @description Internal method used by Drag to signal the start of a drag operation
* @param {Number} x The x position of the drag element
* @param {Number} y The y position of the drag element
* @param {Number} w The width of the drag element
* @param {Number} h The height of the drag element
*/
_start: function(x, y, w, h) {
},
/**
* @private
* @method _startDrag
* @description Factory method to be overwritten by other DDM's
* @param {Number} x The x position of the drag element
* @param {Number} y The y position of the drag element
* @param {Number} w The width of the drag element
* @param {Number} h The height of the drag element
*/
_startDrag: function() {},
/**
* @private
* @method _endDrag
* @description Factory method to be overwritten by other DDM's
*/
_endDrag: function() {},
_dropMove: function() {},
/**
* @private
* @method _end
* @description Internal method used by Drag to signal the end of a drag operation
*/
_end: function() {
//@TODO - Here we can get a (click - drag - click - release) interaction instead of a (mousedown - drag - mouseup - release) interaction
//Add as a config option??
if (this.activeDrag) {
this._endDrag();
this.activeDrag = null;
}
},
/**
* @method stopDrag
* @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
* @return {Self}
* @chainable
*/
stopDrag: function() {
if (this.activeDrag) {
this._end();
}
return this;
},
/**
* @private
* @method _move
* @description Internal listener for the mousemove DOM event to pass to the Drag's move method.
* @param {Event} ev The Dom mousemove Event
*/
if (this.activeDrag) {
this._dropMove();
}
},
/**
* @method setXY
* @description A simple method to set the top and left position from offsets instead of page coordinates
* @param {Object} node The node to set the position of
*/
if (pos === 'static') {
}
// in case of 'auto'
if (isNaN(t)) { t = 0; }
if (isNaN(l)) { l = 0; }
},
/**
* //TODO Private, rename??...
* @private
* @method cssSizestoObject
* @description Helper method to use to set the gutter from the attribute setter.
* @param {String} gutter CSS style string for gutter: '5 0' (sets top and bottom to 5px, left and right to 0px), '1 2 3 4' (top 1px, right 2px, bottom 3px, left 4px)
* @return {Object} The gutter Object Literal.
*/
cssSizestoObject: function(gutter) {
switch (x.length) {
case 1: x[1] = x[2] = x[3] = x[0]; break;
case 2: x[2] = x[0]; x[3] = x[1]; break;
case 3: x[3] = x[1]; break;
}
return {
};
},
/**
* @method getDrag
* @description Get a valid Drag instance back from a Node or a selector string, false otherwise
* @return {Object}
*/
var drag = false,
if (n instanceof Y.Node) {
drag = v;
}
});
}
return drag;
}
});
Y.namespace('DD');
/**
* Extends the dd-ddm-base Class to add support for the viewport shim to allow a draggable node to drag to be dragged over an iframe or any other node that traps mousemove events.
* It is also required to have Drop Targets enabled, as the viewport shim will contain the shims for the Drop Targets.
* @module dd
* @submodule dd-ddm
* @for DDM
*/
/**
* @private
* @property _pg
* @description The shim placed over the screen to track the mousemove event.
* @type {Node}
*/
_pg: null,
/**
* @private
* @property _debugShim
* @description Set this to true to set the shims opacity to .5 for debugging it, default: false.
* @type {Boolean}
*/
_debugShim: false,
_activateTargets: function() {},
_deactivateTargets: function() {},
_startDrag: function() {
this._pg_activate();
this._activateTargets();
}
},
_endDrag: function() {
this._pg_deactivate();
this._deactivateTargets();
},
/**
* @private
* @method _pg_deactivate
* @description Deactivates the shim
*/
_pg_deactivate: function() {
},
/**
* @private
* @method _pg_activate
* @description Activates the shim
*/
_pg_activate: function() {
this._pg_size();
top: 0,
left: 0,
display: 'block',
});
},
/**
* @private
* @method _pg_size
* @description Sizes the shim on: activatation, window:scroll, window:resize
*/
_pg_size: function() {
if (this.activeDrag) {
h = b.get('docHeight'),
w = b.get('docWidth');
height: h + 'px',
width: w + 'px'
});
}
},
/**
* @private
* @method _createPG
* @description Creates the shim and adds it's listeners to it.
*/
_createPG: function() {
//var pg = Y.Node.create(['div']),
top: '0',
left: '0',
position: 'absolute',
zIndex: '9999',
overflow: 'hidden',
//opacity: '0',
backgroundColor: 'red',
display: 'none',
height: '5px',
width: '5px'
});
} else {
}
}
}, true);
/**
* Extends the dd-ddm Class to add support for the placement of Drop Target shims inside the viewport shim. It also handles all Drop Target related events and interactions.
* @module dd
* @submodule dd-ddm-drop
* @for DDM
*/
//TODO CSS class name for the bestMatch..
/**
* @private
* @property _noShim
* @description This flag turns off the use of the mouseover/mouseout shim. It should not be used unless you know what you are doing.
* @type {Boolean}
*/
_noShim: false,
/**
* @private
* @property _activeShims
* @description Placeholder for all active shims on the page
* @type {Array}
*/
_activeShims: [],
/**
* @private
* @method _hasActiveShim
* @description This method checks the _activeShims Object to see if there is a shim active.
* @return {Boolean}
*/
_hasActiveShim: function() {
if (this._noShim) {
return true;
}
return this._activeShims.length;
},
/**
* @private
* @method _addActiveShim
* @description Adds a Drop Target to the list of active shims
* @param {Object} d The Drop instance to add to the list.
*/
_addActiveShim: function(d) {
},
/**
* @private
* @method _removeActiveShim
* @description Removes a Drop Target to the list of active shims
* @param {Object} d The Drop instance to remove from the list.
*/
_removeActiveShim: function(d) {
var s = [];
Y.each(this._activeShims, function(v, k) {
s[s.length] = v;
}
});
this._activeShims = s;
},
/**
* @method syncActiveShims
* @description This method will sync the position of the shims on the Drop Targets that are currently active.
* @return {Array} drops The list of Drop Targets that was just synced.
*/
syncActiveShims: function(force) {
}, this);
return drops;
},
/**
* @private
* @property mode
* @description The mode that the drag operations will run in 0 for Point, 1 for Intersect, 2 for Strict
* @type Number
*/
mode: 0,
/**
* @private
* @property POINT
* @description In point mode, a Drop is targeted by the cursor being over the Target
* @type Number
*/
POINT: 0,
/**
* @private
* @property INTERSECT
* @description In intersect mode, a Drop is targeted by "part" of the drag node being over the Target
* @type Number
*/
INTERSECT: 1,
/**
* @private
* @property STRICT
* @description In strict mode, a Drop is targeted by the "entire" drag node being over the Target
* @type Number
*/
STRICT: 2,
/**
* @property useHash
* @description Should we only check targets that are in the viewport on drags (for performance), default: true
* @type {Boolean}
*/
useHash: true,
/**
* @property activeDrop
* @description A reference to the active Drop Target
* @type {Object}
*/
activeDrop: null,
/**
* @property validDrops
* @description An array of the valid Drop Targets for this interaction.
* @type {Array}
*/
validDrops: [],
/**
* @property otherDrops
* @description An object literal of Other Drop Targets that we encountered during this interaction (in the case of overlapping Drop Targets)
* @type {Object}
*/
otherDrops: {},
/**
* @property targets
* @description All of the Targets
* @type {Array}
*/
targets: [],
/**
* @private
* @method _addValid
* @description Add a Drop Target to the list of Valid Targets. This list get's regenerated on each new drag operation.
* @param {Object} drop
* @return {Self}
* @chainable
*/
return this;
},
/**
* @private
* @method _removeValid
* @description Removes a Drop Target from the list of Valid Targets. This list get's regenerated on each new drag operation.
* @param {Object} drop
* @return {Self}
* @chainable
*/
_removeValid: function(drop) {
var drops = [];
Y.each(this.validDrops, function(v, k) {
if (v !== drop) {
}
});
this.validDrops = drops;
return this;
},
/**
* @method isOverTarget
* @description Check to see if the Drag element is over the target, method varies on current mode
* @param {Object} drop The drop to check against
* @return {Boolean}
*/
isOverTarget: function(drop) {
//if (Y.Lang.isObject(this.activeDrag) && drop) { //TODO, check this check..
if (this.activeDrag && drop) {
if (xy) {
} else {
} else {
return false;
}
}
} else {
return false;
}
} else {
return false;
}
},
/**
* @method clearCache
* @description Clears the cache data used for this interaction.
*/
clearCache: function() {
this.validDrops = [];
this.otherDrops = {};
this._activeShims = [];
},
/**
* @private
* @method _activateTargets
* @description Clear the cache and activate the shims of all the targets
*/
_activateTargets: function() {
this.clearCache();
v._activateShim.apply(v, []);
}, this);
this._handleTargetOver();
},
/**
* @method getBestMatch
* @description This method will gather the area for all potential targets and see which has the hightest covered area and return it.
* @param {Array} drops An Array of drops to scan for the best match.
* @param {Boolean} all If present, it returns an Array. First item is best match, second is an Array of the other items in the original Array.
* @return {Object or Array}
*/
biggest = v;
}
}
}, this);
if (all) {
var out = [];
//TODO Sort the others in numeric order by area covered..
if (v !== biggest) {
}
}, this);
} else {
return biggest;
}
},
/**
* @private
* @method _deactivateTargets
* @description This method fires the drop:hit, drag:drophit, drag:dropmiss methods and deactivates the shims..
*/
_deactivateTargets: function() {
var other = [],
activeDrag = this.activeDrag,
activeDrop = this.activeDrop;
//TODO why is this check so hard??
//TODO otherDrops -- private..
other = this.otherDrops;
delete other[activeDrop];
} else {
}
if (activeDrop) {
}
} else if (activeDrag) {
} else {
}
this.activeDrop = null;
v._deactivateShim.apply(v, []);
}, this);
},
/**
* @private
* @method _dropMove
* @description This method is called when the move method is called on the Drag Object.
*/
_dropMove: function() {
if (this._hasActiveShim()) {
this._handleTargetOver();
} else {
Y.each(this.otherDrops, function(v, k) {
v._handleOut.apply(v, []);
});
}
},
/**
* @private
* @method _lookup
* @description Filters the list of Drops down to those in the viewport.
* @return {Array} The valid Drop Targets that are in the viewport.
*/
_lookup: function() {
if (!this.useHash) {
return this.validDrops;
}
var drops = [];
//Only scan drop shims that are in the Viewport
Y.each(this.validDrops, function(v, k) {
}
});
return drops;
},
/**
* @private
* @method _handleTargetOver
* @description This method execs _handleTargetOver on all valid Drop Targets
* @param {Boolean} force Force it to run the first time.
*/
_handleTargetOver: function() {
v._handleTargetOver.call(v);
}, this);
},
/**
* @private
* @method _regTarget
* @description Add the passed in Target to the targets collection
* @param {Object} t The Target to add to the targets collection
*/
_regTarget: function(t) {
},
/**
* @private
* @method _unregTarget
* @description Remove the passed in Target from the targets collection
* @param {Object} drop The Target to remove from the targets collection
*/
_unregTarget: function(drop) {
var targets = [];
if (v != drop) {
}
}, this);
var vdrops = [];
Y.each(this.validDrops, function(v, k) {
if (v !== drop) {
}
});
this.validDrops = vdrops;
},
/**
* @method getDrop
* @description Get a valid Drop instance back from a Node or a selector string, false otherwise
* @return {Object}
*/
var drop = false,
if (n instanceof Y.Node) {
drop = v;
}
});
}
return drop;
}
}, true);
/**
* 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-drag
*/
/**
* This class provides the ability to drag a Node.
* @class Drag
* @extends Base
* @constructor
*/
NODE = 'node',
DRAG_NODE = 'dragNode',
OFFSET_HEIGHT = 'offsetHeight',
OFFSET_WIDTH = 'offsetWidth',
MOUSE_UP = 'mouseup',
MOUSE_DOWN = 'mousedown',
DRAG_START = 'dragstart',
/**
* @event drag:mouseDown
* @description Handles the mousedown DOM event, checks to see if you have a valid handle then starts the drag timers.
* @preventable _handleMouseDown
* @param {Event} ev The mousedown event.
* @bubbles DDM
* @type Event.Custom
*/
EV_MOUSE_DOWN = 'drag:mouseDown',
/**
* @event drag:afterMouseDown
* @description Fires after the mousedown event has been cleared.
* @param {Event} ev The mousedown event.
* @bubbles DDM
* @type Event.Custom
*/
EV_AFTER_MOUSE_DOWN = 'drag:afterMouseDown',
/**
* @event drag:removeHandle
* @description Fires after a handle is removed.
* @bubbles DDM
* @type Event.Custom
*/
EV_REMOVE_HANDLE = 'drag:removeHandle',
/**
* @event drag:addHandle
* @description Fires after a handle is added.
* @bubbles DDM
* @type Event.Custom
*/
EV_ADD_HANDLE = 'drag:addHandle',
/**
* @event drag:removeInvalid
* @description Fires after an invalid selector is removed.
* @bubbles DDM
* @type Event.Custom
*/
EV_REMOVE_INVALID = 'drag:removeInvalid',
/**
* @event drag:addInvalid
* @description Fires after an invalid selector is added.
* @bubbles DDM
* @type Event.Custom
*/
EV_ADD_INVALID = 'drag:addInvalid',
/**
* @event drag:start
* @description Fires at the start of a drag operation.
* @bubbles DDM
* @type Event.Custom
*/
EV_START = 'drag:start',
/**
* @event drag:end
* @description Fires at the end of a drag operation.
* @bubbles DDM
* @type Event.Custom
*/
EV_END = 'drag:end',
/**
* @event drag:drag
* @description Fires every mousemove during a drag operation.
* @bubbles DDM
* @type Event.Custom
*/
EV_DRAG = 'drag:drag';
/**
* @event drag:over
* @description Fires when this node is over a Drop Target. (Fired from dd-drop)
* @bubbles DDM
* @type Event.Custom
*/
/**
* @event drag:enter
* @description Fires when this node enters a Drop Target. (Fired from dd-drop)
* @bubbles DDM
* @type Event.Custom
*/
/**
* @event drag:exit
* @description Fires when this node exits a Drop Target. (Fired from dd-drop)
* @bubbles DDM
* @type Event.Custom
*/
/**
* @event drag:drophit
* @description Fires when this node is dropped on a valid Drop Target. (Fired from dd-ddm-drop)
* @bubbles DDM
* @type Event.Custom
*/
/**
* @event drag:dropmiss
* @description Fires when this node is dropped on an invalid Drop Target. (Fired from dd-ddm-drop)
* @bubbles DDM
* @type Event.Custom
*/
var Drag = function() {
};
/**
* @attribute node
* @description Y.Node instanace to use as the element to initiate a drag operation
* @type Node
*/
node: {
if (!n) {
} else {
n = n.item(0);
}
return n;
}
},
/**
* @attribute dragNode
* @description Y.Node instanace to use as the draggable element, defaults to node
* @type Node
*/
dragNode: {
if (!n) {
}
return n;
}
},
/**
* @attribute offsetNode
* @description Offset the drag element by the difference in cursor position: default true
* @type Boolean
*/
offsetNode: {
value: true
},
/**
* @attribute clickPixelThresh
* @description The number of pixels to move to start a drag operation, default is 3.
* @type Number
*/
},
/**
* @attribute clickTimeThresh
* @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
* @type Number
*/
},
/**
* @attribute lock
* @description Set to lock this drag element so that it can't be dragged: default false.
* @type Boolean
*/
lock: {
value: false,
if (lock) {
} else {
}
}
},
/**
* @attribute data
* @description A payload holder to store arbitrary data about this drag object, can be used to store any value.
* @type Mixed
*/
data: {
value: false
},
/**
* @attribute move
* @description If this is false, the drag element will not move with the cursor: default true. Can be used to "resize" the element.
* @type Boolean
*/
move: {
value: true
},
/**
* @attribute useShim
* @description Use the protective shim on all drag operations: default true. Only works with dd-ddm, not dd-ddm-base.
* @type Boolean
*/
useShim: {
value: true
},
/**
* @attribute activeHandle
* @description This config option is set by Drag to inform you of which handle fired the drag event (in the case that there are several handles): default false.
* @type Node
*/
activeHandle: {
value: false
},
/**
* @attribute primaryButtonOnly
* @description By default a drag operation will only begin if the mousedown occurred with the primary mouse button. Setting this to false will allow for all mousedown events to trigger a drag.
* @type Boolean
*/
value: true
},
/**
* @attribute dragging
* @description This attribute is not meant to be used by the implementor, it is meant to be used as an Event tracker so you can listen for it to change.
* @type Boolean
*/
dragging: {
value: false
},
parent: {
value: false
},
/**
* @attribute target
* @description This attribute only works if the dd-drop module has been loaded. It will make this node a drop target as well as draggable.
* @type Boolean
*/
target: {
value: false,
this._handleTarget(config);
}
},
/**
* @attribute dragMode
* @description This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of this Drag instance.
* @type String
*/
dragMode: {
value: null,
}
},
/**
* @attribute groups
* @description Array of groups to add this drag into.
* @type Array
*/
groups: {
value: ['default'],
get: function() {
if (!this._groups) {
this._groups = {};
}
var ret = [];
});
return ret;
},
set: function(g) {
this._groups = {};
Y.each(g, function(v, k) {
this._groups[v] = true;
}, this);
}
},
/**
* @attribute handles
* @description Array of valid handles to add. Adding something here will set all handles, even if previously added with addHandle
* @type Array
*/
handles: {
value: null,
set: function(g) {
if (g) {
this._handles = {};
Y.each(g, function(v, k) {
this._handles[v] = true;
}, this);
} else {
this._handles = null;
}
return g;
}
},
/**
* @attribute bubbles
* @description Controls the default bubble parent for this Drag instance. Default: Y.DD.DDM. Set to false to disable bubbling.
* @type Object
*/
bubbles: {
writeOnce: true,
}
};
/**
* @method addToGroup
* @description Add this Drag instance to a group, this should be used for on-the-fly group additions.
* @param {String} g The group to add this Drag Instance to.
* @return {Self}
* @chainable
*/
addToGroup: function(g) {
this._groups[g] = true;
return this;
},
/**
* @method removeFromGroup
* @description Remove this Drag instance from a group, this should be used for on-the-fly group removals.
* @param {String} g The group to remove this Drag Instance from.
* @return {Self}
* @chainable
*/
removeFromGroup: function(g) {
delete this._groups[g];
return this;
},
/**
* @property target
* @description This will be a reference to the Drop instance associated with this drag if the target: true config attribute is set..
* @type {Object}
*/
target: null,
/**
* @private
* @method _handleTarget
* @description Attribute handler for the target config attribute.
*/
_handleTarget: function(config) {
if (config === false) {
if (this.target) {
this.target = null;
}
return false;
} else {
config = {};
}
}
} else {
return false;
}
},
/**
* @private
* @property _groups
* @description Storage Array for the groups this drag belongs to.
* @type {Array}
*/
_groups: null,
/**
* @private
* @method _createEvents
* @description This method creates all the events for this Event Target and publishes them so we get Event Bubbling.
*/
_createEvents: function() {
this.publish(EV_MOUSE_DOWN, {
defaultFn: this._handleMouseDown,
queuable: true,
emitFacade: true,
bubbles: true
});
var ev = [
'drag:drophit',
'drag:dropmiss',
'drag:over',
'drag:enter',
'drag:exit'
];
this.publish(v, {
type: v,
emitFacade: true,
bubbles: true,
preventable: false,
queuable: true
});
}, this);
if (this.get('bubbles')) {
}
},
/**
* @private
* @property _ev_md
* @description A private reference to the mousedown DOM event
* @type {Event}
*/
_ev_md: null,
/**
* @private
* @property _startTime
* @description The getTime of the mousedown event. Not used, just here in case someone wants/needs to use it.
* @type Date
*/
_startTime: null,
/**
* @private
* @property _endTime
* @description The getTime of the mouseup event. Not used, just here in case someone wants/needs to use it.
* @type Date
*/
_endTime: null,
/**
* @private
* @property _handles
* @description A private hash of the valid drag handles
* @type {Object}
*/
_handles: null,
/**
* @private
* @property _invalids
* @description A private hash of the invalid selector strings
* @type {Object}
*/
_invalids: null,
/**
* @private
* @property _invalidsDefault
* @description A private hash of the default invalid selector strings: {'textarea': true, 'input': true, 'a': true, 'button': true}
* @type {Object}
*/
/**
* @private
* @property _dragThreshMet
* @description Private flag to see if the drag threshhold was met
* @type {Boolean}
*/
_dragThreshMet: null,
/**
* @private
* @property _fromTimeout
* @description Flag to determine if the drag operation came from a timeout
* @type {Boolean}
*/
_fromTimeout: null,
/**
* @private
* @property _clickTimeout
* @description Holder for the setTimeout call
* @type {Boolean}
*/
_clickTimeout: null,
/**
* @property deltaXY
* @description The offset of the mouse position to the element's position
* @type {Array}
*/
deltaXY: null,
/**
* @property startXY
* @description The initial mouse position
* @type {Array}
*/
startXY: null,
/**
* @property nodeXY
* @description The initial element position
* @type {Array}
*/
nodeXY: null,
/**
* @property lastXY
* @description The position of the element as it's moving (for offset calculations)
* @type {Array}
*/
lastXY: null,
realXY: null,
/**
* @property mouseXY
* @description The XY coords of the mousemove
* @type {Array}
*/
mouseXY: null,
/**
* @property region
* @description A region object associated with this drag, used for checking regions while dragging.
* @type Object
*/
region: null,
/**
* @private
* @method _handleMouseUp
* @description Handler for the mouseup DOM event
* @param {Event}
*/
_handleMouseUp: function(ev) {
this._fixIEMouseUp();
if (DDM.activeDrag) {
}
},
/**
* @private
* @method _fixDragStart
* @description The function we use as the ondragstart handler when we start a drag in Internet Explorer. This keeps IE from blowing up on images as drag handles.
*/
_fixDragStart: function(e) {
e.preventDefault();
},
/**
* @private
* @method _ieSelectFix
* @description The function we use as the onselectstart handler when we start a drag in Internet Explorer
*/
_ieSelectFix: function() {
return false;
},
/**
* @private
* @property _ieSelectBack
* @description We will hold a copy of the current "onselectstart" method on this property, and reset it after we are done using it.
*/
_ieSelectBack: null,
/**
* @private
* @method _fixIEMouseDown
* @description This method copies the onselectstart listner on the document to the _ieSelectFix property
*/
_fixIEMouseDown: function() {
}
},
/**
* @private
* @method _fixIEMouseUp
* @description This method copies the _ieSelectFix property back to the onselectstart listner on the document.
*/
_fixIEMouseUp: function() {
}
},
/**
* @private
* @method _handleMouseDownEvent
* @description Handler for the mousedown DOM event
* @param {Event}
*/
_handleMouseDownEvent: function(ev) {
},
/**
* @private
* @method _handleMouseDown
* @description Handler for the mousedown DOM event
* @param {Event}
*/
_handleMouseDown: function(e) {
this._dragThreshMet = false;
return false;
}
if (this.validClick(ev)) {
this._fixIEMouseDown();
DDM.activeDrag = this;
var self = this;
this._clickTimeout = setTimeout(function() {
}, this.get('clickTimeThresh'));
}
},
/**
* @method validClick
* @description Method first checks to see if we have handles, if so it validates the click against the handle. Then if it finds a valid handle, it checks it against the invalid handles list. Returns true if a good handle was used, false otherwise.
* @param {Event}
* @return {Boolean}
*/
validClick: function(ev) {
var r = false,
hTest = null;
if (this._handles) {
//Am I this or am I inside this
hTest = n;
r = true;
}
}
});
} else {
r = true;
}
}
if (r) {
if (this._invalids) {
//Am I this or am I inside this
r = false;
}
}
});
}
}
if (r) {
if (hTest) {
set = false;
set = true;
}
}, this);
} else {
}
}
return r;
},
/**
* @private
* @method _setStartPosition
* @description Sets the current position of the Element and calculates the offset
* @param {Array} xy The XY coords to set the position to.
*/
_setStartPosition: function(xy) {
if (this.get('offsetNode')) {
} else {
}
},
/**
* @private
* @method _timeoutCheck
* @description The method passed to setTimeout to determine if the clickTimeThreshold was met.
*/
_timeoutCheck: function() {
if (!this.get('lock')) {
this._fromTimeout = true;
this._dragThreshMet = true;
this.start();
}
},
/**
* @method removeHandle
* @description Remove a Selector added by addHandle
* @param {String} str The selector for the handle to be removed.
* @return {Self}
* @chainable
*/
removeHandle: function(str) {
}
return this;
},
/**
* @method addHandle
* @description Add a handle to a drag element. Drag only initiates when a mousedown happens on this element.
* @param {String} str The selector to test for a valid handle. Must be a child of the element.
* @return {Self}
* @chainable
*/
if (!this._handles) {
this._handles = {};
}
}
return this;
},
/**
* @method removeInvalid
* @description Remove an invalid handle added by addInvalid
* @param {String} str The invalid handle to remove from the internal list.
* @return {Self}
* @chainable
*/
removeInvalid: function(str) {
}
return this;
},
/**
* @method addInvalid
* @description Add a selector string to test the handle against. If the test passes the drag operation will not continue.
* @param {String} str The selector to test against to determine if this is an invalid drag handle.
* @return {Self}
* @chainable
*/
addInvalid: function(str) {
} else {
}
return this;
},
/**
* @private
* @method initializer
* @description Internal init handler
*/
initializer: function() {
//TODO give the node instance a copy of this object
//Not supported in PR1 due to Y.Node.get calling a new under the hood.
//this.get(NODE).dd = this;
}
this._createEvents();
}
this._prep();
this._dragThreshMet = false;
},
/**
* @private
* @method _prep
* @description Attach event listners and add classname
*/
_prep: function() {
},
/**
* @private
* @method _unprep
* @description Detach event listners and remove classname
*/
_unprep: function() {
},
/**
* @method start
* @description Starts the drag operation
* @return {Self}
* @chainable
*/
start: function() {
this.set('dragging', true);
this._startTime = (new Date()).getTime();
this.region = {
area: 0,
};
}
return this;
},
/**
* @method end
* @description Ends the drag operation
* @return {Self}
* @chainable
*/
end: function() {
clearTimeout(this._clickTimeout);
this._dragThreshMet = false;
this._fromTimeout = false;
}
this.set('dragging', false);
return this;
},
/**
* @private
* @method _align
* @description Calculates the offsets and set's the XY that the element will move to.
* @param {Array} xy The xy coords to align with.
* @return Array
* @type {Array}
*/
},
/**
* @private
* @method _moveNode
* @description This method performs the actual element move.
* @param {Array} eXY The XY to move the element to, usually comes from the mousemove DOM event.
* @param {Boolean} noFire If true, the drag:drag event will not fire.
*/
//This will probably kill your machine ;)
if (this.get('move')) {
} else {
}
}
this.region = {
area: 0,
};
if (!noFire) {
info: {
}
});
}
},
/**
* @private
* @method _move
* @description Fired from DragDropMgr (DDM) on mousemove.
* @param {Event} ev The mousemove DOM event
*/
if (this.get('lock')) {
return false;
} else {
if (!this._dragThreshMet) {
this._dragThreshMet = true;
this.start();
}
} else {
clearTimeout(this._clickTimeout);
}
}
},
/**
* @method stopDrag
* @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
* @return {Self}
* @chainable
*/
stopDrag: function() {
if (this.get('dragging')) {
}
return this;
},
/**
* @private
* @method destructor
* @description Lifecycle destructor, unreg the drag from the DDM and remove listeners
*/
destructor: function() {
DDM._unregDrag(this);
this._unprep();
if (this.target) {
}
}
});
Y.namespace('DD');
/**
* 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-proxy
*/
/**
* This class extends dd-drag to allow for creating a proxy drag node, instead of dragging the original node.
* @class Proxy
* @extends Drag
* @constructor
*/
NODE = 'node',
DRAG_NODE = 'dragNode',
PROXY = 'proxy';
var Proxy = function() {
};
/**
* @attribute moveOnEnd
* @description Move the original node at the end of the drag. Default: true
* @type Boolean
*/
moveOnEnd: {
value: true
},
/**
* @attribute resizeFrame
* @description Make the Proxy node assume the size of the original node. Default: true
* @type Boolean
*/
resizeFrame: {
value: true
},
/**
* @attribute proxy
* @description Make this Draggable instance a Proxy instance. Default: false
* @type Boolean
*/
proxy: {
value: false,
set: function(v) {
this._setProxy(v);
}
},
/**
* @attribute positionProxy
* @description Make the Proxy node appear in the same place as the original node. Default: true
* @type Boolean
*/
value: true
},
/**
* @attribute borderStyle
* @description The default border style for the border of the proxy. Default: 1px solid #808080
* @type Boolean
*/
borderStyle: {
value: '1px solid #808080'
}
};
var proto = {
/**
* @private
* @method _setProxy
* @description Handler for the proxy config attribute
*/
_setProxy: function(v) {
if (v) {
this._createFrame();
}
} else {
}
},
/**
* @private
* @method _createFrame
* @description Create the proxy element if it doesn't already exist and set the DD.DDM._proxy value
*/
_createFrame: function() {
p.setStyles({
position: 'absolute',
display: 'none',
zIndex: '999',
top: '-999px',
left: '-999px',
});
}
},
/**
* @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() {
if (this.get('resizeFrame')) {
});
}
visibility: 'hidden',
display: 'block',
});
if (this.get('positionProxy')) {
}
},
/**
* @private
* @method initializer
* @description Lifecycle method
*/
initializer: function() {
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));
}
*/
}
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('moveOnEnd')) {
}
}
}
};
//Extend DD.Drag
//Set this new class as DD.Drag for other extensions
/**
* 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-constrain
*/
/**
* This class extends the dd-drag module to add the constraining methods to it. It supports constraining to a region, node or viewport. It also
* supports tick based moves and XY axis constraints.
* @class DragConstrained
* @extends Drag
* @constructor
*/
var DRAG_NODE = 'dragNode',
OFFSET_HEIGHT = 'offsetHeight',
OFFSET_WIDTH = 'offsetWidth';
var C = function() {
};
C.NAME = 'dragConstrained';
C.ATTRS = {
/**
* @attribute stickX
* @description Stick the drag movement to the X-Axis. Default: false
* @type Boolean
*/
stickX: {
value: false
},
/**
* @attribute stickY
* @description Stick the drag movement to the Y-Axis
* @type Boolean
*/
stickY: {
value: false
},
/**
* @attribute tickX
* @description The X tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
*/
tickX: {
value: false
},
/**
* @attribute tickY
* @description The Y tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
*/
tickY: {
value: false
},
/**
* @attribute tickXArray
* @description An array of page coordinates to use as X ticks for drag movement.
* @type Array
*/
tickXArray: {
value: false
},
/**
* @attribute tickYArray
* @description An array of page coordinates to use as Y ticks for drag movement.
* @type Array
*/
tickYArray: {
value: false
},
/**
* @attribute constrain2region
* @description An Object Literal containing a valid region (top, right, bottom, left) of page positions to constrain the drag node to.
* @type Object
*/
value: false,
get: function(r) {
var o = {};
Y.mix(o, r);
return o;
} else {
return false;
}
},
set: function (r) {
var o = {};
Y.mix(o, r);
return o;
} else {
return false;
}
} else if (r !== false) {
return false;
}
}
},
/**
* @attribute gutter
* @description CSS style string for the gutter of a region (supports negative values): '5 0' (sets top and bottom to 5px, left and right to 0px), '1 2 3 4' (top 1px, right 2px, bottom 3px, left 4px)
* @type String
*/
gutter: {
value: '0',
}
},
/**
* @attribute constrain2node
* @description Will attempt to constrain the drag node to the bounderies of this node.
* @type Object
*/
value: false,
set: function(n) {
if (!this.get('constrain2region')) {
if (node) {
return node;
}
} else if (this.get('constrain2region') !== false) {
}
return false;
}
},
/**
* @attribute constrain2view
* @description Will attempt to constrain the drag node to the bounderies of the viewport region.
* @type Object
*/
value: false
}
};
var proto = {
start: function() {
this._regionCache = null;
},
/**
* @private
* @property _regionCache
* @description Store a cache of the region that we are constraining to
* @type Object
*/
_regionCache: null,
/**
* @private
* @method _cacheRegion
* @description Get's the region and caches it, called from window.resize and when the cache is null
*/
_cacheRegion: function() {
},
/**
* @method getRegion
* @description Get the active region: viewport, node, custom region
* @param {Boolean} inc Include the node's height and width
* @return {Object}
*/
var r = {};
if (this.get('constrain2node')) {
if (!this._regionCache) {
this._cacheRegion();
}
r = Y.clone(this._regionCache);
} else if (this.get('constrain2region')) {
r = this.get('constrain2region');
} else if (this.get('constrain2view')) {
} else {
return false;
}
var g = this.get('gutter');
Y.each(g, function(i, n) {
if ((n == 'right') || (n == 'bottom')) {
r[n] -= i;
} else {
r[n] += i;
}
});
if (inc) {
}
return r;
},
/**
* @private
* @method _checkRegion
* @description
* @param {Array} _xy The XY to check if it's in the current region, if it isn't inside the region, it will reset the xy array to be inside the region.
* @return {Array} The new XY that is inside the region
*/
_checkRegion: function(_xy) {
r = this.getRegion(),
}
}
}
}
return _xy;
},
/**
* @method inRegion
* @description Checks if the XY passed or the dragNode is inside the active region.
* @param {Array} xy Optional XY to check, if not supplied this.get('dragNode').getXY() is used.
* @return {Boolean} True if the XY is inside the region, false otherwise.
*/
inside = false;
inside = true;
}
return inside;
},
/**
* @private
* @method _align
* @description Override of Drag _align to account for region checking and tick checking
* @param {Array} xy The XY to check for ticks and region
* @return {Array} The modified XY coords.
*/
r = this.getRegion(true);
if (this.get('stickX')) {
}
if (this.get('stickY')) {
}
if (r) {
}
return _xy;
},
/**
* @private
* @method _calcTicks
* @description Helper method to calculate the tick offsets for a given position
* @param {Number} pos The current X or Y position
* @param {Number} start The start X or Y position
* @param {Number} tick The X or Y tick increment
* @param {Number} off1 The min offset that we can't pass (region)
* @param {Number} off2 The max offset that we can't pass (region)
* @return {Number} The new position based on the tick calculation
*/
}
}
}
}
}
return pos;
},
/**
* @private
* @method _calcTickArray
* @description This method is used with the tickXArray and tickYArray config options
* @param {Number} pos The current X or Y position
* @param {Number} ticks The array containing our custom tick positions.
* @param {Number} off1 The min offset that we can't pass (region)
* @param {Number} off2 The max offset that we can't pass (region)
* @return The tick position
*/
return pos;
return ticks[0];
} else {
for (i = 0; i < len; i++) {
next = (i + 1);
if (ticks[i]) {
} else {
}
}
}
return ret;
}
}
}
},
/**
* @private
* @method _checkTicks
* @description This method delegates the proper helper method for tick calculations
* @param {Array} xy The XY coords for the Drag
* @param {Object} r The optional region that we are bound to.
* @return {Array} The calced XY coords
*/
_checkTicks: function(xy, r) {
}
}
if (this.get('tickXArray')) {
}
if (this.get('tickYArray')) {
}
return xy;
}
};
//Extend DD.Drag
//Set this to DD.Drag for other extensions
/**
* This is a simple Drag plugin that can be attached to a Node via the plug method.
* @module dd-plugin
* @submodule dd-plugin
*/
/**
* This is a simple Drag plugin that can be attached to a Node via the plug method.
* @class DragPlugin
* @extends Drag
* @constructor
* @namespace plugin
*/
};
/**
* @property NAME
* @description dd-plugin
* @type {String}
*/
/**
* @property NS
* @description The Drag instance will be placed on the Node instance under the dd namespace. It can be accessed via Node.dd;
* @type {String}
*/
Y.namespace('plugin');
/**
* 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];
}
}
}
}
});
/**
* This is a simple Drop plugin that can be attached to a Node via the plug method.
* @module dd-plugin
* @submodule dd-drop-plugin
*/
/**
* This is a simple Drop plugin that can be attached to a Node via the plug method.
* @class DropPlugin
* @extends Drop
* @constructor
* @namespace plugin
*/
};
/**
* @property NAME
* @description dd-drop-plugin
* @type {String}
*/
/**
* @property NS
* @description The Drop instance will be placed on the Node instance under the drop namespace. It can be accessed via Node.drop;
* @type {String}
*/
Y.namespace('plugin');
YUI.add('dd', function(Y){}, '@VERSION@' ,{use:['dd-ddm-base', 'dd-ddm', 'dd-ddm-drop', 'dd-drag', 'dd-proxy', 'dd-constrain', 'dd-plugin', 'dd-drop', 'dd-drop-plugin'], skinnable:false});