DragZone.html
6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-dd-DragZone'>/**
</span> * This class provides a container DD instance that allows dragging of multiple child source nodes.
*
* 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}
*
* 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.view.View DataView}) then use of this class is the most efficient way to
* "activate" those nodes.
*
* 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:
*
* 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.view.View#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;
* }
* });
* });
*
* See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which cooperates with
* this DragZone.
*/
Ext.define('Ext.dd.DragZone', {
extend: 'Ext.dd.DragSource',
<span id='Ext-dd-DragZone-method-constructor'> /**
</span> * Creates new DragZone.
* @param {String/HTMLElement/Ext.Element} el The container element or ID of it.
* @param {Object} config
*/
constructor : function(el, config){
this.callParent([el, config]);
if (this.containerScroll) {
Ext.dd.ScrollManager.register(this.el);
}
},
<span id='Ext-dd-DragZone-property-dragData'> /**
</span> * @property {Object} dragData
* 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 ddel property, but can contain any other data according to the
* application's needs.
*/
<span id='Ext-dd-DragZone-cfg-containerScroll'> /**
</span> * @cfg {Boolean} containerScroll
* True to register this container with the Scrollmanager for auto scrolling during drag operations.
*/
<span id='Ext-dd-DragZone-method-getDragData'> /**
</span> * 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 {Event} e The mouse down event
* @return {Object} The dragData
*/
getDragData : function(e){
return Ext.dd.Registry.getHandleFromEvent(e);
},
<span id='Ext-dd-DragZone-method-onInitDrag'> /**
</span> * 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
* @template
*/
onInitDrag : function(x, y){
this.proxy.update(this.dragData.ddel.cloneNode(true));
this.onStartDrag(x, y);
return true;
},
<span id='Ext-dd-DragZone-method-afterRepair'> /**
</span> * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
* @template
*/
afterRepair : function(){
var me = this;
if (Ext.enableFx) {
Ext.fly(me.dragData.ddel).highlight(me.repairHighlightColor);
}
me.dragging = false;
},
<span id='Ext-dd-DragZone-method-getRepairXY'> /**
</span> * 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 {Event} e The mouse up event
* @return {Number[]} The xy location (e.g. `[100, 200]`)
* @template
*/
getRepairXY : function(e){
return Ext.fly(this.dragData.ddel).getXY();
},
destroy : function(){
this.callParent();
if (this.containerScroll) {
Ext.dd.ScrollManager.unregister(this.el);
}
}
});
</pre>
</body>
</html>