Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
4771 lines
155 KiB
4771 lines
155 KiB
/*!
|
|
* Ext JS Library 3.2.0
|
|
* Copyright(c) 2006-2010 Ext JS, Inc.
|
|
* licensing@extjs.com
|
|
* http://www.extjs.com/license
|
|
*/
|
|
/*
|
|
* These classes are derivatives of the similarly named classes in the YUI Library.
|
|
* The original license:
|
|
* Copyright (c) 2006, Yahoo! Inc. All rights reserved.
|
|
* Code licensed under the BSD License:
|
|
* http://developer.yahoo.net/yui/license.txt
|
|
*/
|
|
|
|
(function() {
|
|
|
|
var Event=Ext.EventManager;
|
|
var Dom=Ext.lib.Dom;
|
|
|
|
/**
|
|
* @class Ext.dd.DragDrop
|
|
* Defines the interface and base operation of items that that can be
|
|
* dragged or can be drop targets. It was designed to be extended, overriding
|
|
* the event handlers for startDrag, onDrag, onDragOver and onDragOut.
|
|
* Up to three html elements can be associated with a DragDrop instance:
|
|
* <ul>
|
|
* <li>linked element: the element that is passed into the constructor.
|
|
* This is the element which defines the boundaries for interaction with
|
|
* other DragDrop objects.</li>
|
|
* <li>handle element(s): The drag operation only occurs if the element that
|
|
* was clicked matches a handle element. By default this is the linked
|
|
* element, but there are times that you will want only a portion of the
|
|
* linked element to initiate the drag operation, and the setHandleElId()
|
|
* method provides a way to define this.</li>
|
|
* <li>drag element: this represents the element that would be moved along
|
|
* with the cursor during a drag operation. By default, this is the linked
|
|
* element itself as in {@link Ext.dd.DD}. setDragElId() lets you define
|
|
* a separate element that would be moved, as in {@link Ext.dd.DDProxy}.
|
|
* </li>
|
|
* </ul>
|
|
* This class should not be instantiated until the onload event to ensure that
|
|
* the associated elements are available.
|
|
* The following would define a DragDrop obj that would interact with any
|
|
* other DragDrop obj in the "group1" group:
|
|
* <pre>
|
|
* dd = new Ext.dd.DragDrop("div1", "group1");
|
|
* </pre>
|
|
* Since none of the event handlers have been implemented, nothing would
|
|
* actually happen if you were to run the code above. Normally you would
|
|
* override this class or one of the default implementations, but you can
|
|
* also override the methods you want on an instance of the class...
|
|
* <pre>
|
|
* dd.onDragDrop = function(e, id) {
|
|
* alert("dd was dropped on " + id);
|
|
* }
|
|
* </pre>
|
|
* @constructor
|
|
* @param {String} id of the element that is linked to this instance
|
|
* @param {String} sGroup the group of related DragDrop objects
|
|
* @param {object} config an object containing configurable attributes
|
|
* Valid properties for DragDrop:
|
|
* padding, isTarget, maintainOffset, primaryButtonOnly
|
|
*/
|
|
Ext.dd.DragDrop = function(id, sGroup, config) {
|
|
if(id) {
|
|
this.init(id, sGroup, config);
|
|
}
|
|
};
|
|
|
|
Ext.dd.DragDrop.prototype = {
|
|
|
|
/**
|
|
* Set to false to enable a DragDrop object to fire drag events while dragging
|
|
* over its own Element. Defaults to true - DragDrop objects do not by default
|
|
* fire drag events to themselves.
|
|
* @property ignoreSelf
|
|
* @type Boolean
|
|
*/
|
|
|
|
/**
|
|
* The id of the element associated with this object. This is what we
|
|
* refer to as the "linked element" because the size and position of
|
|
* this element is used to determine when the drag and drop objects have
|
|
* interacted.
|
|
* @property id
|
|
* @type String
|
|
*/
|
|
id: null,
|
|
|
|
/**
|
|
* Configuration attributes passed into the constructor
|
|
* @property config
|
|
* @type object
|
|
*/
|
|
config: null,
|
|
|
|
/**
|
|
* The id of the element that will be dragged. By default this is same
|
|
* as the linked element, but could be changed to another element. Ex:
|
|
* Ext.dd.DDProxy
|
|
* @property dragElId
|
|
* @type String
|
|
* @private
|
|
*/
|
|
dragElId: null,
|
|
|
|
/**
|
|
* The ID of the element that initiates the drag operation. By default
|
|
* this is the linked element, but could be changed to be a child of this
|
|
* element. This lets us do things like only starting the drag when the
|
|
* header element within the linked html element is clicked.
|
|
* @property handleElId
|
|
* @type String
|
|
* @private
|
|
*/
|
|
handleElId: null,
|
|
|
|
/**
|
|
* An object who's property names identify HTML tags to be considered invalid as drag handles.
|
|
* A non-null property value identifies the tag as invalid. Defaults to the
|
|
* following value which prevents drag operations from being initiated by <a> elements:<pre><code>
|
|
{
|
|
A: "A"
|
|
}</code></pre>
|
|
* @property invalidHandleTypes
|
|
* @type Object
|
|
*/
|
|
invalidHandleTypes: null,
|
|
|
|
/**
|
|
* An object who's property names identify the IDs of elements to be considered invalid as drag handles.
|
|
* A non-null property value identifies the ID as invalid. For example, to prevent
|
|
* dragging from being initiated on element ID "foo", use:<pre><code>
|
|
{
|
|
foo: true
|
|
}</code></pre>
|
|
* @property invalidHandleIds
|
|
* @type Object
|
|
*/
|
|
invalidHandleIds: null,
|
|
|
|
/**
|
|
* An Array of CSS class names for elements to be considered in valid as drag handles.
|
|
* @property invalidHandleClasses
|
|
* @type Array
|
|
*/
|
|
invalidHandleClasses: null,
|
|
|
|
/**
|
|
* The linked element's absolute X position at the time the drag was
|
|
* started
|
|
* @property startPageX
|
|
* @type int
|
|
* @private
|
|
*/
|
|
startPageX: 0,
|
|
|
|
/**
|
|
* The linked element's absolute X position at the time the drag was
|
|
* started
|
|
* @property startPageY
|
|
* @type int
|
|
* @private
|
|
*/
|
|
startPageY: 0,
|
|
|
|
/**
|
|
* The group defines a logical collection of DragDrop objects that are
|
|
* related. Instances only get events when interacting with other
|
|
* DragDrop object in the same group. This lets us define multiple
|
|
* groups using a single DragDrop subclass if we want.
|
|
* @property groups
|
|
* @type object An object in the format {'group1':true, 'group2':true}
|
|
*/
|
|
groups: null,
|
|
|
|
/**
|
|
* Individual drag/drop instances can be locked. This will prevent
|
|
* onmousedown start drag.
|
|
* @property locked
|
|
* @type boolean
|
|
* @private
|
|
*/
|
|
locked: false,
|
|
|
|
/**
|
|
* Lock this instance
|
|
* @method lock
|
|
*/
|
|
lock: function() {
|
|
this.locked = true;
|
|
},
|
|
|
|
/**
|
|
* When set to true, other DD objects in cooperating DDGroups do not receive
|
|
* notification events when this DD object is dragged over them. Defaults to false.
|
|
* @property moveOnly
|
|
* @type boolean
|
|
*/
|
|
moveOnly: false,
|
|
|
|
/**
|
|
* Unlock this instace
|
|
* @method unlock
|
|
*/
|
|
unlock: function() {
|
|
this.locked = false;
|
|
},
|
|
|
|
/**
|
|
* By default, all instances can be a drop target. This can be disabled by
|
|
* setting isTarget to false.
|
|
* @property isTarget
|
|
* @type boolean
|
|
*/
|
|
isTarget: true,
|
|
|
|
/**
|
|
* The padding configured for this drag and drop object for calculating
|
|
* the drop zone intersection with this object.
|
|
* @property padding
|
|
* @type int[] An array containing the 4 padding values: [top, right, bottom, left]
|
|
*/
|
|
padding: null,
|
|
|
|
/**
|
|
* Cached reference to the linked element
|
|
* @property _domRef
|
|
* @private
|
|
*/
|
|
_domRef: null,
|
|
|
|
/**
|
|
* Internal typeof flag
|
|
* @property __ygDragDrop
|
|
* @private
|
|
*/
|
|
__ygDragDrop: true,
|
|
|
|
/**
|
|
* Set to true when horizontal contraints are applied
|
|
* @property constrainX
|
|
* @type boolean
|
|
* @private
|
|
*/
|
|
constrainX: false,
|
|
|
|
/**
|
|
* Set to true when vertical contraints are applied
|
|
* @property constrainY
|
|
* @type boolean
|
|
* @private
|
|
*/
|
|
constrainY: false,
|
|
|
|
/**
|
|
* The left constraint
|
|
* @property minX
|
|
* @type int
|
|
* @private
|
|
*/
|
|
minX: 0,
|
|
|
|
/**
|
|
* The right constraint
|
|
* @property maxX
|
|
* @type int
|
|
* @private
|
|
*/
|
|
maxX: 0,
|
|
|
|
/**
|
|
* The up constraint
|
|
* @property minY
|
|
* @type int
|
|
* @private
|
|
*/
|
|
minY: 0,
|
|
|
|
/**
|
|
* The down constraint
|
|
* @property maxY
|
|
* @type int
|
|
* @private
|
|
*/
|
|
maxY: 0,
|
|
|
|
/**
|
|
* Maintain offsets when we resetconstraints. Set to true when you want
|
|
* the position of the element relative to its parent to stay the same
|
|
* when the page changes
|
|
*
|
|
* @property maintainOffset
|
|
* @type boolean
|
|
*/
|
|
maintainOffset: false,
|
|
|
|
/**
|
|
* Array of pixel locations the element will snap to if we specified a
|
|
* horizontal graduation/interval. This array is generated automatically
|
|
* when you define a tick interval.
|
|
* @property xTicks
|
|
* @type int[]
|
|
*/
|
|
xTicks: null,
|
|
|
|
/**
|
|
* Array of pixel locations the element will snap to if we specified a
|
|
* vertical graduation/interval. This array is generated automatically
|
|
* when you define a tick interval.
|
|
* @property yTicks
|
|
* @type int[]
|
|
*/
|
|
yTicks: null,
|
|
|
|
/**
|
|
* By default the drag and drop instance will only respond to the primary
|
|
* button click (left button for a right-handed mouse). Set to true to
|
|
* allow drag and drop to start with any mouse click that is propogated
|
|
* by the browser
|
|
* @property primaryButtonOnly
|
|
* @type boolean
|
|
*/
|
|
primaryButtonOnly: true,
|
|
|
|
/**
|
|
* The available property is false until the linked dom element is accessible.
|
|
* @property available
|
|
* @type boolean
|
|
*/
|
|
available: false,
|
|
|
|
/**
|
|
* By default, drags can only be initiated if the mousedown occurs in the
|
|
* region the linked element is. This is done in part to work around a
|
|
* bug in some browsers that mis-report the mousedown if the previous
|
|
* mouseup happened outside of the window. This property is set to true
|
|
* if outer handles are defined.
|
|
*
|
|
* @property hasOuterHandles
|
|
* @type boolean
|
|
* @default false
|
|
*/
|
|
hasOuterHandles: false,
|
|
|
|
/**
|
|
* Code that executes immediately before the startDrag event
|
|
* @method b4StartDrag
|
|
* @private
|
|
*/
|
|
b4StartDrag: function(x, y) { },
|
|
|
|
/**
|
|
* Abstract method called after a drag/drop object is clicked
|
|
* and the drag or mousedown time thresholds have beeen met.
|
|
* @method startDrag
|
|
* @param {int} X click location
|
|
* @param {int} Y click location
|
|
*/
|
|
startDrag: function(x, y) { /* override this */ },
|
|
|
|
/**
|
|
* Code that executes immediately before the onDrag event
|
|
* @method b4Drag
|
|
* @private
|
|
*/
|
|
b4Drag: function(e) { },
|
|
|
|
/**
|
|
* Abstract method called during the onMouseMove event while dragging an
|
|
* object.
|
|
* @method onDrag
|
|
* @param {Event} e the mousemove event
|
|
*/
|
|
onDrag: function(e) { /* override this */ },
|
|
|
|
/**
|
|
* Abstract method called when this element fist begins hovering over
|
|
* another DragDrop obj
|
|
* @method onDragEnter
|
|
* @param {Event} e the mousemove event
|
|
* @param {String|DragDrop[]} id In POINT mode, the element
|
|
* id this is hovering over. In INTERSECT mode, an array of one or more
|
|
* dragdrop items being hovered over.
|
|
*/
|
|
onDragEnter: function(e, id) { /* override this */ },
|
|
|
|
/**
|
|
* Code that executes immediately before the onDragOver event
|
|
* @method b4DragOver
|
|
* @private
|
|
*/
|
|
b4DragOver: function(e) { },
|
|
|
|
/**
|
|
* Abstract method called when this element is hovering over another
|
|
* DragDrop obj
|
|
* @method onDragOver
|
|
* @param {Event} e the mousemove event
|
|
* @param {String|DragDrop[]} id In POINT mode, the element
|
|
* id this is hovering over. In INTERSECT mode, an array of dd items
|
|
* being hovered over.
|
|
*/
|
|
onDragOver: function(e, id) { /* override this */ },
|
|
|
|
/**
|
|
* Code that executes immediately before the onDragOut event
|
|
* @method b4DragOut
|
|
* @private
|
|
*/
|
|
b4DragOut: function(e) { },
|
|
|
|
/**
|
|
* Abstract method called when we are no longer hovering over an element
|
|
* @method onDragOut
|
|
* @param {Event} e the mousemove event
|
|
* @param {String|DragDrop[]} id In POINT mode, the element
|
|
* id this was hovering over. In INTERSECT mode, an array of dd items
|
|
* that the mouse is no longer over.
|
|
*/
|
|
onDragOut: function(e, id) { /* override this */ },
|
|
|
|
/**
|
|
* Code that executes immediately before the onDragDrop event
|
|
* @method b4DragDrop
|
|
* @private
|
|
*/
|
|
b4DragDrop: function(e) { },
|
|
|
|
/**
|
|
* Abstract method called when this item is dropped on another DragDrop
|
|
* obj
|
|
* @method onDragDrop
|
|
* @param {Event} e the mouseup event
|
|
* @param {String|DragDrop[]} id In POINT mode, the element
|
|
* id this was dropped on. In INTERSECT mode, an array of dd items this
|
|
* was dropped on.
|
|
*/
|
|
onDragDrop: function(e, id) { /* override this */ },
|
|
|
|
/**
|
|
* Abstract method called when this item is dropped on an area with no
|
|
* drop target
|
|
* @method onInvalidDrop
|
|
* @param {Event} e the mouseup event
|
|
*/
|
|
onInvalidDrop: function(e) { /* override this */ },
|
|
|
|
/**
|
|
* Code that executes immediately before the endDrag event
|
|
* @method b4EndDrag
|
|
* @private
|
|
*/
|
|
b4EndDrag: function(e) { },
|
|
|
|
/**
|
|
* Fired when we are done dragging the object
|
|
* @method endDrag
|
|
* @param {Event} e the mouseup event
|
|
*/
|
|
endDrag: function(e) { /* override this */ },
|
|
|
|
/**
|
|
* Code executed immediately before the onMouseDown event
|
|
* @method b4MouseDown
|
|
* @param {Event} e the mousedown event
|
|
* @private
|
|
*/
|
|
b4MouseDown: function(e) { },
|
|
|
|
/**
|
|
* Event handler that fires when a drag/drop obj gets a mousedown
|
|
* @method onMouseDown
|
|
* @param {Event} e the mousedown event
|
|
*/
|
|
onMouseDown: function(e) { /* override this */ },
|
|
|
|
/**
|
|
* Event handler that fires when a drag/drop obj gets a mouseup
|
|
* @method onMouseUp
|
|
* @param {Event} e the mouseup event
|
|
*/
|
|
onMouseUp: function(e) { /* override this */ },
|
|
|
|
/**
|
|
* Override the onAvailable method to do what is needed after the initial
|
|
* position was determined.
|
|
* @method onAvailable
|
|
*/
|
|
onAvailable: function () {
|
|
},
|
|
|
|
/**
|
|
* Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
|
|
* @type Object
|
|
*/
|
|
defaultPadding : {left:0, right:0, top:0, bottom:0},
|
|
|
|
/**
|
|
* Initializes the drag drop object's constraints to restrict movement to a certain element.
|
|
*
|
|
* Usage:
|
|
<pre><code>
|
|
var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
|
|
{ dragElId: "existingProxyDiv" });
|
|
dd.startDrag = function(){
|
|
this.constrainTo("parent-id");
|
|
};
|
|
</code></pre>
|
|
* Or you can initalize it using the {@link Ext.Element} object:
|
|
<pre><code>
|
|
Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
|
|
startDrag : function(){
|
|
this.constrainTo("parent-id");
|
|
}
|
|
});
|
|
</code></pre>
|
|
* @param {Mixed} constrainTo The element to constrain to.
|
|
* @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
|
|
* and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
|
|
* an object containing the sides to pad. For example: {right:10, bottom:10}
|
|
* @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
|
|
*/
|
|
constrainTo : function(constrainTo, pad, inContent){
|
|
if(Ext.isNumber(pad)){
|
|
pad = {left: pad, right:pad, top:pad, bottom:pad};
|
|
}
|
|
pad = pad || this.defaultPadding;
|
|
var b = Ext.get(this.getEl()).getBox(),
|
|
ce = Ext.get(constrainTo),
|
|
s = ce.getScroll(),
|
|
c,
|
|
cd = ce.dom;
|
|
if(cd == document.body){
|
|
c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()};
|
|
}else{
|
|
var xy = ce.getXY();
|
|
c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
|
|
}
|
|
|
|
|
|
var topSpace = b.y - c.y,
|
|
leftSpace = b.x - c.x;
|
|
|
|
this.resetConstraints();
|
|
this.setXConstraint(leftSpace - (pad.left||0), // left
|
|
c.width - leftSpace - b.width - (pad.right||0), //right
|
|
this.xTickSize
|
|
);
|
|
this.setYConstraint(topSpace - (pad.top||0), //top
|
|
c.height - topSpace - b.height - (pad.bottom||0), //bottom
|
|
this.yTickSize
|
|
);
|
|
},
|
|
|
|
/**
|
|
* Returns a reference to the linked element
|
|
* @method getEl
|
|
* @return {HTMLElement} the html element
|
|
*/
|
|
getEl: function() {
|
|
if (!this._domRef) {
|
|
this._domRef = Ext.getDom(this.id);
|
|
}
|
|
|
|
return this._domRef;
|
|
},
|
|
|
|
/**
|
|
* Returns a reference to the actual element to drag. By default this is
|
|
* the same as the html element, but it can be assigned to another
|
|
* element. An example of this can be found in Ext.dd.DDProxy
|
|
* @method getDragEl
|
|
* @return {HTMLElement} the html element
|
|
*/
|
|
getDragEl: function() {
|
|
return Ext.getDom(this.dragElId);
|
|
},
|
|
|
|
/**
|
|
* Sets up the DragDrop object. Must be called in the constructor of any
|
|
* Ext.dd.DragDrop subclass
|
|
* @method init
|
|
* @param id the id of the linked element
|
|
* @param {String} sGroup the group of related items
|
|
* @param {object} config configuration attributes
|
|
*/
|
|
init: function(id, sGroup, config) {
|
|
this.initTarget(id, sGroup, config);
|
|
Event.on(this.id, "mousedown", this.handleMouseDown, this);
|
|
// Event.on(this.id, "selectstart", Event.preventDefault);
|
|
},
|
|
|
|
/**
|
|
* Initializes Targeting functionality only... the object does not
|
|
* get a mousedown handler.
|
|
* @method initTarget
|
|
* @param id the id of the linked element
|
|
* @param {String} sGroup the group of related items
|
|
* @param {object} config configuration attributes
|
|
*/
|
|
initTarget: function(id, sGroup, config) {
|
|
|
|
// configuration attributes
|
|
this.config = config || {};
|
|
|
|
// create a local reference to the drag and drop manager
|
|
this.DDM = Ext.dd.DDM;
|
|
// initialize the groups array
|
|
this.groups = {};
|
|
|
|
// assume that we have an element reference instead of an id if the
|
|
// parameter is not a string
|
|
if (typeof id !== "string") {
|
|
id = Ext.id(id);
|
|
}
|
|
|
|
// set the id
|
|
this.id = id;
|
|
|
|
// add to an interaction group
|
|
this.addToGroup((sGroup) ? sGroup : "default");
|
|
|
|
// We don't want to register this as the handle with the manager
|
|
// so we just set the id rather than calling the setter.
|
|
this.handleElId = id;
|
|
|
|
// the linked element is the element that gets dragged by default
|
|
this.setDragElId(id);
|
|
|
|
// by default, clicked anchors will not start drag operations.
|
|
this.invalidHandleTypes = { A: "A" };
|
|
this.invalidHandleIds = {};
|
|
this.invalidHandleClasses = [];
|
|
|
|
this.applyConfig();
|
|
|
|
this.handleOnAvailable();
|
|
},
|
|
|
|
/**
|
|
* Applies the configuration parameters that were passed into the constructor.
|
|
* This is supposed to happen at each level through the inheritance chain. So
|
|
* a DDProxy implentation will execute apply config on DDProxy, DD, and
|
|
* DragDrop in order to get all of the parameters that are available in
|
|
* each object.
|
|
* @method applyConfig
|
|
*/
|
|
applyConfig: function() {
|
|
|
|
// configurable properties:
|
|
// padding, isTarget, maintainOffset, primaryButtonOnly
|
|
this.padding = this.config.padding || [0, 0, 0, 0];
|
|
this.isTarget = (this.config.isTarget !== false);
|
|
this.maintainOffset = (this.config.maintainOffset);
|
|
this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
|
|
|
|
},
|
|
|
|
/**
|
|
* Executed when the linked element is available
|
|
* @method handleOnAvailable
|
|
* @private
|
|
*/
|
|
handleOnAvailable: function() {
|
|
this.available = true;
|
|
this.resetConstraints();
|
|
this.onAvailable();
|
|
},
|
|
|
|
/**
|
|
* Configures the padding for the target zone in px. Effectively expands
|
|
* (or reduces) the virtual object size for targeting calculations.
|
|
* Supports css-style shorthand; if only one parameter is passed, all sides
|
|
* will have that padding, and if only two are passed, the top and bottom
|
|
* will have the first param, the left and right the second.
|
|
* @method setPadding
|
|
* @param {int} iTop Top pad
|
|
* @param {int} iRight Right pad
|
|
* @param {int} iBot Bot pad
|
|
* @param {int} iLeft Left pad
|
|
*/
|
|
setPadding: function(iTop, iRight, iBot, iLeft) {
|
|
// this.padding = [iLeft, iRight, iTop, iBot];
|
|
if (!iRight && 0 !== iRight) {
|
|
this.padding = [iTop, iTop, iTop, iTop];
|
|
} else if (!iBot && 0 !== iBot) {
|
|
this.padding = [iTop, iRight, iTop, iRight];
|
|
} else {
|
|
this.padding = [iTop, iRight, iBot, iLeft];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Stores the initial placement of the linked element.
|
|
* @method setInitPosition
|
|
* @param {int} diffX the X offset, default 0
|
|
* @param {int} diffY the Y offset, default 0
|
|
*/
|
|
setInitPosition: function(diffX, diffY) {
|
|
var el = this.getEl();
|
|
|
|
if (!this.DDM.verifyEl(el)) {
|
|
return;
|
|
}
|
|
|
|
var dx = diffX || 0;
|
|
var dy = diffY || 0;
|
|
|
|
var p = Dom.getXY( el );
|
|
|
|
this.initPageX = p[0] - dx;
|
|
this.initPageY = p[1] - dy;
|
|
|
|
this.lastPageX = p[0];
|
|
this.lastPageY = p[1];
|
|
|
|
this.setStartPosition(p);
|
|
},
|
|
|
|
/**
|
|
* Sets the start position of the element. This is set when the obj
|
|
* is initialized, the reset when a drag is started.
|
|
* @method setStartPosition
|
|
* @param pos current position (from previous lookup)
|
|
* @private
|
|
*/
|
|
setStartPosition: function(pos) {
|
|
var p = pos || Dom.getXY( this.getEl() );
|
|
this.deltaSetXY = null;
|
|
|
|
this.startPageX = p[0];
|
|
this.startPageY = p[1];
|
|
},
|
|
|
|
/**
|
|
* Add this instance to a group of related drag/drop objects. All
|
|
* instances belong to at least one group, and can belong to as many
|
|
* groups as needed.
|
|
* @method addToGroup
|
|
* @param sGroup {string} the name of the group
|
|
*/
|
|
addToGroup: function(sGroup) {
|
|
this.groups[sGroup] = true;
|
|
this.DDM.regDragDrop(this, sGroup);
|
|
},
|
|
|
|
/**
|
|
* Remove's this instance from the supplied interaction group
|
|
* @method removeFromGroup
|
|
* @param {string} sGroup The group to drop
|
|
*/
|
|
removeFromGroup: function(sGroup) {
|
|
if (this.groups[sGroup]) {
|
|
delete this.groups[sGroup];
|
|
}
|
|
|
|
this.DDM.removeDDFromGroup(this, sGroup);
|
|
},
|
|
|
|
/**
|
|
* Allows you to specify that an element other than the linked element
|
|
* will be moved with the cursor during a drag
|
|
* @method setDragElId
|
|
* @param id {string} the id of the element that will be used to initiate the drag
|
|
*/
|
|
setDragElId: function(id) {
|
|
this.dragElId = id;
|
|
},
|
|
|
|
/**
|
|
* Allows you to specify a child of the linked element that should be
|
|
* used to initiate the drag operation. An example of this would be if
|
|
* you have a content div with text and links. Clicking anywhere in the
|
|
* content area would normally start the drag operation. Use this method
|
|
* to specify that an element inside of the content div is the element
|
|
* that starts the drag operation.
|
|
* @method setHandleElId
|
|
* @param id {string} the id of the element that will be used to
|
|
* initiate the drag.
|
|
*/
|
|
setHandleElId: function(id) {
|
|
if (typeof id !== "string") {
|
|
id = Ext.id(id);
|
|
}
|
|
this.handleElId = id;
|
|
this.DDM.regHandle(this.id, id);
|
|
},
|
|
|
|
/**
|
|
* Allows you to set an element outside of the linked element as a drag
|
|
* handle
|
|
* @method setOuterHandleElId
|
|
* @param id the id of the element that will be used to initiate the drag
|
|
*/
|
|
setOuterHandleElId: function(id) {
|
|
if (typeof id !== "string") {
|
|
id = Ext.id(id);
|
|
}
|
|
Event.on(id, "mousedown",
|
|
this.handleMouseDown, this);
|
|
this.setHandleElId(id);
|
|
|
|
this.hasOuterHandles = true;
|
|
},
|
|
|
|
/**
|
|
* Remove all drag and drop hooks for this element
|
|
* @method unreg
|
|
*/
|
|
unreg: function() {
|
|
Event.un(this.id, "mousedown",
|
|
this.handleMouseDown);
|
|
this._domRef = null;
|
|
this.DDM._remove(this);
|
|
},
|
|
|
|
destroy : function(){
|
|
this.unreg();
|
|
},
|
|
|
|
/**
|
|
* Returns true if this instance is locked, or the drag drop mgr is locked
|
|
* (meaning that all drag/drop is disabled on the page.)
|
|
* @method isLocked
|
|
* @return {boolean} true if this obj or all drag/drop is locked, else
|
|
* false
|
|
*/
|
|
isLocked: function() {
|
|
return (this.DDM.isLocked() || this.locked);
|
|
},
|
|
|
|
/**
|
|
* Fired when this object is clicked
|
|
* @method handleMouseDown
|
|
* @param {Event} e
|
|
* @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
|
|
* @private
|
|
*/
|
|
handleMouseDown: function(e, oDD){
|
|
if (this.primaryButtonOnly && e.button != 0) {
|
|
return;
|
|
}
|
|
|
|
if (this.isLocked()) {
|
|
return;
|
|
}
|
|
|
|
this.DDM.refreshCache(this.groups);
|
|
|
|
var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e));
|
|
if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
|
|
} else {
|
|
if (this.clickValidator(e)) {
|
|
|
|
// set the initial element position
|
|
this.setStartPosition();
|
|
|
|
this.b4MouseDown(e);
|
|
this.onMouseDown(e);
|
|
|
|
this.DDM.handleMouseDown(e, this);
|
|
|
|
this.DDM.stopEvent(e);
|
|
} else {
|
|
|
|
|
|
}
|
|
}
|
|
},
|
|
|
|
clickValidator: function(e) {
|
|
var target = e.getTarget();
|
|
return ( this.isValidHandleChild(target) &&
|
|
(this.id == this.handleElId ||
|
|
this.DDM.handleWasClicked(target, this.id)) );
|
|
},
|
|
|
|
/**
|
|
* Allows you to specify a tag name that should not start a drag operation
|
|
* when clicked. This is designed to facilitate embedding links within a
|
|
* drag handle that do something other than start the drag.
|
|
* @method addInvalidHandleType
|
|
* @param {string} tagName the type of element to exclude
|
|
*/
|
|
addInvalidHandleType: function(tagName) {
|
|
var type = tagName.toUpperCase();
|
|
this.invalidHandleTypes[type] = type;
|
|
},
|
|
|
|
/**
|
|
* Lets you to specify an element id for a child of a drag handle
|
|
* that should not initiate a drag
|
|
* @method addInvalidHandleId
|
|
* @param {string} id the element id of the element you wish to ignore
|
|
*/
|
|
addInvalidHandleId: function(id) {
|
|
if (typeof id !== "string") {
|
|
id = Ext.id(id);
|
|
}
|
|
this.invalidHandleIds[id] = id;
|
|
},
|
|
|
|
/**
|
|
* Lets you specify a css class of elements that will not initiate a drag
|
|
* @method addInvalidHandleClass
|
|
* @param {string} cssClass the class of the elements you wish to ignore
|
|
*/
|
|
addInvalidHandleClass: function(cssClass) {
|
|
this.invalidHandleClasses.push(cssClass);
|
|
},
|
|
|
|
/**
|
|
* Unsets an excluded tag name set by addInvalidHandleType
|
|
* @method removeInvalidHandleType
|
|
* @param {string} tagName the type of element to unexclude
|
|
*/
|
|
removeInvalidHandleType: function(tagName) {
|
|
var type = tagName.toUpperCase();
|
|
// this.invalidHandleTypes[type] = null;
|
|
delete this.invalidHandleTypes[type];
|
|
},
|
|
|
|
/**
|
|
* Unsets an invalid handle id
|
|
* @method removeInvalidHandleId
|
|
* @param {string} id the id of the element to re-enable
|
|
*/
|
|
removeInvalidHandleId: function(id) {
|
|
if (typeof id !== "string") {
|
|
id = Ext.id(id);
|
|
}
|
|
delete this.invalidHandleIds[id];
|
|
},
|
|
|
|
/**
|
|
* Unsets an invalid css class
|
|
* @method removeInvalidHandleClass
|
|
* @param {string} cssClass the class of the element(s) you wish to
|
|
* re-enable
|
|
*/
|
|
removeInvalidHandleClass: function(cssClass) {
|
|
for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
|
|
if (this.invalidHandleClasses[i] == cssClass) {
|
|
delete this.invalidHandleClasses[i];
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Checks the tag exclusion list to see if this click should be ignored
|
|
* @method isValidHandleChild
|
|
* @param {HTMLElement} node the HTMLElement to evaluate
|
|
* @return {boolean} true if this is a valid tag type, false if not
|
|
*/
|
|
isValidHandleChild: function(node) {
|
|
|
|
var valid = true;
|
|
// var n = (node.nodeName == "#text") ? node.parentNode : node;
|
|
var nodeName;
|
|
try {
|
|
nodeName = node.nodeName.toUpperCase();
|
|
} catch(e) {
|
|
nodeName = node.nodeName;
|
|
}
|
|
valid = valid && !this.invalidHandleTypes[nodeName];
|
|
valid = valid && !this.invalidHandleIds[node.id];
|
|
|
|
for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
|
|
valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]);
|
|
}
|
|
|
|
|
|
return valid;
|
|
|
|
},
|
|
|
|
/**
|
|
* Create the array of horizontal tick marks if an interval was specified
|
|
* in setXConstraint().
|
|
* @method setXTicks
|
|
* @private
|
|
*/
|
|
setXTicks: function(iStartX, iTickSize) {
|
|
this.xTicks = [];
|
|
this.xTickSize = iTickSize;
|
|
|
|
var tickMap = {};
|
|
|
|
for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
|
|
if (!tickMap[i]) {
|
|
this.xTicks[this.xTicks.length] = i;
|
|
tickMap[i] = true;
|
|
}
|
|
}
|
|
|
|
for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
|
|
if (!tickMap[i]) {
|
|
this.xTicks[this.xTicks.length] = i;
|
|
tickMap[i] = true;
|
|
}
|
|
}
|
|
|
|
this.xTicks.sort(this.DDM.numericSort) ;
|
|
},
|
|
|
|
/**
|
|
* Create the array of vertical tick marks if an interval was specified in
|
|
* setYConstraint().
|
|
* @method setYTicks
|
|
* @private
|
|
*/
|
|
setYTicks: function(iStartY, iTickSize) {
|
|
this.yTicks = [];
|
|
this.yTickSize = iTickSize;
|
|
|
|
var tickMap = {};
|
|
|
|
for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
|
|
if (!tickMap[i]) {
|
|
this.yTicks[this.yTicks.length] = i;
|
|
tickMap[i] = true;
|
|
}
|
|
}
|
|
|
|
for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
|
|
if (!tickMap[i]) {
|
|
this.yTicks[this.yTicks.length] = i;
|
|
tickMap[i] = true;
|
|
}
|
|
}
|
|
|
|
this.yTicks.sort(this.DDM.numericSort) ;
|
|
},
|
|
|
|
/**
|
|
* By default, the element can be dragged any place on the screen. Use
|
|
* this method to limit the horizontal travel of the element. Pass in
|
|
* 0,0 for the parameters if you want to lock the drag to the y axis.
|
|
* @method setXConstraint
|
|
* @param {int} iLeft the number of pixels the element can move to the left
|
|
* @param {int} iRight the number of pixels the element can move to the
|
|
* right
|
|
* @param {int} iTickSize optional parameter for specifying that the
|
|
* element
|
|
* should move iTickSize pixels at a time.
|
|
*/
|
|
setXConstraint: function(iLeft, iRight, iTickSize) {
|
|
this.leftConstraint = iLeft;
|
|
this.rightConstraint = iRight;
|
|
|
|
this.minX = this.initPageX - iLeft;
|
|
this.maxX = this.initPageX + iRight;
|
|
if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
|
|
|
|
this.constrainX = true;
|
|
},
|
|
|
|
/**
|
|
* Clears any constraints applied to this instance. Also clears ticks
|
|
* since they can't exist independent of a constraint at this time.
|
|
* @method clearConstraints
|
|
*/
|
|
clearConstraints: function() {
|
|
this.constrainX = false;
|
|
this.constrainY = false;
|
|
this.clearTicks();
|
|
},
|
|
|
|
/**
|
|
* Clears any tick interval defined for this instance
|
|
* @method clearTicks
|
|
*/
|
|
clearTicks: function() {
|
|
this.xTicks = null;
|
|
this.yTicks = null;
|
|
this.xTickSize = 0;
|
|
this.yTickSize = 0;
|
|
},
|
|
|
|
/**
|
|
* By default, the element can be dragged any place on the screen. Set
|
|
* this to limit the vertical travel of the element. Pass in 0,0 for the
|
|
* parameters if you want to lock the drag to the x axis.
|
|
* @method setYConstraint
|
|
* @param {int} iUp the number of pixels the element can move up
|
|
* @param {int} iDown the number of pixels the element can move down
|
|
* @param {int} iTickSize optional parameter for specifying that the
|
|
* element should move iTickSize pixels at a time.
|
|
*/
|
|
setYConstraint: function(iUp, iDown, iTickSize) {
|
|
this.topConstraint = iUp;
|
|
this.bottomConstraint = iDown;
|
|
|
|
this.minY = this.initPageY - iUp;
|
|
this.maxY = this.initPageY + iDown;
|
|
if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
|
|
|
|
this.constrainY = true;
|
|
|
|
},
|
|
|
|
/**
|
|
* resetConstraints must be called if you manually reposition a dd element.
|
|
* @method resetConstraints
|
|
* @param {boolean} maintainOffset
|
|
*/
|
|
resetConstraints: function() {
|
|
// Maintain offsets if necessary
|
|
if (this.initPageX || this.initPageX === 0) {
|
|
// figure out how much this thing has moved
|
|
var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
|
|
var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
|
|
|
|
this.setInitPosition(dx, dy);
|
|
|
|
// This is the first time we have detected the element's position
|
|
} else {
|
|
this.setInitPosition();
|
|
}
|
|
|
|
if (this.constrainX) {
|
|
this.setXConstraint( this.leftConstraint,
|
|
this.rightConstraint,
|
|
this.xTickSize );
|
|
}
|
|
|
|
if (this.constrainY) {
|
|
this.setYConstraint( this.topConstraint,
|
|
this.bottomConstraint,
|
|
this.yTickSize );
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Normally the drag element is moved pixel by pixel, but we can specify
|
|
* that it move a number of pixels at a time. This method resolves the
|
|
* location when we have it set up like this.
|
|
* @method getTick
|
|
* @param {int} val where we want to place the object
|
|
* @param {int[]} tickArray sorted array of valid points
|
|
* @return {int} the closest tick
|
|
* @private
|
|
*/
|
|
getTick: function(val, tickArray) {
|
|
if (!tickArray) {
|
|
// If tick interval is not defined, it is effectively 1 pixel,
|
|
// so we return the value passed to us.
|
|
return val;
|
|
} else if (tickArray[0] >= val) {
|
|
// The value is lower than the first tick, so we return the first
|
|
// tick.
|
|
return tickArray[0];
|
|
} else {
|
|
for (var i=0, len=tickArray.length; i<len; ++i) {
|
|
var next = i + 1;
|
|
if (tickArray[next] && tickArray[next] >= val) {
|
|
var diff1 = val - tickArray[i];
|
|
var diff2 = tickArray[next] - val;
|
|
return (diff2 > diff1) ? tickArray[i] : tickArray[next];
|
|
}
|
|
}
|
|
|
|
// The value is larger than the last tick, so we return the last
|
|
// tick.
|
|
return tickArray[tickArray.length - 1];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* toString method
|
|
* @method toString
|
|
* @return {string} string representation of the dd obj
|
|
*/
|
|
toString: function() {
|
|
return ("DragDrop " + this.id);
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
/*!
|
|
* The drag and drop utility provides a framework for building drag and drop
|
|
* applications. In addition to enabling drag and drop for specific elements,
|
|
* the drag and drop elements are tracked by the manager class, and the
|
|
* interactions between the various elements are tracked during the drag and
|
|
* the implementing code is notified about these important moments.
|
|
*/
|
|
|
|
// Only load the library once. Rewriting the manager class would orphan
|
|
// existing drag and drop instances.
|
|
if (!Ext.dd.DragDropMgr) {
|
|
|
|
/**
|
|
* @class Ext.dd.DragDropMgr
|
|
* DragDropMgr is a singleton that tracks the element interaction for
|
|
* all DragDrop items in the window. Generally, you will not call
|
|
* this class directly, but it does have helper methods that could
|
|
* be useful in your DragDrop implementations.
|
|
* @singleton
|
|
*/
|
|
Ext.dd.DragDropMgr = function() {
|
|
|
|
var Event = Ext.EventManager;
|
|
|
|
return {
|
|
|
|
/**
|
|
* Two dimensional Array of registered DragDrop objects. The first
|
|
* dimension is the DragDrop item group, the second the DragDrop
|
|
* object.
|
|
* @property ids
|
|
* @type String[]
|
|
* @private
|
|
* @static
|
|
*/
|
|
ids: {},
|
|
|
|
/**
|
|
* Array of element ids defined as drag handles. Used to determine
|
|
* if the element that generated the mousedown event is actually the
|
|
* handle and not the html element itself.
|
|
* @property handleIds
|
|
* @type String[]
|
|
* @private
|
|
* @static
|
|
*/
|
|
handleIds: {},
|
|
|
|
/**
|
|
* the DragDrop object that is currently being dragged
|
|
* @property dragCurrent
|
|
* @type DragDrop
|
|
* @private
|
|
* @static
|
|
**/
|
|
dragCurrent: null,
|
|
|
|
/**
|
|
* the DragDrop object(s) that are being hovered over
|
|
* @property dragOvers
|
|
* @type Array
|
|
* @private
|
|
* @static
|
|
*/
|
|
dragOvers: {},
|
|
|
|
/**
|
|
* the X distance between the cursor and the object being dragged
|
|
* @property deltaX
|
|
* @type int
|
|
* @private
|
|
* @static
|
|
*/
|
|
deltaX: 0,
|
|
|
|
/**
|
|
* the Y distance between the cursor and the object being dragged
|
|
* @property deltaY
|
|
* @type int
|
|
* @private
|
|
* @static
|
|
*/
|
|
deltaY: 0,
|
|
|
|
/**
|
|
* Flag to determine if we should prevent the default behavior of the
|
|
* events we define. By default this is true, but this can be set to
|
|
* false if you need the default behavior (not recommended)
|
|
* @property preventDefault
|
|
* @type boolean
|
|
* @static
|
|
*/
|
|
preventDefault: true,
|
|
|
|
/**
|
|
* Flag to determine if we should stop the propagation of the events
|
|
* we generate. This is true by default but you may want to set it to
|
|
* false if the html element contains other features that require the
|
|
* mouse click.
|
|
* @property stopPropagation
|
|
* @type boolean
|
|
* @static
|
|
*/
|
|
stopPropagation: true,
|
|
|
|
/**
|
|
* Internal flag that is set to true when drag and drop has been
|
|
* intialized
|
|
* @property initialized
|
|
* @private
|
|
* @static
|
|
*/
|
|
initialized: false,
|
|
|
|
/**
|
|
* All drag and drop can be disabled.
|
|
* @property locked
|
|
* @private
|
|
* @static
|
|
*/
|
|
locked: false,
|
|
|
|
/**
|
|
* Called the first time an element is registered.
|
|
* @method init
|
|
* @private
|
|
* @static
|
|
*/
|
|
init: function() {
|
|
this.initialized = true;
|
|
},
|
|
|
|
/**
|
|
* In point mode, drag and drop interaction is defined by the
|
|
* location of the cursor during the drag/drop
|
|
* @property POINT
|
|
* @type int
|
|
* @static
|
|
*/
|
|
POINT: 0,
|
|
|
|
/**
|
|
* In intersect mode, drag and drop interaction is defined by the
|
|
* overlap of two or more drag and drop objects.
|
|
* @property INTERSECT
|
|
* @type int
|
|
* @static
|
|
*/
|
|
INTERSECT: 1,
|
|
|
|
/**
|
|
* The current drag and drop mode. Default: POINT
|
|
* @property mode
|
|
* @type int
|
|
* @static
|
|
*/
|
|
mode: 0,
|
|
|
|
/**
|
|
* Runs method on all drag and drop objects
|
|
* @method _execOnAll
|
|
* @private
|
|
* @static
|
|
*/
|
|
_execOnAll: function(sMethod, args) {
|
|
for (var i in this.ids) {
|
|
for (var j in this.ids[i]) {
|
|
var oDD = this.ids[i][j];
|
|
if (! this.isTypeOfDD(oDD)) {
|
|
continue;
|
|
}
|
|
oDD[sMethod].apply(oDD, args);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Drag and drop initialization. Sets up the global event handlers
|
|
* @method _onLoad
|
|
* @private
|
|
* @static
|
|
*/
|
|
_onLoad: function() {
|
|
|
|
this.init();
|
|
|
|
|
|
Event.on(document, "mouseup", this.handleMouseUp, this, true);
|
|
Event.on(document, "mousemove", this.handleMouseMove, this, true);
|
|
Event.on(window, "unload", this._onUnload, this, true);
|
|
Event.on(window, "resize", this._onResize, this, true);
|
|
// Event.on(window, "mouseout", this._test);
|
|
|
|
},
|
|
|
|
/**
|
|
* Reset constraints on all drag and drop objs
|
|
* @method _onResize
|
|
* @private
|
|
* @static
|
|
*/
|
|
_onResize: function(e) {
|
|
this._execOnAll("resetConstraints", []);
|
|
},
|
|
|
|
/**
|
|
* Lock all drag and drop functionality
|
|
* @method lock
|
|
* @static
|
|
*/
|
|
lock: function() { this.locked = true; },
|
|
|
|
/**
|
|
* Unlock all drag and drop functionality
|
|
* @method unlock
|
|
* @static
|
|
*/
|
|
unlock: function() { this.locked = false; },
|
|
|
|
/**
|
|
* Is drag and drop locked?
|
|
* @method isLocked
|
|
* @return {boolean} True if drag and drop is locked, false otherwise.
|
|
* @static
|
|
*/
|
|
isLocked: function() { return this.locked; },
|
|
|
|
/**
|
|
* Location cache that is set for all drag drop objects when a drag is
|
|
* initiated, cleared when the drag is finished.
|
|
* @property locationCache
|
|
* @private
|
|
* @static
|
|
*/
|
|
locationCache: {},
|
|
|
|
/**
|
|
* Set useCache to false if you want to force object the lookup of each
|
|
* drag and drop linked element constantly during a drag.
|
|
* @property useCache
|
|
* @type boolean
|
|
* @static
|
|
*/
|
|
useCache: true,
|
|
|
|
/**
|
|
* The number of pixels that the mouse needs to move after the
|
|
* mousedown before the drag is initiated. Default=3;
|
|
* @property clickPixelThresh
|
|
* @type int
|
|
* @static
|
|
*/
|
|
clickPixelThresh: 3,
|
|
|
|
/**
|
|
* The number of milliseconds after the mousedown event to initiate the
|
|
* drag if we don't get a mouseup event. Default=350
|
|
* @property clickTimeThresh
|
|
* @type int
|
|
* @static
|
|
*/
|
|
clickTimeThresh: 350,
|
|
|
|
/**
|
|
* Flag that indicates that either the drag pixel threshold or the
|
|
* mousdown time threshold has been met
|
|
* @property dragThreshMet
|
|
* @type boolean
|
|
* @private
|
|
* @static
|
|
*/
|
|
dragThreshMet: false,
|
|
|
|
/**
|
|
* Timeout used for the click time threshold
|
|
* @property clickTimeout
|
|
* @type Object
|
|
* @private
|
|
* @static
|
|
*/
|
|
clickTimeout: null,
|
|
|
|
/**
|
|
* The X position of the mousedown event stored for later use when a
|
|
* drag threshold is met.
|
|
* @property startX
|
|
* @type int
|
|
* @private
|
|
* @static
|
|
*/
|
|
startX: 0,
|
|
|
|
/**
|
|
* The Y position of the mousedown event stored for later use when a
|
|
* drag threshold is met.
|
|
* @property startY
|
|
* @type int
|
|
* @private
|
|
* @static
|
|
*/
|
|
startY: 0,
|
|
|
|
/**
|
|
* Each DragDrop instance must be registered with the DragDropMgr.
|
|
* This is executed in DragDrop.init()
|
|
* @method regDragDrop
|
|
* @param {DragDrop} oDD the DragDrop object to register
|
|
* @param {String} sGroup the name of the group this element belongs to
|
|
* @static
|
|
*/
|
|
regDragDrop: function(oDD, sGroup) {
|
|
if (!this.initialized) { this.init(); }
|
|
|
|
if (!this.ids[sGroup]) {
|
|
this.ids[sGroup] = {};
|
|
}
|
|
this.ids[sGroup][oDD.id] = oDD;
|
|
},
|
|
|
|
/**
|
|
* Removes the supplied dd instance from the supplied group. Executed
|
|
* by DragDrop.removeFromGroup, so don't call this function directly.
|
|
* @method removeDDFromGroup
|
|
* @private
|
|
* @static
|
|
*/
|
|
removeDDFromGroup: function(oDD, sGroup) {
|
|
if (!this.ids[sGroup]) {
|
|
this.ids[sGroup] = {};
|
|
}
|
|
|
|
var obj = this.ids[sGroup];
|
|
if (obj && obj[oDD.id]) {
|
|
delete obj[oDD.id];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Unregisters a drag and drop item. This is executed in
|
|
* DragDrop.unreg, use that method instead of calling this directly.
|
|
* @method _remove
|
|
* @private
|
|
* @static
|
|
*/
|
|
_remove: function(oDD) {
|
|
for (var g in oDD.groups) {
|
|
if (g && this.ids[g] && this.ids[g][oDD.id]) {
|
|
delete this.ids[g][oDD.id];
|
|
}
|
|
}
|
|
delete this.handleIds[oDD.id];
|
|
},
|
|
|
|
/**
|
|
* Each DragDrop handle element must be registered. This is done
|
|
* automatically when executing DragDrop.setHandleElId()
|
|
* @method regHandle
|
|
* @param {String} sDDId the DragDrop id this element is a handle for
|
|
* @param {String} sHandleId the id of the element that is the drag
|
|
* handle
|
|
* @static
|
|
*/
|
|
regHandle: function(sDDId, sHandleId) {
|
|
if (!this.handleIds[sDDId]) {
|
|
this.handleIds[sDDId] = {};
|
|
}
|
|
this.handleIds[sDDId][sHandleId] = sHandleId;
|
|
},
|
|
|
|
/**
|
|
* Utility function to determine if a given element has been
|
|
* registered as a drag drop item.
|
|
* @method isDragDrop
|
|
* @param {String} id the element id to check
|
|
* @return {boolean} true if this element is a DragDrop item,
|
|
* false otherwise
|
|
* @static
|
|
*/
|
|
isDragDrop: function(id) {
|
|
return ( this.getDDById(id) ) ? true : false;
|
|
},
|
|
|
|
/**
|
|
* Returns the drag and drop instances that are in all groups the
|
|
* passed in instance belongs to.
|
|
* @method getRelated
|
|
* @param {DragDrop} p_oDD the obj to get related data for
|
|
* @param {boolean} bTargetsOnly if true, only return targetable objs
|
|
* @return {DragDrop[]} the related instances
|
|
* @static
|
|
*/
|
|
getRelated: function(p_oDD, bTargetsOnly) {
|
|
var oDDs = [];
|
|
for (var i in p_oDD.groups) {
|
|
for (var j in this.ids[i]) {
|
|
var dd = this.ids[i][j];
|
|
if (! this.isTypeOfDD(dd)) {
|
|
continue;
|
|
}
|
|
if (!bTargetsOnly || dd.isTarget) {
|
|
oDDs[oDDs.length] = dd;
|
|
}
|
|
}
|
|
}
|
|
|
|
return oDDs;
|
|
},
|
|
|
|
/**
|
|
* Returns true if the specified dd target is a legal target for
|
|
* the specifice drag obj
|
|
* @method isLegalTarget
|
|
* @param {DragDrop} oDD the drag obj
|
|
* @param {DragDrop} oTargetDD the target
|
|
* @return {boolean} true if the target is a legal target for the
|
|
* dd obj
|
|
* @static
|
|
*/
|
|
isLegalTarget: function (oDD, oTargetDD) {
|
|
var targets = this.getRelated(oDD, true);
|
|
for (var i=0, len=targets.length;i<len;++i) {
|
|
if (targets[i].id == oTargetDD.id) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* My goal is to be able to transparently determine if an object is
|
|
* typeof DragDrop, and the exact subclass of DragDrop. typeof
|
|
* returns "object", oDD.constructor.toString() always returns
|
|
* "DragDrop" and not the name of the subclass. So for now it just
|
|
* evaluates a well-known variable in DragDrop.
|
|
* @method isTypeOfDD
|
|
* @param {Object} the object to evaluate
|
|
* @return {boolean} true if typeof oDD = DragDrop
|
|
* @static
|
|
*/
|
|
isTypeOfDD: function (oDD) {
|
|
return (oDD && oDD.__ygDragDrop);
|
|
},
|
|
|
|
/**
|
|
* Utility function to determine if a given element has been
|
|
* registered as a drag drop handle for the given Drag Drop object.
|
|
* @method isHandle
|
|
* @param {String} id the element id to check
|
|
* @return {boolean} true if this element is a DragDrop handle, false
|
|
* otherwise
|
|
* @static
|
|
*/
|
|
isHandle: function(sDDId, sHandleId) {
|
|
return ( this.handleIds[sDDId] &&
|
|
this.handleIds[sDDId][sHandleId] );
|
|
},
|
|
|
|
/**
|
|
* Returns the DragDrop instance for a given id
|
|
* @method getDDById
|
|
* @param {String} id the id of the DragDrop object
|
|
* @return {DragDrop} the drag drop object, null if it is not found
|
|
* @static
|
|
*/
|
|
getDDById: function(id) {
|
|
for (var i in this.ids) {
|
|
if (this.ids[i][id]) {
|
|
return this.ids[i][id];
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
|
|
/**
|
|
* Fired after a registered DragDrop object gets the mousedown event.
|
|
* Sets up the events required to track the object being dragged
|
|
* @method handleMouseDown
|
|
* @param {Event} e the event
|
|
* @param oDD the DragDrop object being dragged
|
|
* @private
|
|
* @static
|
|
*/
|
|
handleMouseDown: function(e, oDD) {
|
|
if(Ext.QuickTips){
|
|
Ext.QuickTips.disable();
|
|
}
|
|
if(this.dragCurrent){
|
|
// the original browser mouseup wasn't handled (e.g. outside FF browser window)
|
|
// so clean up first to avoid breaking the next drag
|
|
this.handleMouseUp(e);
|
|
}
|
|
|
|
this.currentTarget = e.getTarget();
|
|
this.dragCurrent = oDD;
|
|
|
|
var el = oDD.getEl();
|
|
|
|
// track start position
|
|
this.startX = e.getPageX();
|
|
this.startY = e.getPageY();
|
|
|
|
this.deltaX = this.startX - el.offsetLeft;
|
|
this.deltaY = this.startY - el.offsetTop;
|
|
|
|
this.dragThreshMet = false;
|
|
|
|
this.clickTimeout = setTimeout(
|
|
function() {
|
|
var DDM = Ext.dd.DDM;
|
|
DDM.startDrag(DDM.startX, DDM.startY);
|
|
},
|
|
this.clickTimeThresh );
|
|
},
|
|
|
|
/**
|
|
* Fired when either the drag pixel threshol or the mousedown hold
|
|
* time threshold has been met.
|
|
* @method startDrag
|
|
* @param x {int} the X position of the original mousedown
|
|
* @param y {int} the Y position of the original mousedown
|
|
* @static
|
|
*/
|
|
startDrag: function(x, y) {
|
|
clearTimeout(this.clickTimeout);
|
|
if (this.dragCurrent) {
|
|
this.dragCurrent.b4StartDrag(x, y);
|
|
this.dragCurrent.startDrag(x, y);
|
|
}
|
|
this.dragThreshMet = true;
|
|
},
|
|
|
|
/**
|
|
* Internal function to handle the mouseup event. Will be invoked
|
|
* from the context of the document.
|
|
* @method handleMouseUp
|
|
* @param {Event} e the event
|
|
* @private
|
|
* @static
|
|
*/
|
|
handleMouseUp: function(e) {
|
|
|
|
if(Ext.QuickTips){
|
|
Ext.QuickTips.enable();
|
|
}
|
|
if (! this.dragCurrent) {
|
|
return;
|
|
}
|
|
|
|
clearTimeout(this.clickTimeout);
|
|
|
|
if (this.dragThreshMet) {
|
|
this.fireEvents(e, true);
|
|
} else {
|
|
}
|
|
|
|
this.stopDrag(e);
|
|
|
|
this.stopEvent(e);
|
|
},
|
|
|
|
/**
|
|
* Utility to stop event propagation and event default, if these
|
|
* features are turned on.
|
|
* @method stopEvent
|
|
* @param {Event} e the event as returned by this.getEvent()
|
|
* @static
|
|
*/
|
|
stopEvent: function(e){
|
|
if(this.stopPropagation) {
|
|
e.stopPropagation();
|
|
}
|
|
|
|
if (this.preventDefault) {
|
|
e.preventDefault();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Internal function to clean up event handlers after the drag
|
|
* operation is complete
|
|
* @method stopDrag
|
|
* @param {Event} e the event
|
|
* @private
|
|
* @static
|
|
*/
|
|
stopDrag: function(e) {
|
|
// Fire the drag end event for the item that was dragged
|
|
if (this.dragCurrent) {
|
|
if (this.dragThreshMet) {
|
|
this.dragCurrent.b4EndDrag(e);
|
|
this.dragCurrent.endDrag(e);
|
|
}
|
|
|
|
this.dragCurrent.onMouseUp(e);
|
|
}
|
|
|
|
this.dragCurrent = null;
|
|
this.dragOvers = {};
|
|
},
|
|
|
|
/**
|
|
* Internal function to handle the mousemove event. Will be invoked
|
|
* from the context of the html element.
|
|
*
|
|
* @TODO figure out what we can do about mouse events lost when the
|
|
* user drags objects beyond the window boundary. Currently we can
|
|
* detect this in internet explorer by verifying that the mouse is
|
|
* down during the mousemove event. Firefox doesn't give us the
|
|
* button state on the mousemove event.
|
|
* @method handleMouseMove
|
|
* @param {Event} e the event
|
|
* @private
|
|
* @static
|
|
*/
|
|
handleMouseMove: function(e) {
|
|
if (! this.dragCurrent) {
|
|
return true;
|
|
}
|
|
// var button = e.which || e.button;
|
|
|
|
// check for IE mouseup outside of page boundary
|
|
if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
|
|
this.stopEvent(e);
|
|
return this.handleMouseUp(e);
|
|
}
|
|
|
|
if (!this.dragThreshMet) {
|
|
var diffX = Math.abs(this.startX - e.getPageX());
|
|
var diffY = Math.abs(this.startY - e.getPageY());
|
|
if (diffX > this.clickPixelThresh ||
|
|
diffY > this.clickPixelThresh) {
|
|
this.startDrag(this.startX, this.startY);
|
|
}
|
|
}
|
|
|
|
if (this.dragThreshMet) {
|
|
this.dragCurrent.b4Drag(e);
|
|
this.dragCurrent.onDrag(e);
|
|
if(!this.dragCurrent.moveOnly){
|
|
this.fireEvents(e, false);
|
|
}
|
|
}
|
|
|
|
this.stopEvent(e);
|
|
|
|
return true;
|
|
},
|
|
|
|
/**
|
|
* Iterates over all of the DragDrop elements to find ones we are
|
|
* hovering over or dropping on
|
|
* @method fireEvents
|
|
* @param {Event} e the event
|
|
* @param {boolean} isDrop is this a drop op or a mouseover op?
|
|
* @private
|
|
* @static
|
|
*/
|
|
fireEvents: function(e, isDrop) {
|
|
var dc = this.dragCurrent;
|
|
|
|
// If the user did the mouse up outside of the window, we could
|
|
// get here even though we have ended the drag.
|
|
if (!dc || dc.isLocked()) {
|
|
return;
|
|
}
|
|
|
|
var pt = e.getPoint();
|
|
|
|
// cache the previous dragOver array
|
|
var oldOvers = [];
|
|
|
|
var outEvts = [];
|
|
var overEvts = [];
|
|
var dropEvts = [];
|
|
var enterEvts = [];
|
|
|
|
// Check to see if the object(s) we were hovering over is no longer
|
|
// being hovered over so we can fire the onDragOut event
|
|
for (var i in this.dragOvers) {
|
|
|
|
var ddo = this.dragOvers[i];
|
|
|
|
if (! this.isTypeOfDD(ddo)) {
|
|
continue;
|
|
}
|
|
|
|
if (! this.isOverTarget(pt, ddo, this.mode)) {
|
|
outEvts.push( ddo );
|
|
}
|
|
|
|
oldOvers[i] = true;
|
|
delete this.dragOvers[i];
|
|
}
|
|
|
|
for (var sGroup in dc.groups) {
|
|
|
|
if ("string" != typeof sGroup) {
|
|
continue;
|
|
}
|
|
|
|
for (i in this.ids[sGroup]) {
|
|
var oDD = this.ids[sGroup][i];
|
|
if (! this.isTypeOfDD(oDD)) {
|
|
continue;
|
|
}
|
|
|
|
if (oDD.isTarget && !oDD.isLocked() && ((oDD != dc) || (dc.ignoreSelf === false))) {
|
|
if (this.isOverTarget(pt, oDD, this.mode)) {
|
|
// look for drop interactions
|
|
if (isDrop) {
|
|
dropEvts.push( oDD );
|
|
// look for drag enter and drag over interactions
|
|
} else {
|
|
|
|
// initial drag over: dragEnter fires
|
|
if (!oldOvers[oDD.id]) {
|
|
enterEvts.push( oDD );
|
|
// subsequent drag overs: dragOver fires
|
|
} else {
|
|
overEvts.push( oDD );
|
|
}
|
|
|
|
this.dragOvers[oDD.id] = oDD;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (this.mode) {
|
|
if (outEvts.length) {
|
|
dc.b4DragOut(e, outEvts);
|
|
dc.onDragOut(e, outEvts);
|
|
}
|
|
|
|
if (enterEvts.length) {
|
|
dc.onDragEnter(e, enterEvts);
|
|
}
|
|
|
|
if (overEvts.length) {
|
|
dc.b4DragOver(e, overEvts);
|
|
dc.onDragOver(e, overEvts);
|
|
}
|
|
|
|
if (dropEvts.length) {
|
|
dc.b4DragDrop(e, dropEvts);
|
|
dc.onDragDrop(e, dropEvts);
|
|
}
|
|
|
|
} else {
|
|
// fire dragout events
|
|
var len = 0;
|
|
for (i=0, len=outEvts.length; i<len; ++i) {
|
|
dc.b4DragOut(e, outEvts[i].id);
|
|
dc.onDragOut(e, outEvts[i].id);
|
|
}
|
|
|
|
// fire enter events
|
|
for (i=0,len=enterEvts.length; i<len; ++i) {
|
|
// dc.b4DragEnter(e, oDD.id);
|
|
dc.onDragEnter(e, enterEvts[i].id);
|
|
}
|
|
|
|
// fire over events
|
|
for (i=0,len=overEvts.length; i<len; ++i) {
|
|
dc.b4DragOver(e, overEvts[i].id);
|
|
dc.onDragOver(e, overEvts[i].id);
|
|
}
|
|
|
|
// fire drop events
|
|
for (i=0, len=dropEvts.length; i<len; ++i) {
|
|
dc.b4DragDrop(e, dropEvts[i].id);
|
|
dc.onDragDrop(e, dropEvts[i].id);
|
|
}
|
|
|
|
}
|
|
|
|
// notify about a drop that did not find a target
|
|
if (isDrop && !dropEvts.length) {
|
|
dc.onInvalidDrop(e);
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* Helper function for getting the best match from the list of drag
|
|
* and drop objects returned by the drag and drop events when we are
|
|
* in INTERSECT mode. It returns either the first object that the
|
|
* cursor is over, or the object that has the greatest overlap with
|
|
* the dragged element.
|
|
* @method getBestMatch
|
|
* @param {DragDrop[]} dds The array of drag and drop objects
|
|
* targeted
|
|
* @return {DragDrop} The best single match
|
|
* @static
|
|
*/
|
|
getBestMatch: function(dds) {
|
|
var winner = null;
|
|
// Return null if the input is not what we expect
|
|
//if (!dds || !dds.length || dds.length == 0) {
|
|
// winner = null;
|
|
// If there is only one item, it wins
|
|
//} else if (dds.length == 1) {
|
|
|
|
var len = dds.length;
|
|
|
|
if (len == 1) {
|
|
winner = dds[0];
|
|
} else {
|
|
// Loop through the targeted items
|
|
for (var i=0; i<len; ++i) {
|
|
var dd = dds[i];
|
|
// If the cursor is over the object, it wins. If the
|
|
// cursor is over multiple matches, the first one we come
|
|
// to wins.
|
|
if (dd.cursorIsOver) {
|
|
winner = dd;
|
|
break;
|
|
// Otherwise the object with the most overlap wins
|
|
} else {
|
|
if (!winner ||
|
|
winner.overlap.getArea() < dd.overlap.getArea()) {
|
|
winner = dd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return winner;
|
|
},
|
|
|
|
/**
|
|
* Refreshes the cache of the top-left and bottom-right points of the
|
|
* drag and drop objects in the specified group(s). This is in the
|
|
* format that is stored in the drag and drop instance, so typical
|
|
* usage is:
|
|
* <code>
|
|
* Ext.dd.DragDropMgr.refreshCache(ddinstance.groups);
|
|
* </code>
|
|
* Alternatively:
|
|
* <code>
|
|
* Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true});
|
|
* </code>
|
|
* @TODO this really should be an indexed array. Alternatively this
|
|
* method could accept both.
|
|
* @method refreshCache
|
|
* @param {Object} groups an associative array of groups to refresh
|
|
* @static
|
|
*/
|
|
refreshCache: function(groups) {
|
|
for (var sGroup in groups) {
|
|
if ("string" != typeof sGroup) {
|
|
continue;
|
|
}
|
|
for (var i in this.ids[sGroup]) {
|
|
var oDD = this.ids[sGroup][i];
|
|
|
|
if (this.isTypeOfDD(oDD)) {
|
|
// if (this.isTypeOfDD(oDD) && oDD.isTarget) {
|
|
var loc = this.getLocation(oDD);
|
|
if (loc) {
|
|
this.locationCache[oDD.id] = loc;
|
|
} else {
|
|
delete this.locationCache[oDD.id];
|
|
// this will unregister the drag and drop object if
|
|
// the element is not in a usable state
|
|
// oDD.unreg();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* This checks to make sure an element exists and is in the DOM. The
|
|
* main purpose is to handle cases where innerHTML is used to remove
|
|
* drag and drop objects from the DOM. IE provides an 'unspecified
|
|
* error' when trying to access the offsetParent of such an element
|
|
* @method verifyEl
|
|
* @param {HTMLElement} el the element to check
|
|
* @return {boolean} true if the element looks usable
|
|
* @static
|
|
*/
|
|
verifyEl: function(el) {
|
|
if (el) {
|
|
var parent;
|
|
if(Ext.isIE){
|
|
try{
|
|
parent = el.offsetParent;
|
|
}catch(e){}
|
|
}else{
|
|
parent = el.offsetParent;
|
|
}
|
|
if (parent) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* Returns a Region object containing the drag and drop element's position
|
|
* and size, including the padding configured for it
|
|
* @method getLocation
|
|
* @param {DragDrop} oDD the drag and drop object to get the
|
|
* location for
|
|
* @return {Ext.lib.Region} a Region object representing the total area
|
|
* the element occupies, including any padding
|
|
* the instance is configured for.
|
|
* @static
|
|
*/
|
|
getLocation: function(oDD) {
|
|
if (! this.isTypeOfDD(oDD)) {
|
|
return null;
|
|
}
|
|
|
|
var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
|
|
|
|
try {
|
|
pos= Ext.lib.Dom.getXY(el);
|
|
} catch (e) { }
|
|
|
|
if (!pos) {
|
|
return null;
|
|
}
|
|
|
|
x1 = pos[0];
|
|
x2 = x1 + el.offsetWidth;
|
|
y1 = pos[1];
|
|
y2 = y1 + el.offsetHeight;
|
|
|
|
t = y1 - oDD.padding[0];
|
|
r = x2 + oDD.padding[1];
|
|
b = y2 + oDD.padding[2];
|
|
l = x1 - oDD.padding[3];
|
|
|
|
return new Ext.lib.Region( t, r, b, l );
|
|
},
|
|
|
|
/**
|
|
* Checks the cursor location to see if it over the target
|
|
* @method isOverTarget
|
|
* @param {Ext.lib.Point} pt The point to evaluate
|
|
* @param {DragDrop} oTarget the DragDrop object we are inspecting
|
|
* @return {boolean} true if the mouse is over the target
|
|
* @private
|
|
* @static
|
|
*/
|
|
isOverTarget: function(pt, oTarget, intersect) {
|
|
// use cache if available
|
|
var loc = this.locationCache[oTarget.id];
|
|
if (!loc || !this.useCache) {
|
|
loc = this.getLocation(oTarget);
|
|
this.locationCache[oTarget.id] = loc;
|
|
|
|
}
|
|
|
|
if (!loc) {
|
|
return false;
|
|
}
|
|
|
|
oTarget.cursorIsOver = loc.contains( pt );
|
|
|
|
// DragDrop is using this as a sanity check for the initial mousedown
|
|
// in this case we are done. In POINT mode, if the drag obj has no
|
|
// contraints, we are also done. Otherwise we need to evaluate the
|
|
// location of the target as related to the actual location of the
|
|
// dragged element.
|
|
var dc = this.dragCurrent;
|
|
if (!dc || !dc.getTargetCoord ||
|
|
(!intersect && !dc.constrainX && !dc.constrainY)) {
|
|
return oTarget.cursorIsOver;
|
|
}
|
|
|
|
oTarget.overlap = null;
|
|
|
|
// Get the current location of the drag element, this is the
|
|
// location of the mouse event less the delta that represents
|
|
// where the original mousedown happened on the element. We
|
|
// need to consider constraints and ticks as well.
|
|
var pos = dc.getTargetCoord(pt.x, pt.y);
|
|
|
|
var el = dc.getDragEl();
|
|
var curRegion = new Ext.lib.Region( pos.y,
|
|
pos.x + el.offsetWidth,
|
|
pos.y + el.offsetHeight,
|
|
pos.x );
|
|
|
|
var overlap = curRegion.intersect(loc);
|
|
|
|
if (overlap) {
|
|
oTarget.overlap = overlap;
|
|
return (intersect) ? true : oTarget.cursorIsOver;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* unload event handler
|
|
* @method _onUnload
|
|
* @private
|
|
* @static
|
|
*/
|
|
_onUnload: function(e, me) {
|
|
Ext.dd.DragDropMgr.unregAll();
|
|
},
|
|
|
|
/**
|
|
* Cleans up the drag and drop events and objects.
|
|
* @method unregAll
|
|
* @private
|
|
* @static
|
|
*/
|
|
unregAll: function() {
|
|
|
|
if (this.dragCurrent) {
|
|
this.stopDrag();
|
|
this.dragCurrent = null;
|
|
}
|
|
|
|
this._execOnAll("unreg", []);
|
|
|
|
for (var i in this.elementCache) {
|
|
delete this.elementCache[i];
|
|
}
|
|
|
|
this.elementCache = {};
|
|
this.ids = {};
|
|
},
|
|
|
|
/**
|
|
* A cache of DOM elements
|
|
* @property elementCache
|
|
* @private
|
|
* @static
|
|
*/
|
|
elementCache: {},
|
|
|
|
/**
|
|
* Get the wrapper for the DOM element specified
|
|
* @method getElWrapper
|
|
* @param {String} id the id of the element to get
|
|
* @return {Ext.dd.DDM.ElementWrapper} the wrapped element
|
|
* @private
|
|
* @deprecated This wrapper isn't that useful
|
|
* @static
|
|
*/
|
|
getElWrapper: function(id) {
|
|
var oWrapper = this.elementCache[id];
|
|
if (!oWrapper || !oWrapper.el) {
|
|
oWrapper = this.elementCache[id] =
|
|
new this.ElementWrapper(Ext.getDom(id));
|
|
}
|
|
return oWrapper;
|
|
},
|
|
|
|
/**
|
|
* Returns the actual DOM element
|
|
* @method getElement
|
|
* @param {String} id the id of the elment to get
|
|
* @return {Object} The element
|
|
* @deprecated use Ext.lib.Ext.getDom instead
|
|
* @static
|
|
*/
|
|
getElement: function(id) {
|
|
return Ext.getDom(id);
|
|
},
|
|
|
|
/**
|
|
* Returns the style property for the DOM element (i.e.,
|
|
* document.getElById(id).style)
|
|
* @method getCss
|
|
* @param {String} id the id of the elment to get
|
|
* @return {Object} The style property of the element
|
|
* @deprecated use Ext.lib.Dom instead
|
|
* @static
|
|
*/
|
|
getCss: function(id) {
|
|
var el = Ext.getDom(id);
|
|
return (el) ? el.style : null;
|
|
},
|
|
|
|
/**
|
|
* Inner class for cached elements
|
|
* @class Ext.dd.DragDropMgr.ElementWrapper
|
|
* @for DragDropMgr
|
|
* @private
|
|
* @deprecated
|
|
*/
|
|
ElementWrapper: function(el) {
|
|
/**
|
|
* The element
|
|
* @property el
|
|
*/
|
|
this.el = el || null;
|
|
/**
|
|
* The element id
|
|
* @property id
|
|
*/
|
|
this.id = this.el && el.id;
|
|
/**
|
|
* A reference to the style property
|
|
* @property css
|
|
*/
|
|
this.css = this.el && el.style;
|
|
},
|
|
|
|
/**
|
|
* Returns the X position of an html element
|
|
* @method getPosX
|
|
* @param el the element for which to get the position
|
|
* @return {int} the X coordinate
|
|
* @for DragDropMgr
|
|
* @deprecated use Ext.lib.Dom.getX instead
|
|
* @static
|
|
*/
|
|
getPosX: function(el) {
|
|
return Ext.lib.Dom.getX(el);
|
|
},
|
|
|
|
/**
|
|
* Returns the Y position of an html element
|
|
* @method getPosY
|
|
* @param el the element for which to get the position
|
|
* @return {int} the Y coordinate
|
|
* @deprecated use Ext.lib.Dom.getY instead
|
|
* @static
|
|
*/
|
|
getPosY: function(el) {
|
|
return Ext.lib.Dom.getY(el);
|
|
},
|
|
|
|
/**
|
|
* Swap two nodes. In IE, we use the native method, for others we
|
|
* emulate the IE behavior
|
|
* @method swapNode
|
|
* @param n1 the first node to swap
|
|
* @param n2 the other node to swap
|
|
* @static
|
|
*/
|
|
swapNode: function(n1, n2) {
|
|
if (n1.swapNode) {
|
|
n1.swapNode(n2);
|
|
} else {
|
|
var p = n2.parentNode;
|
|
var s = n2.nextSibling;
|
|
|
|
if (s == n1) {
|
|
p.insertBefore(n1, n2);
|
|
} else if (n2 == n1.nextSibling) {
|
|
p.insertBefore(n2, n1);
|
|
} else {
|
|
n1.parentNode.replaceChild(n2, n1);
|
|
p.insertBefore(n1, s);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Returns the current scroll position
|
|
* @method getScroll
|
|
* @private
|
|
* @static
|
|
*/
|
|
getScroll: function () {
|
|
var t, l, dde=document.documentElement, db=document.body;
|
|
if (dde && (dde.scrollTop || dde.scrollLeft)) {
|
|
t = dde.scrollTop;
|
|
l = dde.scrollLeft;
|
|
} else if (db) {
|
|
t = db.scrollTop;
|
|
l = db.scrollLeft;
|
|
} else {
|
|
|
|
}
|
|
return { top: t, left: l };
|
|
},
|
|
|
|
/**
|
|
* Returns the specified element style property
|
|
* @method getStyle
|
|
* @param {HTMLElement} el the element
|
|
* @param {string} styleProp the style property
|
|
* @return {string} The value of the style property
|
|
* @deprecated use Ext.lib.Dom.getStyle
|
|
* @static
|
|
*/
|
|
getStyle: function(el, styleProp) {
|
|
return Ext.fly(el).getStyle(styleProp);
|
|
},
|
|
|
|
/**
|
|
* Gets the scrollTop
|
|
* @method getScrollTop
|
|
* @return {int} the document's scrollTop
|
|
* @static
|
|
*/
|
|
getScrollTop: function () {
|
|
return this.getScroll().top;
|
|
},
|
|
|
|
/**
|
|
* Gets the scrollLeft
|
|
* @method getScrollLeft
|
|
* @return {int} the document's scrollTop
|
|
* @static
|
|
*/
|
|
getScrollLeft: function () {
|
|
return this.getScroll().left;
|
|
},
|
|
|
|
/**
|
|
* Sets the x/y position of an element to the location of the
|
|
* target element.
|
|
* @method moveToEl
|
|
* @param {HTMLElement} moveEl The element to move
|
|
* @param {HTMLElement} targetEl The position reference element
|
|
* @static
|
|
*/
|
|
moveToEl: function (moveEl, targetEl) {
|
|
var aCoord = Ext.lib.Dom.getXY(targetEl);
|
|
Ext.lib.Dom.setXY(moveEl, aCoord);
|
|
},
|
|
|
|
/**
|
|
* Numeric array sort function
|
|
* @method numericSort
|
|
* @static
|
|
*/
|
|
numericSort: function(a, b) {
|
|
return (a - b);
|
|
},
|
|
|
|
/**
|
|
* Internal counter
|
|
* @property _timeoutCount
|
|
* @private
|
|
* @static
|
|
*/
|
|
_timeoutCount: 0,
|
|
|
|
/**
|
|
* Trying to make the load order less important. Without this we get
|
|
* an error if this file is loaded before the Event Utility.
|
|
* @method _addListeners
|
|
* @private
|
|
* @static
|
|
*/
|
|
_addListeners: function() {
|
|
var DDM = Ext.dd.DDM;
|
|
if ( Ext.lib.Event && document ) {
|
|
DDM._onLoad();
|
|
} else {
|
|
if (DDM._timeoutCount > 2000) {
|
|
} else {
|
|
setTimeout(DDM._addListeners, 10);
|
|
if (document && document.body) {
|
|
DDM._timeoutCount += 1;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Recursively searches the immediate parent and all child nodes for
|
|
* the handle element in order to determine wheter or not it was
|
|
* clicked.
|
|
* @method handleWasClicked
|
|
* @param node the html element to inspect
|
|
* @static
|
|
*/
|
|
handleWasClicked: function(node, id) {
|
|
if (this.isHandle(id, node.id)) {
|
|
return true;
|
|
} else {
|
|
// check to see if this is a text node child of the one we want
|
|
var p = node.parentNode;
|
|
|
|
while (p) {
|
|
if (this.isHandle(id, p.id)) {
|
|
return true;
|
|
} else {
|
|
p = p.parentNode;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
};
|
|
|
|
}();
|
|
|
|
// shorter alias, save a few bytes
|
|
Ext.dd.DDM = Ext.dd.DragDropMgr;
|
|
Ext.dd.DDM._addListeners();
|
|
|
|
}
|
|
|
|
/**
|
|
* @class Ext.dd.DD
|
|
* A DragDrop implementation where the linked element follows the
|
|
* mouse cursor during a drag.
|
|
* @extends Ext.dd.DragDrop
|
|
* @constructor
|
|
* @param {String} id the id of the linked element
|
|
* @param {String} sGroup the group of related DragDrop items
|
|
* @param {object} config an object containing configurable attributes
|
|
* Valid properties for DD:
|
|
* scroll
|
|
*/
|
|
Ext.dd.DD = function(id, sGroup, config) {
|
|
if (id) {
|
|
this.init(id, sGroup, config);
|
|
}
|
|
};
|
|
|
|
Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, {
|
|
|
|
/**
|
|
* When set to true, the utility automatically tries to scroll the browser
|
|
* window when a drag and drop element is dragged near the viewport boundary.
|
|
* Defaults to true.
|
|
* @property scroll
|
|
* @type boolean
|
|
*/
|
|
scroll: true,
|
|
|
|
/**
|
|
* Sets the pointer offset to the distance between the linked element's top
|
|
* left corner and the location the element was clicked
|
|
* @method autoOffset
|
|
* @param {int} iPageX the X coordinate of the click
|
|
* @param {int} iPageY the Y coordinate of the click
|
|
*/
|
|
autoOffset: function(iPageX, iPageY) {
|
|
var x = iPageX - this.startPageX;
|
|
var y = iPageY - this.startPageY;
|
|
this.setDelta(x, y);
|
|
},
|
|
|
|
/**
|
|
* Sets the pointer offset. You can call this directly to force the
|
|
* offset to be in a particular location (e.g., pass in 0,0 to set it
|
|
* to the center of the object)
|
|
* @method setDelta
|
|
* @param {int} iDeltaX the distance from the left
|
|
* @param {int} iDeltaY the distance from the top
|
|
*/
|
|
setDelta: function(iDeltaX, iDeltaY) {
|
|
this.deltaX = iDeltaX;
|
|
this.deltaY = iDeltaY;
|
|
},
|
|
|
|
/**
|
|
* Sets the drag element to the location of the mousedown or click event,
|
|
* maintaining the cursor location relative to the location on the element
|
|
* that was clicked. Override this if you want to place the element in a
|
|
* location other than where the cursor is.
|
|
* @method setDragElPos
|
|
* @param {int} iPageX the X coordinate of the mousedown or drag event
|
|
* @param {int} iPageY the Y coordinate of the mousedown or drag event
|
|
*/
|
|
setDragElPos: function(iPageX, iPageY) {
|
|
// the first time we do this, we are going to check to make sure
|
|
// the element has css positioning
|
|
|
|
var el = this.getDragEl();
|
|
this.alignElWithMouse(el, iPageX, iPageY);
|
|
},
|
|
|
|
/**
|
|
* Sets the element to the location of the mousedown or click event,
|
|
* maintaining the cursor location relative to the location on the element
|
|
* that was clicked. Override this if you want to place the element in a
|
|
* location other than where the cursor is.
|
|
* @method alignElWithMouse
|
|
* @param {HTMLElement} el the element to move
|
|
* @param {int} iPageX the X coordinate of the mousedown or drag event
|
|
* @param {int} iPageY the Y coordinate of the mousedown or drag event
|
|
*/
|
|
alignElWithMouse: function(el, iPageX, iPageY) {
|
|
var oCoord = this.getTargetCoord(iPageX, iPageY);
|
|
var fly = el.dom ? el : Ext.fly(el, '_dd');
|
|
if (!this.deltaSetXY) {
|
|
var aCoord = [oCoord.x, oCoord.y];
|
|
fly.setXY(aCoord);
|
|
var newLeft = fly.getLeft(true);
|
|
var newTop = fly.getTop(true);
|
|
this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
|
|
} else {
|
|
fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
|
|
}
|
|
|
|
this.cachePosition(oCoord.x, oCoord.y);
|
|
this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
|
|
return oCoord;
|
|
},
|
|
|
|
/**
|
|
* Saves the most recent position so that we can reset the constraints and
|
|
* tick marks on-demand. We need to know this so that we can calculate the
|
|
* number of pixels the element is offset from its original position.
|
|
* @method cachePosition
|
|
* @param iPageX the current x position (optional, this just makes it so we
|
|
* don't have to look it up again)
|
|
* @param iPageY the current y position (optional, this just makes it so we
|
|
* don't have to look it up again)
|
|
*/
|
|
cachePosition: function(iPageX, iPageY) {
|
|
if (iPageX) {
|
|
this.lastPageX = iPageX;
|
|
this.lastPageY = iPageY;
|
|
} else {
|
|
var aCoord = Ext.lib.Dom.getXY(this.getEl());
|
|
this.lastPageX = aCoord[0];
|
|
this.lastPageY = aCoord[1];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Auto-scroll the window if the dragged object has been moved beyond the
|
|
* visible window boundary.
|
|
* @method autoScroll
|
|
* @param {int} x the drag element's x position
|
|
* @param {int} y the drag element's y position
|
|
* @param {int} h the height of the drag element
|
|
* @param {int} w the width of the drag element
|
|
* @private
|
|
*/
|
|
autoScroll: function(x, y, h, w) {
|
|
|
|
if (this.scroll) {
|
|
// The client height
|
|
var clientH = Ext.lib.Dom.getViewHeight();
|
|
|
|
// The client width
|
|
var clientW = Ext.lib.Dom.getViewWidth();
|
|
|
|
// The amt scrolled down
|
|
var st = this.DDM.getScrollTop();
|
|
|
|
// The amt scrolled right
|
|
var sl = this.DDM.getScrollLeft();
|
|
|
|
// Location of the bottom of the element
|
|
var bot = h + y;
|
|
|
|
// Location of the right of the element
|
|
var right = w + x;
|
|
|
|
// The distance from the cursor to the bottom of the visible area,
|
|
// adjusted so that we don't scroll if the cursor is beyond the
|
|
// element drag constraints
|
|
var toBot = (clientH + st - y - this.deltaY);
|
|
|
|
// The distance from the cursor to the right of the visible area
|
|
var toRight = (clientW + sl - x - this.deltaX);
|
|
|
|
|
|
// How close to the edge the cursor must be before we scroll
|
|
// var thresh = (document.all) ? 100 : 40;
|
|
var thresh = 40;
|
|
|
|
// How many pixels to scroll per autoscroll op. This helps to reduce
|
|
// clunky scrolling. IE is more sensitive about this ... it needs this
|
|
// value to be higher.
|
|
var scrAmt = (document.all) ? 80 : 30;
|
|
|
|
// Scroll down if we are near the bottom of the visible page and the
|
|
// obj extends below the crease
|
|
if ( bot > clientH && toBot < thresh ) {
|
|
window.scrollTo(sl, st + scrAmt);
|
|
}
|
|
|
|
// Scroll up if the window is scrolled down and the top of the object
|
|
// goes above the top border
|
|
if ( y < st && st > 0 && y - st < thresh ) {
|
|
window.scrollTo(sl, st - scrAmt);
|
|
}
|
|
|
|
// Scroll right if the obj is beyond the right border and the cursor is
|
|
// near the border.
|
|
if ( right > clientW && toRight < thresh ) {
|
|
window.scrollTo(sl + scrAmt, st);
|
|
}
|
|
|
|
// Scroll left if the window has been scrolled to the right and the obj
|
|
// extends past the left border
|
|
if ( x < sl && sl > 0 && x - sl < thresh ) {
|
|
window.scrollTo(sl - scrAmt, st);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Finds the location the element should be placed if we want to move
|
|
* it to where the mouse location less the click offset would place us.
|
|
* @method getTargetCoord
|
|
* @param {int} iPageX the X coordinate of the click
|
|
* @param {int} iPageY the Y coordinate of the click
|
|
* @return an object that contains the coordinates (Object.x and Object.y)
|
|
* @private
|
|
*/
|
|
getTargetCoord: function(iPageX, iPageY) {
|
|
var x = iPageX - this.deltaX;
|
|
var y = iPageY - this.deltaY;
|
|
|
|
if (this.constrainX) {
|
|
if (x < this.minX) { x = this.minX; }
|
|
if (x > this.maxX) { x = this.maxX; }
|
|
}
|
|
|
|
if (this.constrainY) {
|
|
if (y < this.minY) { y = this.minY; }
|
|
if (y > this.maxY) { y = this.maxY; }
|
|
}
|
|
|
|
x = this.getTick(x, this.xTicks);
|
|
y = this.getTick(y, this.yTicks);
|
|
|
|
|
|
return {x:x, y:y};
|
|
},
|
|
|
|
/**
|
|
* Sets up config options specific to this class. Overrides
|
|
* Ext.dd.DragDrop, but all versions of this method through the
|
|
* inheritance chain are called
|
|
*/
|
|
applyConfig: function() {
|
|
Ext.dd.DD.superclass.applyConfig.call(this);
|
|
this.scroll = (this.config.scroll !== false);
|
|
},
|
|
|
|
/**
|
|
* Event that fires prior to the onMouseDown event. Overrides
|
|
* Ext.dd.DragDrop.
|
|
*/
|
|
b4MouseDown: function(e) {
|
|
// this.resetConstraints();
|
|
this.autoOffset(e.getPageX(),
|
|
e.getPageY());
|
|
},
|
|
|
|
/**
|
|
* Event that fires prior to the onDrag event. Overrides
|
|
* Ext.dd.DragDrop.
|
|
*/
|
|
b4Drag: function(e) {
|
|
this.setDragElPos(e.getPageX(),
|
|
e.getPageY());
|
|
},
|
|
|
|
toString: function() {
|
|
return ("DD " + this.id);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Debugging ygDragDrop events that can be overridden
|
|
//////////////////////////////////////////////////////////////////////////
|
|
/*
|
|
startDrag: function(x, y) {
|
|
},
|
|
|
|
onDrag: function(e) {
|
|
},
|
|
|
|
onDragEnter: function(e, id) {
|
|
},
|
|
|
|
onDragOver: function(e, id) {
|
|
},
|
|
|
|
onDragOut: function(e, id) {
|
|
},
|
|
|
|
onDragDrop: function(e, id) {
|
|
},
|
|
|
|
endDrag: function(e) {
|
|
}
|
|
|
|
*/
|
|
|
|
});
|
|
/**
|
|
* @class Ext.dd.DDProxy
|
|
* A DragDrop implementation that inserts an empty, bordered div into
|
|
* the document that follows the cursor during drag operations. At the time of
|
|
* the click, the frame div is resized to the dimensions of the linked html
|
|
* element, and moved to the exact location of the linked element.
|
|
*
|
|
* References to the "frame" element refer to the single proxy element that
|
|
* was created to be dragged in place of all DDProxy elements on the
|
|
* page.
|
|
*
|
|
* @extends Ext.dd.DD
|
|
* @constructor
|
|
* @param {String} id the id of the linked html element
|
|
* @param {String} sGroup the group of related DragDrop objects
|
|
* @param {object} config an object containing configurable attributes
|
|
* Valid properties for DDProxy in addition to those in DragDrop:
|
|
* resizeFrame, centerFrame, dragElId
|
|
*/
|
|
Ext.dd.DDProxy = function(id, sGroup, config) {
|
|
if (id) {
|
|
this.init(id, sGroup, config);
|
|
this.initFrame();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* The default drag frame div id
|
|
* @property Ext.dd.DDProxy.dragElId
|
|
* @type String
|
|
* @static
|
|
*/
|
|
Ext.dd.DDProxy.dragElId = "ygddfdiv";
|
|
|
|
Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, {
|
|
|
|
/**
|
|
* By default we resize the drag frame to be the same size as the element
|
|
* we want to drag (this is to get the frame effect). We can turn it off
|
|
* if we want a different behavior.
|
|
* @property resizeFrame
|
|
* @type boolean
|
|
*/
|
|
resizeFrame: true,
|
|
|
|
/**
|
|
* By default the frame is positioned exactly where the drag element is, so
|
|
* we use the cursor offset provided by Ext.dd.DD. Another option that works only if
|
|
* you do not have constraints on the obj is to have the drag frame centered
|
|
* around the cursor. Set centerFrame to true for this effect.
|
|
* @property centerFrame
|
|
* @type boolean
|
|
*/
|
|
centerFrame: false,
|
|
|
|
/**
|
|
* Creates the proxy element if it does not yet exist
|
|
* @method createFrame
|
|
*/
|
|
createFrame: function() {
|
|
var self = this;
|
|
var body = document.body;
|
|
|
|
if (!body || !body.firstChild) {
|
|
setTimeout( function() { self.createFrame(); }, 50 );
|
|
return;
|
|
}
|
|
|
|
var div = this.getDragEl();
|
|
|
|
if (!div) {
|
|
div = document.createElement("div");
|
|
div.id = this.dragElId;
|
|
var s = div.style;
|
|
|
|
s.position = "absolute";
|
|
s.visibility = "hidden";
|
|
s.cursor = "move";
|
|
s.border = "2px solid #aaa";
|
|
s.zIndex = 999;
|
|
|
|
// appendChild can blow up IE if invoked prior to the window load event
|
|
// while rendering a table. It is possible there are other scenarios
|
|
// that would cause this to happen as well.
|
|
body.insertBefore(div, body.firstChild);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Initialization for the drag frame element. Must be called in the
|
|
* constructor of all subclasses
|
|
* @method initFrame
|
|
*/
|
|
initFrame: function() {
|
|
this.createFrame();
|
|
},
|
|
|
|
applyConfig: function() {
|
|
Ext.dd.DDProxy.superclass.applyConfig.call(this);
|
|
|
|
this.resizeFrame = (this.config.resizeFrame !== false);
|
|
this.centerFrame = (this.config.centerFrame);
|
|
this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
|
|
},
|
|
|
|
/**
|
|
* Resizes the drag frame to the dimensions of the clicked object, positions
|
|
* it over the object, and finally displays it
|
|
* @method showFrame
|
|
* @param {int} iPageX X click position
|
|
* @param {int} iPageY Y click position
|
|
* @private
|
|
*/
|
|
showFrame: function(iPageX, iPageY) {
|
|
var el = this.getEl();
|
|
var dragEl = this.getDragEl();
|
|
var s = dragEl.style;
|
|
|
|
this._resizeProxy();
|
|
|
|
if (this.centerFrame) {
|
|
this.setDelta( Math.round(parseInt(s.width, 10)/2),
|
|
Math.round(parseInt(s.height, 10)/2) );
|
|
}
|
|
|
|
this.setDragElPos(iPageX, iPageY);
|
|
|
|
Ext.fly(dragEl).show();
|
|
},
|
|
|
|
/**
|
|
* The proxy is automatically resized to the dimensions of the linked
|
|
* element when a drag is initiated, unless resizeFrame is set to false
|
|
* @method _resizeProxy
|
|
* @private
|
|
*/
|
|
_resizeProxy: function() {
|
|
if (this.resizeFrame) {
|
|
var el = this.getEl();
|
|
Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
|
|
}
|
|
},
|
|
|
|
// overrides Ext.dd.DragDrop
|
|
b4MouseDown: function(e) {
|
|
var x = e.getPageX();
|
|
var y = e.getPageY();
|
|
this.autoOffset(x, y);
|
|
this.setDragElPos(x, y);
|
|
},
|
|
|
|
// overrides Ext.dd.DragDrop
|
|
b4StartDrag: function(x, y) {
|
|
// show the drag frame
|
|
this.showFrame(x, y);
|
|
},
|
|
|
|
// overrides Ext.dd.DragDrop
|
|
b4EndDrag: function(e) {
|
|
Ext.fly(this.getDragEl()).hide();
|
|
},
|
|
|
|
// overrides Ext.dd.DragDrop
|
|
// By default we try to move the element to the last location of the frame.
|
|
// This is so that the default behavior mirrors that of Ext.dd.DD.
|
|
endDrag: function(e) {
|
|
|
|
var lel = this.getEl();
|
|
var del = this.getDragEl();
|
|
|
|
// Show the drag frame briefly so we can get its position
|
|
del.style.visibility = "";
|
|
|
|
this.beforeMove();
|
|
// Hide the linked element before the move to get around a Safari
|
|
// rendering bug.
|
|
lel.style.visibility = "hidden";
|
|
Ext.dd.DDM.moveToEl(lel, del);
|
|
del.style.visibility = "hidden";
|
|
lel.style.visibility = "";
|
|
|
|
this.afterDrag();
|
|
},
|
|
|
|
beforeMove : function(){
|
|
|
|
},
|
|
|
|
afterDrag : function(){
|
|
|
|
},
|
|
|
|
toString: function() {
|
|
return ("DDProxy " + this.id);
|
|
}
|
|
|
|
});
|
|
/**
|
|
* @class Ext.dd.DDTarget
|
|
* A DragDrop implementation that does not move, but can be a drop
|
|
* target. You would get the same result by simply omitting implementation
|
|
* for the event callbacks, but this way we reduce the processing cost of the
|
|
* event listener and the callbacks.
|
|
* @extends Ext.dd.DragDrop
|
|
* @constructor
|
|
* @param {String} id the id of the element that is a drop target
|
|
* @param {String} sGroup the group of related DragDrop objects
|
|
* @param {object} config an object containing configurable attributes
|
|
* Valid properties for DDTarget in addition to those in
|
|
* DragDrop:
|
|
* none
|
|
*/
|
|
Ext.dd.DDTarget = function(id, sGroup, config) {
|
|
if (id) {
|
|
this.initTarget(id, sGroup, config);
|
|
}
|
|
};
|
|
|
|
// Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop();
|
|
Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, {
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
getDragEl: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
isValidHandleChild: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
startDrag: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
endDrag: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onDrag: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onDragDrop: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onDragEnter: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onDragOut: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onDragOver: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onInvalidDrop: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onMouseDown: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
onMouseUp: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setXConstraint: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setYConstraint: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
resetConstraints: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
clearConstraints: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
clearTicks: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setInitPosition: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setDragElId: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setHandleElId: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
setOuterHandleElId: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
addInvalidHandleClass: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
addInvalidHandleId: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
addInvalidHandleType: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
removeInvalidHandleClass: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
removeInvalidHandleId: Ext.emptyFn,
|
|
/**
|
|
* @hide
|
|
* Overridden and disabled. A DDTarget does not support being dragged.
|
|
* @method
|
|
*/
|
|
removeInvalidHandleType: Ext.emptyFn,
|
|
|
|
toString: function() {
|
|
return ("DDTarget " + this.id);
|
|
}
|
|
});/**
|
|
* @class Ext.dd.DragTracker
|
|
* @extends Ext.util.Observable
|
|
* A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
|
|
* as well as during the drag. This is useful for components such as {@link Ext.Slider}, where there is
|
|
* an element that can be dragged around to change the Slider's value.
|
|
* DragTracker provides a series of template methods that should be overridden to provide functionality
|
|
* in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd.
|
|
* See {@link Ext.Slider}'s initEvents function for an example implementation.
|
|
*/
|
|
Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
|
|
/**
|
|
* @cfg {Boolean} active
|
|
* Defaults to <tt>false</tt>.
|
|
*/
|
|
active: false,
|
|
/**
|
|
* @cfg {Number} tolerance
|
|
* Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>.
|
|
*/
|
|
tolerance: 5,
|
|
/**
|
|
* @cfg {Boolean/Number} autoStart
|
|
* Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
|
|
* Specify a Number for the number of milliseconds to defer trigger start.
|
|
*/
|
|
autoStart: false,
|
|
|
|
constructor : function(config){
|
|
Ext.apply(this, config);
|
|
this.addEvents(
|
|
/**
|
|
* @event mousedown
|
|
* @param {Object} this
|
|
* @param {Object} e event object
|
|
*/
|
|
'mousedown',
|
|
/**
|
|
* @event mouseup
|
|
* @param {Object} this
|
|
* @param {Object} e event object
|
|
*/
|
|
'mouseup',
|
|
/**
|
|
* @event mousemove
|
|
* @param {Object} this
|
|
* @param {Object} e event object
|
|
*/
|
|
'mousemove',
|
|
/**
|
|
* @event dragstart
|
|
* @param {Object} this
|
|
* @param {Object} startXY the page coordinates of the event
|
|
*/
|
|
'dragstart',
|
|
/**
|
|
* @event dragend
|
|
* @param {Object} this
|
|
* @param {Object} e event object
|
|
*/
|
|
'dragend',
|
|
/**
|
|
* @event drag
|
|
* @param {Object} this
|
|
* @param {Object} e event object
|
|
*/
|
|
'drag'
|
|
);
|
|
|
|
this.dragRegion = new Ext.lib.Region(0,0,0,0);
|
|
|
|
if(this.el){
|
|
this.initEl(this.el);
|
|
}
|
|
Ext.dd.DragTracker.superclass.constructor.call(this, config);
|
|
},
|
|
|
|
initEl: function(el){
|
|
this.el = Ext.get(el);
|
|
el.on('mousedown', this.onMouseDown, this,
|
|
this.delegate ? {delegate: this.delegate} : undefined);
|
|
},
|
|
|
|
destroy : function(){
|
|
this.el.un('mousedown', this.onMouseDown, this);
|
|
},
|
|
|
|
onMouseDown: function(e, target){
|
|
if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
|
|
this.startXY = this.lastXY = e.getXY();
|
|
this.dragTarget = this.delegate ? target : this.el.dom;
|
|
if(this.preventDefault !== false){
|
|
e.preventDefault();
|
|
}
|
|
var doc = Ext.getDoc();
|
|
doc.on('mouseup', this.onMouseUp, this);
|
|
doc.on('mousemove', this.onMouseMove, this);
|
|
doc.on('selectstart', this.stopSelect, this);
|
|
if(this.autoStart){
|
|
this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
|
|
}
|
|
}
|
|
},
|
|
|
|
onMouseMove: function(e, target){
|
|
// HACK: IE hack to see if button was released outside of window. */
|
|
if(this.active && Ext.isIE && !e.browserEvent.button){
|
|
e.preventDefault();
|
|
this.onMouseUp(e);
|
|
return;
|
|
}
|
|
|
|
e.preventDefault();
|
|
var xy = e.getXY(), s = this.startXY;
|
|
this.lastXY = xy;
|
|
if(!this.active){
|
|
if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
|
|
this.triggerStart();
|
|
}else{
|
|
return;
|
|
}
|
|
}
|
|
this.fireEvent('mousemove', this, e);
|
|
this.onDrag(e);
|
|
this.fireEvent('drag', this, e);
|
|
},
|
|
|
|
onMouseUp: function(e) {
|
|
var doc = Ext.getDoc();
|
|
doc.un('mousemove', this.onMouseMove, this);
|
|
doc.un('mouseup', this.onMouseUp, this);
|
|
doc.un('selectstart', this.stopSelect, this);
|
|
e.preventDefault();
|
|
this.clearStart();
|
|
var wasActive = this.active;
|
|
this.active = false;
|
|
delete this.elRegion;
|
|
this.fireEvent('mouseup', this, e);
|
|
if(wasActive){
|
|
this.onEnd(e);
|
|
this.fireEvent('dragend', this, e);
|
|
}
|
|
},
|
|
|
|
triggerStart: function(isTimer) {
|
|
this.clearStart();
|
|
this.active = true;
|
|
this.onStart(this.startXY);
|
|
this.fireEvent('dragstart', this, this.startXY);
|
|
},
|
|
|
|
clearStart : function() {
|
|
if(this.timer){
|
|
clearTimeout(this.timer);
|
|
delete this.timer;
|
|
}
|
|
},
|
|
|
|
stopSelect : function(e) {
|
|
e.stopEvent();
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
|
|
* holds the mouse button down. Return false to disallow the drag
|
|
* @param {Ext.EventObject} e The event object
|
|
*/
|
|
onBeforeStart : function(e) {
|
|
|
|
},
|
|
|
|
/**
|
|
* Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
|
|
* (e.g. the user has moved the tracked element beyond the specified tolerance)
|
|
* @param {Array} xy x and y co-ordinates of the original location of the tracked element
|
|
*/
|
|
onStart : function(xy) {
|
|
|
|
},
|
|
|
|
/**
|
|
* Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
|
|
* @param {Ext.EventObject} e The event object
|
|
*/
|
|
onDrag : function(e) {
|
|
|
|
},
|
|
|
|
/**
|
|
* Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
|
|
* (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
|
|
* @param {Ext.EventObject} e The event object
|
|
*/
|
|
onEnd : function(e) {
|
|
|
|
},
|
|
|
|
/**
|
|
* Returns the drag target
|
|
* @return {Ext.Element} The element currently being tracked
|
|
*/
|
|
getDragTarget : function(){
|
|
return this.dragTarget;
|
|
},
|
|
|
|
getDragCt : function(){
|
|
return this.el;
|
|
},
|
|
|
|
getXY : function(constrain){
|
|
return constrain ?
|
|
this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
|
|
},
|
|
|
|
getOffset : function(constrain){
|
|
var xy = this.getXY(constrain);
|
|
var s = this.startXY;
|
|
return [s[0]-xy[0], s[1]-xy[1]];
|
|
},
|
|
|
|
constrainModes: {
|
|
'point' : function(xy){
|
|
|
|
if(!this.elRegion){
|
|
this.elRegion = this.getDragCt().getRegion();
|
|
}
|
|
|
|
var dr = this.dragRegion;
|
|
|
|
dr.left = xy[0];
|
|
dr.top = xy[1];
|
|
dr.right = xy[0];
|
|
dr.bottom = xy[1];
|
|
|
|
dr.constrainTo(this.elRegion);
|
|
|
|
return [dr.left, dr.top];
|
|
}
|
|
}
|
|
});/**
|
|
* @class Ext.dd.ScrollManager
|
|
* <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
|
|
* <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
|
|
* but you can also override most of the configs per scroll container by adding a
|
|
* <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
|
|
* {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
|
|
* <pre><code>
|
|
var el = Ext.get('scroll-ct');
|
|
el.ddScrollConfig = {
|
|
vthresh: 50,
|
|
hthresh: -1,
|
|
frequency: 100,
|
|
increment: 200
|
|
};
|
|
Ext.dd.ScrollManager.register(el);
|
|
</code></pre>
|
|
* <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
|
|
* @singleton
|
|
*/
|
|
Ext.dd.ScrollManager = function(){
|
|
var ddm = Ext.dd.DragDropMgr;
|
|
var els = {};
|
|
var dragEl = null;
|
|
var proc = {};
|
|
|
|
var onStop = function(e){
|
|
dragEl = null;
|
|
clearProc();
|
|
};
|
|
|
|
var triggerRefresh = function(){
|
|
if(ddm.dragCurrent){
|
|
ddm.refreshCache(ddm.dragCurrent.groups);
|
|
}
|
|
};
|
|
|
|
var doScroll = function(){
|
|
if(ddm.dragCurrent){
|
|
var dds = Ext.dd.ScrollManager;
|
|
var inc = proc.el.ddScrollConfig ?
|
|
proc.el.ddScrollConfig.increment : dds.increment;
|
|
if(!dds.animate){
|
|
if(proc.el.scroll(proc.dir, inc)){
|
|
triggerRefresh();
|
|
}
|
|
}else{
|
|
proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
|
|
}
|
|
}
|
|
};
|
|
|
|
var clearProc = function(){
|
|
if(proc.id){
|
|
clearInterval(proc.id);
|
|
}
|
|
proc.id = 0;
|
|
proc.el = null;
|
|
proc.dir = "";
|
|
};
|
|
|
|
var startProc = function(el, dir){
|
|
clearProc();
|
|
proc.el = el;
|
|
proc.dir = dir;
|
|
var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
|
|
el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;
|
|
proc.id = setInterval(doScroll, freq);
|
|
};
|
|
|
|
var onFire = function(e, isDrop){
|
|
if(isDrop || !ddm.dragCurrent){ return; }
|
|
var dds = Ext.dd.ScrollManager;
|
|
if(!dragEl || dragEl != ddm.dragCurrent){
|
|
dragEl = ddm.dragCurrent;
|
|
// refresh regions on drag start
|
|
dds.refreshCache();
|
|
}
|
|
|
|
var xy = Ext.lib.Event.getXY(e);
|
|
var pt = new Ext.lib.Point(xy[0], xy[1]);
|
|
for(var id in els){
|
|
var el = els[id], r = el._region;
|
|
var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
|
|
if(r && r.contains(pt) && el.isScrollable()){
|
|
if(r.bottom - pt.y <= c.vthresh){
|
|
if(proc.el != el){
|
|
startProc(el, "down");
|
|
}
|
|
return;
|
|
}else if(r.right - pt.x <= c.hthresh){
|
|
if(proc.el != el){
|
|
startProc(el, "left");
|
|
}
|
|
return;
|
|
}else if(pt.y - r.top <= c.vthresh){
|
|
if(proc.el != el){
|
|
startProc(el, "up");
|
|
}
|
|
return;
|
|
}else if(pt.x - r.left <= c.hthresh){
|
|
if(proc.el != el){
|
|
startProc(el, "right");
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
clearProc();
|
|
};
|
|
|
|
ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
|
|
ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
|
|
|
|
return {
|
|
/**
|
|
* Registers new overflow element(s) to auto scroll
|
|
* @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
|
|
*/
|
|
register : function(el){
|
|
if(Ext.isArray(el)){
|
|
for(var i = 0, len = el.length; i < len; i++) {
|
|
this.register(el[i]);
|
|
}
|
|
}else{
|
|
el = Ext.get(el);
|
|
els[el.id] = el;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Unregisters overflow element(s) so they are no longer scrolled
|
|
* @param {Mixed/Array} el The id of or the element to be removed or an array of either
|
|
*/
|
|
unregister : function(el){
|
|
if(Ext.isArray(el)){
|
|
for(var i = 0, len = el.length; i < len; i++) {
|
|
this.unregister(el[i]);
|
|
}
|
|
}else{
|
|
el = Ext.get(el);
|
|
delete els[el.id];
|
|
}
|
|
},
|
|
|
|
/**
|
|
* The number of pixels from the top or bottom edge of a container the pointer needs to be to
|
|
* trigger scrolling (defaults to 25)
|
|
* @type Number
|
|
*/
|
|
vthresh : 25,
|
|
/**
|
|
* The number of pixels from the right or left edge of a container the pointer needs to be to
|
|
* trigger scrolling (defaults to 25)
|
|
* @type Number
|
|
*/
|
|
hthresh : 25,
|
|
|
|
/**
|
|
* The number of pixels to scroll in each scroll increment (defaults to 50)
|
|
* @type Number
|
|
*/
|
|
increment : 100,
|
|
|
|
/**
|
|
* The frequency of scrolls in milliseconds (defaults to 500)
|
|
* @type Number
|
|
*/
|
|
frequency : 500,
|
|
|
|
/**
|
|
* True to animate the scroll (defaults to true)
|
|
* @type Boolean
|
|
*/
|
|
animate: true,
|
|
|
|
/**
|
|
* The animation duration in seconds -
|
|
* MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
|
|
* @type Number
|
|
*/
|
|
animDuration: .4,
|
|
|
|
/**
|
|
* Manually trigger a cache refresh.
|
|
*/
|
|
refreshCache : function(){
|
|
for(var id in els){
|
|
if(typeof els[id] == 'object'){ // for people extending the object prototype
|
|
els[id]._region = els[id].getRegion();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}();/**
|
|
* @class Ext.dd.Registry
|
|
* Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
|
|
* directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
|
|
* @singleton
|
|
*/
|
|
Ext.dd.Registry = function(){
|
|
var elements = {};
|
|
var handles = {};
|
|
var autoIdSeed = 0;
|
|
|
|
var getId = function(el, autogen){
|
|
if(typeof el == "string"){
|
|
return el;
|
|
}
|
|
var id = el.id;
|
|
if(!id && autogen !== false){
|
|
id = "extdd-" + (++autoIdSeed);
|
|
el.id = id;
|
|
}
|
|
return id;
|
|
};
|
|
|
|
return {
|
|
/**
|
|
* Resgister a drag drop element
|
|
* @param {String/HTMLElement} element The id or DOM node to register
|
|
* @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
|
|
* in drag drop operations. You can populate this object with any arbitrary properties that your own code
|
|
* knows how to interpret, plus there are some specific properties known to the Registry that should be
|
|
* populated in the data object (if applicable):
|
|
* <pre>
|
|
Value Description<br />
|
|
--------- ------------------------------------------<br />
|
|
handles Array of DOM nodes that trigger dragging<br />
|
|
for the element being registered<br />
|
|
isHandle True if the element passed in triggers<br />
|
|
dragging itself, else false
|
|
</pre>
|
|
*/
|
|
register : function(el, data){
|
|
data = data || {};
|
|
if(typeof el == "string"){
|
|
el = document.getElementById(el);
|
|
}
|
|
data.ddel = el;
|
|
elements[getId(el)] = data;
|
|
if(data.isHandle !== false){
|
|
handles[data.ddel.id] = data;
|
|
}
|
|
if(data.handles){
|
|
var hs = data.handles;
|
|
for(var i = 0, len = hs.length; i < len; i++){
|
|
handles[getId(hs[i])] = data;
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Unregister a drag drop element
|
|
* @param {String/HTMLElement} element The id or DOM node to unregister
|
|
*/
|
|
unregister : function(el){
|
|
var id = getId(el, false);
|
|
var data = elements[id];
|
|
if(data){
|
|
delete elements[id];
|
|
if(data.handles){
|
|
var hs = data.handles;
|
|
for(var i = 0, len = hs.length; i < len; i++){
|
|
delete handles[getId(hs[i], false)];
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Returns the handle registered for a DOM Node by id
|
|
* @param {String/HTMLElement} id The DOM node or id to look up
|
|
* @return {Object} handle The custom handle data
|
|
*/
|
|
getHandle : function(id){
|
|
if(typeof id != "string"){ // must be element?
|
|
id = id.id;
|
|
}
|
|
return handles[id];
|
|
},
|
|
|
|
/**
|
|
* Returns the handle that is registered for the DOM node that is the target of the event
|
|
* @param {Event} e The event
|
|
* @return {Object} handle The custom handle data
|
|
*/
|
|
getHandleFromEvent : function(e){
|
|
var t = Ext.lib.Event.getTarget(e);
|
|
return t ? handles[t.id] : null;
|
|
},
|
|
|
|
/**
|
|
* Returns a custom data object that is registered for a DOM node by id
|
|
* @param {String/HTMLElement} id The DOM node or id to look up
|
|
* @return {Object} data The custom data
|
|
*/
|
|
getTarget : function(id){
|
|
if(typeof id != "string"){ // must be element?
|
|
id = id.id;
|
|
}
|
|
return elements[id];
|
|
},
|
|
|
|
/**
|
|
* Returns a custom data object that is registered for the DOM node that is the target of the event
|
|
* @param {Event} e The event
|
|
* @return {Object} data The custom data
|
|
*/
|
|
getTargetFromEvent : function(e){
|
|
var t = Ext.lib.Event.getTarget(e);
|
|
return t ? elements[t.id] || handles[t.id] : null;
|
|
}
|
|
};
|
|
}();/**
|
|
* @class Ext.dd.StatusProxy
|
|
* A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair. This is the
|
|
* default drag proxy used by all Ext.dd components.
|
|
* @constructor
|
|
* @param {Object} config
|
|
*/
|
|
Ext.dd.StatusProxy = function(config){
|
|
Ext.apply(this, config);
|
|
this.id = this.id || Ext.id();
|
|
this.el = new Ext.Layer({
|
|
dh: {
|
|
id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
|
|
{tag: "div", cls: "x-dd-drop-icon"},
|
|
{tag: "div", cls: "x-dd-drag-ghost"}
|
|
]
|
|
},
|
|
shadow: !config || config.shadow !== false
|
|
});
|
|
this.ghost = Ext.get(this.el.dom.childNodes[1]);
|
|
this.dropStatus = this.dropNotAllowed;
|
|
};
|
|
|
|
Ext.dd.StatusProxy.prototype = {
|
|
/**
|
|
* @cfg {String} dropAllowed
|
|
* The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
|
|
*/
|
|
dropAllowed : "x-dd-drop-ok",
|
|
/**
|
|
* @cfg {String} dropNotAllowed
|
|
* The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
|
|
*/
|
|
dropNotAllowed : "x-dd-drop-nodrop",
|
|
|
|
/**
|
|
* Updates the proxy's visual element to indicate the status of whether or not drop is allowed
|
|
* over the current target element.
|
|
* @param {String} cssClass The css class for the new drop status indicator image
|
|
*/
|
|
setStatus : function(cssClass){
|
|
cssClass = cssClass || this.dropNotAllowed;
|
|
if(this.dropStatus != cssClass){
|
|
this.el.replaceClass(this.dropStatus, cssClass);
|
|
this.dropStatus = cssClass;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Resets the status indicator to the default dropNotAllowed value
|
|
* @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
|
|
*/
|
|
reset : function(clearGhost){
|
|
this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
|
|
this.dropStatus = this.dropNotAllowed;
|
|
if(clearGhost){
|
|
this.ghost.update("");
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Updates the contents of the ghost element
|
|
* @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a
|
|
* DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).
|
|
*/
|
|
update : function(html){
|
|
if(typeof html == "string"){
|
|
this.ghost.update(html);
|
|
}else{
|
|
this.ghost.update("");
|
|
html.style.margin = "0";
|
|
this.ghost.dom.appendChild(html);
|
|
}
|
|
var el = this.ghost.dom.firstChild;
|
|
if(el){
|
|
Ext.fly(el).setStyle('float', 'none');
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Returns the underlying proxy {@link Ext.Layer}
|
|
* @return {Ext.Layer} el
|
|
*/
|
|
getEl : function(){
|
|
return this.el;
|
|
},
|
|
|
|
/**
|
|
* Returns the ghost element
|
|
* @return {Ext.Element} el
|
|
*/
|
|
getGhost : function(){
|
|
return this.ghost;
|
|
},
|
|
|
|
/**
|
|
* Hides the proxy
|
|
* @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
|
|
*/
|
|
hide : function(clear){
|
|
this.el.hide();
|
|
if(clear){
|
|
this.reset(true);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Stops the repair animation if it's currently running
|
|
*/
|
|
stop : function(){
|
|
if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
|
|
this.anim.stop();
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Displays this proxy
|
|
*/
|
|
show : function(){
|
|
this.el.show();
|
|
},
|
|
|
|
/**
|
|
* Force the Layer to sync its shadow and shim positions to the element
|
|
*/
|
|
sync : function(){
|
|
this.el.sync();
|
|
},
|
|
|
|
/**
|
|
* Causes the proxy to return to its position of origin via an animation. Should be called after an
|
|
* invalid drop operation by the item being dragged.
|
|
* @param {Array} xy The XY position of the element ([x, y])
|
|
* @param {Function} callback The function to call after the repair is complete.
|
|
* @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
|
|
*/
|
|
repair : function(xy, callback, scope){
|
|
this.callback = callback;
|
|
this.scope = scope;
|
|
if(xy && this.animRepair !== false){
|
|
this.el.addClass("x-dd-drag-repair");
|
|
this.el.hideUnders(true);
|
|
this.anim = this.el.shift({
|
|
duration: this.repairDuration || .5,
|
|
easing: 'easeOut',
|
|
xy: xy,
|
|
stopFx: true,
|
|
callback: this.afterRepair,
|
|
scope: this
|
|
});
|
|
}else{
|
|
this.afterRepair();
|
|
}
|
|
},
|
|
|
|
// private
|
|
afterRepair : function(){
|
|
this.hide(true);
|
|
if(typeof this.callback == "function"){
|
|
this.callback.call(this.scope || this);
|
|
}
|
|
this.callback = null;
|
|
this.scope = null;
|
|
},
|
|
|
|
destroy: function(){
|
|
Ext.destroy(this.ghost, this.el);
|
|
}
|
|
};/**
|
|
* @class Ext.dd.DragSource
|
|
* @extends Ext.dd.DDProxy
|
|
* A simple class that provides the basic implementation needed to make any element draggable.
|
|
* @constructor
|
|
* @param {Mixed} el The container element
|
|
* @param {Object} config
|
|
*/
|
|
Ext.dd.DragSource = function(el, config){
|
|
this.el = Ext.get(el);
|
|
if(!this.dragData){
|
|
this.dragData = {};
|
|
}
|
|
|
|
Ext.apply(this, config);
|
|
|
|
if(!this.proxy){
|
|
this.proxy = new Ext.dd.StatusProxy();
|
|
}
|
|
Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
|
|
{dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
|
|
|
|
this.dragging = false;
|
|
};
|
|
|
|
Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
|
|
/**
|
|
* @cfg {String} ddGroup
|
|
* A named drag drop group to which this object belongs. If a group is specified, then this object will only
|
|
* interact with other drag drop objects in the same group (defaults to undefined).
|
|
*/
|
|
/**
|
|
* @cfg {String} dropAllowed
|
|
* The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
|
|
*/
|
|
dropAllowed : "x-dd-drop-ok",
|
|
/**
|
|
* @cfg {String} dropNotAllowed
|
|
* The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
|
|
*/
|
|
dropNotAllowed : "x-dd-drop-nodrop",
|
|
|
|
/**
|
|
* Returns the data object associated with this drag source
|
|
* @return {Object} data An object containing arbitrary data
|
|
*/
|
|
getDragData : function(e){
|
|
return this.dragData;
|
|
},
|
|
|
|
// private
|
|
onDragEnter : function(e, id){
|
|
var target = Ext.dd.DragDropMgr.getDDById(id);
|
|
this.cachedTarget = target;
|
|
if(this.beforeDragEnter(target, e, id) !== false){
|
|
if(target.isNotifyTarget){
|
|
var status = target.notifyEnter(this, e, this.dragData);
|
|
this.proxy.setStatus(status);
|
|
}else{
|
|
this.proxy.setStatus(this.dropAllowed);
|
|
}
|
|
|
|
if(this.afterDragEnter){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* when the dragged item enters the drop target by providing an implementation.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @method afterDragEnter
|
|
*/
|
|
this.afterDragEnter(target, e, id);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* before the dragged item enters the drop target and optionally cancel the onDragEnter.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
|
|
*/
|
|
beforeDragEnter : function(target, e, id){
|
|
return true;
|
|
},
|
|
|
|
// private
|
|
alignElWithMouse: function() {
|
|
Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
|
|
this.proxy.sync();
|
|
},
|
|
|
|
// private
|
|
onDragOver : function(e, id){
|
|
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
|
|
if(this.beforeDragOver(target, e, id) !== false){
|
|
if(target.isNotifyTarget){
|
|
var status = target.notifyOver(this, e, this.dragData);
|
|
this.proxy.setStatus(status);
|
|
}
|
|
|
|
if(this.afterDragOver){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* while the dragged item is over the drop target by providing an implementation.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @method afterDragOver
|
|
*/
|
|
this.afterDragOver(target, e, id);
|
|
}
|
|
}
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* while the dragged item is over the drop target and optionally cancel the onDragOver.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
|
|
*/
|
|
beforeDragOver : function(target, e, id){
|
|
return true;
|
|
},
|
|
|
|
// private
|
|
onDragOut : function(e, id){
|
|
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
|
|
if(this.beforeDragOut(target, e, id) !== false){
|
|
if(target.isNotifyTarget){
|
|
target.notifyOut(this, e, this.dragData);
|
|
}
|
|
this.proxy.reset();
|
|
if(this.afterDragOut){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* after the dragged item is dragged out of the target without dropping.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @method afterDragOut
|
|
*/
|
|
this.afterDragOut(target, e, id);
|
|
}
|
|
}
|
|
this.cachedTarget = null;
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action before the dragged
|
|
* item is dragged out of the target without dropping, and optionally cancel the onDragOut.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
|
|
*/
|
|
beforeDragOut : function(target, e, id){
|
|
return true;
|
|
},
|
|
|
|
// private
|
|
onDragDrop : function(e, id){
|
|
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
|
|
if(this.beforeDragDrop(target, e, id) !== false){
|
|
if(target.isNotifyTarget){
|
|
if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
|
|
this.onValidDrop(target, e, id);
|
|
}else{
|
|
this.onInvalidDrop(target, e, id);
|
|
}
|
|
}else{
|
|
this.onValidDrop(target, e, id);
|
|
}
|
|
|
|
if(this.afterDragDrop){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* after a valid drag drop has occurred by providing an implementation.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dropped element
|
|
* @method afterDragDrop
|
|
*/
|
|
this.afterDragDrop(target, e, id);
|
|
}
|
|
}
|
|
delete this.cachedTarget;
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action before the dragged
|
|
* item is dropped onto the target and optionally cancel the onDragDrop.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
|
|
*/
|
|
beforeDragDrop : function(target, e, id){
|
|
return true;
|
|
},
|
|
|
|
// private
|
|
onValidDrop : function(target, e, id){
|
|
this.hideProxy();
|
|
if(this.afterValidDrop){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* after a valid drop has occurred by providing an implementation.
|
|
* @param {Object} target The target DD
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dropped element
|
|
* @method afterInvalidDrop
|
|
*/
|
|
this.afterValidDrop(target, e, id);
|
|
}
|
|
},
|
|
|
|
// private
|
|
getRepairXY : function(e, data){
|
|
return this.el.getXY();
|
|
},
|
|
|
|
// private
|
|
onInvalidDrop : function(target, e, id){
|
|
this.beforeInvalidDrop(target, e, id);
|
|
if(this.cachedTarget){
|
|
if(this.cachedTarget.isNotifyTarget){
|
|
this.cachedTarget.notifyOut(this, e, this.dragData);
|
|
}
|
|
this.cacheTarget = null;
|
|
}
|
|
this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
|
|
|
|
if(this.afterInvalidDrop){
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action
|
|
* after an invalid drop has occurred by providing an implementation.
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dropped element
|
|
* @method afterInvalidDrop
|
|
*/
|
|
this.afterInvalidDrop(e, id);
|
|
}
|
|
},
|
|
|
|
// private
|
|
afterRepair : function(){
|
|
if(Ext.enableFx){
|
|
this.el.highlight(this.hlColor || "c3daf9");
|
|
}
|
|
this.dragging = false;
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action after an invalid
|
|
* drop has occurred.
|
|
* @param {Ext.dd.DragDrop} target The drop target
|
|
* @param {Event} e The event object
|
|
* @param {String} id The id of the dragged element
|
|
* @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
|
|
*/
|
|
beforeInvalidDrop : function(target, e, id){
|
|
return true;
|
|
},
|
|
|
|
// private
|
|
handleMouseDown : function(e){
|
|
if(this.dragging) {
|
|
return;
|
|
}
|
|
var data = this.getDragData(e);
|
|
if(data && this.onBeforeDrag(data, e) !== false){
|
|
this.dragData = data;
|
|
this.proxy.stop();
|
|
Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action before the initial
|
|
* drag event begins and optionally cancel it.
|
|
* @param {Object} data An object containing arbitrary data to be shared with drop targets
|
|
* @param {Event} e The event object
|
|
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
|
|
*/
|
|
onBeforeDrag : function(data, e){
|
|
return true;
|
|
},
|
|
|
|
/**
|
|
* An empty function by default, but provided so that you can perform a custom action once the initial
|
|
* drag event has begun. The drag cannot be canceled from this function.
|
|
* @param {Number} x The x position of the click on the dragged object
|
|
* @param {Number} y The y position of the click on the dragged object
|
|
*/
|
|
onStartDrag : Ext.emptyFn,
|
|
|
|
// private override
|
|
startDrag : function(x, y){
|
|
this.proxy.reset();
|
|
this.dragging = true;
|
|
this.proxy.update("");
|
|
this.onInitDrag(x, y);
|
|
this.proxy.show();
|
|
},
|
|
|
|
// private
|
|
onInitDrag : function(x, y){
|
|
var clone = this.el.dom.cloneNode(true);
|
|
clone.id = Ext.id(); // prevent duplicate ids
|
|
this.proxy.update(clone);
|
|
this.onStartDrag(x, y);
|
|
return true;
|
|
},
|
|
|
|
/**
|
|
* Returns the drag source's underlying {@link Ext.dd.StatusProxy}
|
|
* @return {Ext.dd.StatusProxy} proxy The StatusProxy
|
|
*/
|
|
getProxy : function(){
|
|
return this.proxy;
|
|
},
|
|
|
|
/**
|
|
* Hides the drag source's {@link Ext.dd.StatusProxy}
|
|
*/
|
|
hideProxy : function(){
|
|
this.proxy.hide();
|
|
this.proxy.reset(true);
|
|
this.dragging = false;
|
|
},
|
|
|
|
// private
|
|
triggerCacheRefresh : function(){
|
|
Ext.dd.DDM.refreshCache(this.groups);
|
|
},
|
|
|
|
// private - override to prevent hiding
|
|
b4EndDrag: function(e) {
|
|
},
|
|
|
|
// private - override to prevent moving
|
|
endDrag : function(e){
|
|
this.onEndDrag(this.dragData, e);
|
|
},
|
|
|
|
// private
|
|
onEndDrag : function(data, e){
|
|
},
|
|
|
|
// private - pin to cursor
|
|
autoOffset : function(x, y) {
|
|
this.setDelta(-12, -20);
|
|
},
|
|
|
|
destroy: function(){
|
|
Ext.dd.DragSource.superclass.destroy.call(this);
|
|
Ext.destroy(this.proxy);
|
|
}
|
|
});/**
|
|
* @class Ext.dd.DropTarget
|
|
* @extends Ext.dd.DDTarget
|
|
* A simple class that provides the basic implementation needed to make any element a drop target that can have
|
|
* draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
|
|
* @constructor
|
|
* @param {Mixed} el The container element
|
|
* @param {Object} config
|
|
*/
|
|
Ext.dd.DropTarget = function(el, config){
|
|
this.el = Ext.get(el);
|
|
|
|
Ext.apply(this, config);
|
|
|
|
if(this.containerScroll){
|
|
Ext.dd.ScrollManager.register(this.el);
|
|
}
|
|
|
|
Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
|
|
{isTarget: true});
|
|
|
|
};
|
|
|
|
Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, {
|
|
/**
|
|
* @cfg {String} ddGroup
|
|
* A named drag drop group to which this object belongs. If a group is specified, then this object will only
|
|
* interact with other drag drop objects in the same group (defaults to undefined).
|
|
*/
|
|
/**
|
|
* @cfg {String} overClass
|
|
* The CSS class applied to the drop target element while the drag source is over it (defaults to "").
|
|
*/
|
|
/**
|
|
* @cfg {String} dropAllowed
|
|
* The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
|
|
*/
|
|
dropAllowed : "x-dd-drop-ok",
|
|
/**
|
|
* @cfg {String} dropNotAllowed
|
|
* The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
|
|
*/
|
|
dropNotAllowed : "x-dd-drop-nodrop",
|
|
|
|
// private
|
|
isTarget : true,
|
|
|
|
// private
|
|
isNotifyTarget : true,
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the
|
|
* target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
|
|
* and returns the dropAllowed config value. This method should be overridden if drop validation is required.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
notifyEnter : function(dd, e, data){
|
|
if(this.overClass){
|
|
this.el.addClass(this.overClass);
|
|
}
|
|
return this.dropAllowed;
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.
|
|
* This method will be called on every mouse movement while the drag source is over the drop target.
|
|
* This default implementation simply returns the dropAllowed config value.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
notifyOver : function(dd, e, data){
|
|
return this.dropAllowed;
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged
|
|
* out of the target without dropping. This default implementation simply removes the CSS class specified by
|
|
* overClass (if any) from the drop element.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
*/
|
|
notifyOut : function(dd, e, data){
|
|
if(this.overClass){
|
|
this.el.removeClass(this.overClass);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has
|
|
* been dropped on it. This method has no default implementation and returns false, so you must provide an
|
|
* implementation that does something to process the drop event and returns true so that the drag source's
|
|
* repair action does not run.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {Boolean} True if the drop was valid, else false
|
|
*/
|
|
notifyDrop : function(dd, e, data){
|
|
return false;
|
|
}
|
|
});/**
|
|
* @class Ext.dd.DragZone
|
|
* @extends Ext.dd.DragSource
|
|
* <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
|
|
* <p>This class does not move the drag target nodes, but a proxy element which may contain
|
|
* any DOM structure you wish. The DOM element to show in the proxy is provided by either a
|
|
* provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
|
|
* <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
|
|
* application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
|
|
* is the most efficient way to "activate" those nodes.</p>
|
|
* <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
|
|
* However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
|
|
* the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
|
|
* mouse event to see if it has taken place within an element, or class of elements. This is easily done
|
|
* by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
|
|
* {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
|
|
* technique. Knowledge of the use of the DataView is required:</p><pre><code>
|
|
myDataView.on('render', function(v) {
|
|
myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
|
|
|
|
// On receipt of a mousedown event, see if it is within a DataView node.
|
|
// Return a drag data object if so.
|
|
getDragData: function(e) {
|
|
|
|
// Use the DataView's own itemSelector (a mandatory property) to
|
|
// test if the mousedown is within one of the DataView's nodes.
|
|
var sourceEl = e.getTarget(v.itemSelector, 10);
|
|
|
|
// If the mousedown is within a DataView node, clone the node to produce
|
|
// a ddel element for use by the drag proxy. Also add application data
|
|
// to the returned data object.
|
|
if (sourceEl) {
|
|
d = sourceEl.cloneNode(true);
|
|
d.id = Ext.id();
|
|
return {
|
|
ddel: d,
|
|
sourceEl: sourceEl,
|
|
repairXY: Ext.fly(sourceEl).getXY(),
|
|
sourceStore: v.store,
|
|
draggedRecord: v.{@link Ext.DataView#getRecord getRecord}(sourceEl)
|
|
}
|
|
}
|
|
},
|
|
|
|
// Provide coordinates for the proxy to slide back to on failed drag.
|
|
// This is the original XY coordinates of the draggable element captured
|
|
// in the getDragData method.
|
|
getRepairXY: function() {
|
|
return this.dragData.repairXY;
|
|
}
|
|
});
|
|
});</code></pre>
|
|
* See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
|
|
* cooperates with this DragZone.
|
|
* @constructor
|
|
* @param {Mixed} el The container element
|
|
* @param {Object} config
|
|
*/
|
|
Ext.dd.DragZone = function(el, config){
|
|
Ext.dd.DragZone.superclass.constructor.call(this, el, config);
|
|
if(this.containerScroll){
|
|
Ext.dd.ScrollManager.register(this.el);
|
|
}
|
|
};
|
|
|
|
Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
|
|
/**
|
|
* This property contains the data representing the dragged object. This data is set up by the implementation
|
|
* of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
|
|
* any other data according to the application's needs.
|
|
* @type Object
|
|
* @property dragData
|
|
*/
|
|
/**
|
|
* @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
|
|
* for auto scrolling during drag operations.
|
|
*/
|
|
/**
|
|
* @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
|
|
* method after a failed drop (defaults to "c3daf9" - light blue)
|
|
*/
|
|
|
|
/**
|
|
* Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
|
|
* for a valid target to drag based on the mouse down. Override this method
|
|
* to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
|
|
* object has a "ddel" attribute (with an HTML Element) for other functions to work.
|
|
* @param {EventObject} e The mouse down event
|
|
* @return {Object} The dragData
|
|
*/
|
|
getDragData : function(e){
|
|
return Ext.dd.Registry.getHandleFromEvent(e);
|
|
},
|
|
|
|
/**
|
|
* Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
|
|
* this.dragData.ddel
|
|
* @param {Number} x The x position of the click on the dragged object
|
|
* @param {Number} y The y position of the click on the dragged object
|
|
* @return {Boolean} true to continue the drag, false to cancel
|
|
*/
|
|
onInitDrag : function(x, y){
|
|
this.proxy.update(this.dragData.ddel.cloneNode(true));
|
|
this.onStartDrag(x, y);
|
|
return true;
|
|
},
|
|
|
|
/**
|
|
* Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
|
|
*/
|
|
afterRepair : function(){
|
|
if(Ext.enableFx){
|
|
Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
|
|
}
|
|
this.dragging = false;
|
|
},
|
|
|
|
/**
|
|
* Called before a repair of an invalid drop to get the XY to animate to. By default returns
|
|
* the XY of this.dragData.ddel
|
|
* @param {EventObject} e The mouse up event
|
|
* @return {Array} The xy location (e.g. [100, 200])
|
|
*/
|
|
getRepairXY : function(e){
|
|
return Ext.Element.fly(this.dragData.ddel).getXY();
|
|
}
|
|
});/**
|
|
* @class Ext.dd.DropZone
|
|
* @extends Ext.dd.DropTarget
|
|
* <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>
|
|
* <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
|
|
* However a simpler way to allow a DropZone to manage any number of target elements is to configure the
|
|
* DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
|
|
* mouse event to see if it has taken place within an element, or class of elements. This is easily done
|
|
* by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
|
|
* {@link Ext.DomQuery} selector.</p>
|
|
* <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
|
|
* a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
|
|
* {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
|
|
* of these methods to provide application-specific behaviour for these events to update both
|
|
* application state, and UI state.</p>
|
|
* <p>For example to make a GridPanel a cooperating target with the example illustrated in
|
|
* {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>
|
|
myGridPanel.on('render', function() {
|
|
myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
|
|
|
|
// If the mouse is over a grid row, return that node. This is
|
|
// provided as the "target" parameter in all "onNodeXXXX" node event handling functions
|
|
getTargetFromEvent: function(e) {
|
|
return e.getTarget(myGridPanel.getView().rowSelector);
|
|
},
|
|
|
|
// On entry into a target node, highlight that node.
|
|
onNodeEnter : function(target, dd, e, data){
|
|
Ext.fly(target).addClass('my-row-highlight-class');
|
|
},
|
|
|
|
// On exit from a target node, unhighlight that node.
|
|
onNodeOut : function(target, dd, e, data){
|
|
Ext.fly(target).removeClass('my-row-highlight-class');
|
|
},
|
|
|
|
// While over a target node, return the default drop allowed class which
|
|
// places a "tick" icon into the drag proxy.
|
|
onNodeOver : function(target, dd, e, data){
|
|
return Ext.dd.DropZone.prototype.dropAllowed;
|
|
},
|
|
|
|
// On node drop we can interrogate the target to find the underlying
|
|
// application object that is the real target of the dragged data.
|
|
// In this case, it is a Record in the GridPanel's Store.
|
|
// We can use the data set up by the DragZone's getDragData method to read
|
|
// any data we decided to attach in the DragZone's getDragData method.
|
|
onNodeDrop : function(target, dd, e, data){
|
|
var rowIndex = myGridPanel.getView().findRowIndex(target);
|
|
var r = myGridPanel.getStore().getAt(rowIndex);
|
|
Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
|
|
' on Record id ' + r.id);
|
|
return true;
|
|
}
|
|
});
|
|
}
|
|
</code></pre>
|
|
* See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
|
|
* cooperates with this DropZone.
|
|
* @constructor
|
|
* @param {Mixed} el The container element
|
|
* @param {Object} config
|
|
*/
|
|
Ext.dd.DropZone = function(el, config){
|
|
Ext.dd.DropZone.superclass.constructor.call(this, el, config);
|
|
};
|
|
|
|
Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {
|
|
/**
|
|
* Returns a custom data object associated with the DOM node that is the target of the event. By default
|
|
* this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
|
|
* provide your own custom lookup.
|
|
* @param {Event} e The event
|
|
* @return {Object} data The custom data
|
|
*/
|
|
getTargetFromEvent : function(e){
|
|
return Ext.dd.Registry.getTargetFromEvent(e);
|
|
},
|
|
|
|
/**
|
|
* Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
|
|
* that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
|
|
* This method has no default implementation and should be overridden to provide
|
|
* node-specific processing if necessary.
|
|
* @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
|
|
* {@link #getTargetFromEvent} for this node)
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
*/
|
|
onNodeEnter : function(n, dd, e, data){
|
|
|
|
},
|
|
|
|
/**
|
|
* Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
|
|
* that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
|
|
* The default implementation returns this.dropNotAllowed, so it should be
|
|
* overridden to provide the proper feedback.
|
|
* @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
|
|
* {@link #getTargetFromEvent} for this node)
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
onNodeOver : function(n, dd, e, data){
|
|
return this.dropAllowed;
|
|
},
|
|
|
|
/**
|
|
* Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
|
|
* the drop node without dropping. This method has no default implementation and should be overridden to provide
|
|
* node-specific processing if necessary.
|
|
* @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
|
|
* {@link #getTargetFromEvent} for this node)
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
*/
|
|
onNodeOut : function(n, dd, e, data){
|
|
|
|
},
|
|
|
|
/**
|
|
* Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
|
|
* the drop node. The default implementation returns false, so it should be overridden to provide the
|
|
* appropriate processing of the drop event and return true so that the drag source's repair action does not run.
|
|
* @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
|
|
* {@link #getTargetFromEvent} for this node)
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {Boolean} True if the drop was valid, else false
|
|
*/
|
|
onNodeDrop : function(n, dd, e, data){
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
|
|
* but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
|
|
* it should be overridden to provide the proper feedback if necessary.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
onContainerOver : function(dd, e, data){
|
|
return this.dropNotAllowed;
|
|
},
|
|
|
|
/**
|
|
* Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
|
|
* but not on any of its registered drop nodes. The default implementation returns false, so it should be
|
|
* overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
|
|
* be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {Boolean} True if the drop was valid, else false
|
|
*/
|
|
onContainerDrop : function(dd, e, data){
|
|
return false;
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
|
|
* the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
|
|
* nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
|
|
* you should override this method and provide a custom implementation.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
notifyEnter : function(dd, e, data){
|
|
return this.dropNotAllowed;
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
|
|
* This method will be called on every mouse movement while the drag source is over the drop zone.
|
|
* It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
|
|
* delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
|
|
* registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
|
|
* registered node, it will call {@link #onContainerOver}.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {String} status The CSS class that communicates the drop status back to the source so that the
|
|
* underlying {@link Ext.dd.StatusProxy} can be updated
|
|
*/
|
|
notifyOver : function(dd, e, data){
|
|
var n = this.getTargetFromEvent(e);
|
|
if(!n){ // not over valid drop target
|
|
if(this.lastOverNode){
|
|
this.onNodeOut(this.lastOverNode, dd, e, data);
|
|
this.lastOverNode = null;
|
|
}
|
|
return this.onContainerOver(dd, e, data);
|
|
}
|
|
if(this.lastOverNode != n){
|
|
if(this.lastOverNode){
|
|
this.onNodeOut(this.lastOverNode, dd, e, data);
|
|
}
|
|
this.onNodeEnter(n, dd, e, data);
|
|
this.lastOverNode = n;
|
|
}
|
|
return this.onNodeOver(n, dd, e, data);
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
|
|
* out of the zone without dropping. If the drag source is currently over a registered node, the notification
|
|
* will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag zone
|
|
*/
|
|
notifyOut : function(dd, e, data){
|
|
if(this.lastOverNode){
|
|
this.onNodeOut(this.lastOverNode, dd, e, data);
|
|
this.lastOverNode = null;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
|
|
* been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
|
|
* is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
|
|
* otherwise it will call {@link #onContainerDrop}.
|
|
* @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
|
|
* @param {Event} e The event
|
|
* @param {Object} data An object containing arbitrary data supplied by the drag source
|
|
* @return {Boolean} True if the drop was valid, else false
|
|
*/
|
|
notifyDrop : function(dd, e, data){
|
|
if(this.lastOverNode){
|
|
this.onNodeOut(this.lastOverNode, dd, e, data);
|
|
this.lastOverNode = null;
|
|
}
|
|
var n = this.getTargetFromEvent(e);
|
|
return n ?
|
|
this.onNodeDrop(n, dd, e, data) :
|
|
this.onContainerDrop(dd, e, data);
|
|
},
|
|
|
|
// private
|
|
triggerCacheRefresh : function(){
|
|
Ext.dd.DDM.refreshCache(this.groups);
|
|
}
|
|
});/**
|
|
* @class Ext.Element
|
|
*/
|
|
Ext.Element.addMethods({
|
|
/**
|
|
* Initializes a {@link Ext.dd.DD} drag drop object for this element.
|
|
* @param {String} group The group the DD object is member of
|
|
* @param {Object} config The DD config object
|
|
* @param {Object} overrides An object containing methods to override/implement on the DD object
|
|
* @return {Ext.dd.DD} The DD object
|
|
*/
|
|
initDD : function(group, config, overrides){
|
|
var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
|
|
return Ext.apply(dd, overrides);
|
|
},
|
|
|
|
/**
|
|
* Initializes a {@link Ext.dd.DDProxy} object for this element.
|
|
* @param {String} group The group the DDProxy object is member of
|
|
* @param {Object} config The DDProxy config object
|
|
* @param {Object} overrides An object containing methods to override/implement on the DDProxy object
|
|
* @return {Ext.dd.DDProxy} The DDProxy object
|
|
*/
|
|
initDDProxy : function(group, config, overrides){
|
|
var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
|
|
return Ext.apply(dd, overrides);
|
|
},
|
|
|
|
/**
|
|
* Initializes a {@link Ext.dd.DDTarget} object for this element.
|
|
* @param {String} group The group the DDTarget object is member of
|
|
* @param {Object} config The DDTarget config object
|
|
* @param {Object} overrides An object containing methods to override/implement on the DDTarget object
|
|
* @return {Ext.dd.DDTarget} The DDTarget object
|
|
*/
|
|
initDDTarget : function(group, config, overrides){
|
|
var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
|
|
return Ext.apply(dd, overrides);
|
|
}
|
|
});
|