4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-dd-DragZone-method-constructor'><span id='Ext-dd-DragZone'>/**
19 </span></span> * @class Ext.dd.DragZone
20 * @extends Ext.dd.DragSource
21 * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
22 * <p>This class does not move the drag target nodes, but a proxy element which may contain
23 * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
24 * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
25 * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
26 * application object (For example nodes in a {@link Ext.view.View DataView}) then use of this class
27 * is the most efficient way to "activate" those nodes.</p>
28 * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
29 * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
30 * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
31 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
32 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
33 * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
34 * technique. Knowledge of the use of the DataView is required:</p><pre><code>
35 myDataView.on('render', function(v) {
36 myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
38 // On receipt of a mousedown event, see if it is within a DataView node.
39 // Return a drag data object if so.
40 getDragData: function(e) {
42 // Use the DataView's own itemSelector (a mandatory property) to
43 // test if the mousedown is within one of the DataView's nodes.
44 var sourceEl = e.getTarget(v.itemSelector, 10);
46 // If the mousedown is within a DataView node, clone the node to produce
47 // a ddel element for use by the drag proxy. Also add application data
48 // to the returned data object.
50 d = sourceEl.cloneNode(true);
55 repairXY: Ext.fly(sourceEl).getXY(),
57 draggedRecord: v.{@link Ext.view.View#getRecord getRecord}(sourceEl)
62 // Provide coordinates for the proxy to slide back to on failed drag.
63 // This is the original XY coordinates of the draggable element captured
64 // in the getDragData method.
65 getRepairXY: function() {
66 return this.dragData.repairXY;
69 });</code></pre>
70 * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
71 * cooperates with this DragZone.
73 * @param {Mixed} el The container element
74 * @param {Object} config
76 Ext.define('Ext.dd.DragZone', {
78 extend: 'Ext.dd.DragSource',
80 constructor : function(el, config){
81 this.callParent([el, config]);
82 if (this.containerScroll) {
83 Ext.dd.ScrollManager.register(this.el);
87 <span id='Ext-dd-DragZone-property-dragData'> /**
88 </span> * This property contains the data representing the dragged object. This data is set up by the implementation
89 * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
90 * any other data according to the application's needs.
95 <span id='Ext-dd-DragZone-cfg-containerScroll'> /**
96 </span> * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
97 * for auto scrolling during drag operations.
100 <span id='Ext-dd-DragZone-method-getDragData'> /**
101 </span> * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
102 * for a valid target to drag based on the mouse down. Override this method
103 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
104 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
105 * @param {EventObject} e The mouse down event
106 * @return {Object} The dragData
108 getDragData : function(e){
109 return Ext.dd.Registry.getHandleFromEvent(e);
112 <span id='Ext-dd-DragZone-method-onInitDrag'> /**
113 </span> * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
115 * @param {Number} x The x position of the click on the dragged object
116 * @param {Number} y The y position of the click on the dragged object
117 * @return {Boolean} true to continue the drag, false to cancel
119 onInitDrag : function(x, y){
120 this.proxy.update(this.dragData.ddel.cloneNode(true));
121 this.onStartDrag(x, y);
125 <span id='Ext-dd-DragZone-method-afterRepair'> /**
126 </span> * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
128 afterRepair : function(){
131 Ext.fly(me.dragData.ddel).highlight(me.repairHighlightColor);
136 <span id='Ext-dd-DragZone-method-getRepairXY'> /**
137 </span> * Called before a repair of an invalid drop to get the XY to animate to. By default returns
138 * the XY of this.dragData.ddel
139 * @param {EventObject} e The mouse up event
140 * @return {Array} The xy location (e.g. [100, 200])
142 getRepairXY : function(e){
143 return Ext.core.Element.fly(this.dragData.ddel).getXY();
146 destroy : function(){
148 if (this.containerScroll) {
149 Ext.dd.ScrollManager.unregister(this.el);