4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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'>/**
19 </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 Ext.define('Ext.dd.DragZone', {
75 extend: 'Ext.dd.DragSource',
77 <span id='Ext-dd-DragZone-method-constructor'> /**
78 </span> * Creates new DragZone.
79 * @param {String/HTMLElement/Ext.Element} el The container element or ID of it.
80 * @param {Object} config
82 constructor : function(el, config){
83 this.callParent([el, config]);
84 if (this.containerScroll) {
85 Ext.dd.ScrollManager.register(this.el);
89 <span id='Ext-dd-DragZone-property-dragData'> /**
90 </span> * This property contains the data representing the dragged object. This data is set up by the implementation
91 * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
92 * any other data according to the application's needs.
97 <span id='Ext-dd-DragZone-cfg-containerScroll'> /**
98 </span> * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
99 * for auto scrolling during drag operations.
102 <span id='Ext-dd-DragZone-method-getDragData'> /**
103 </span> * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
104 * for a valid target to drag based on the mouse down. Override this method
105 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
106 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
107 * @param {Event} e The mouse down event
108 * @return {Object} The dragData
110 getDragData : function(e){
111 return Ext.dd.Registry.getHandleFromEvent(e);
114 <span id='Ext-dd-DragZone-method-onInitDrag'> /**
115 </span> * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
117 * @param {Number} x The x position of the click on the dragged object
118 * @param {Number} y The y position of the click on the dragged object
119 * @return {Boolean} true to continue the drag, false to cancel
121 onInitDrag : function(x, y){
122 this.proxy.update(this.dragData.ddel.cloneNode(true));
123 this.onStartDrag(x, y);
127 <span id='Ext-dd-DragZone-method-afterRepair'> /**
128 </span> * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
130 afterRepair : function(){
133 Ext.fly(me.dragData.ddel).highlight(me.repairHighlightColor);
138 <span id='Ext-dd-DragZone-method-getRepairXY'> /**
139 </span> * Called before a repair of an invalid drop to get the XY to animate to. By default returns
140 * the XY of this.dragData.ddel
141 * @param {Event} e The mouse up event
142 * @return {Number[]} The xy location (e.g. [100, 200])
144 getRepairXY : function(e){
145 return Ext.Element.fly(this.dragData.ddel).getXY();
148 destroy : function(){
150 if (this.containerScroll) {
151 Ext.dd.ScrollManager.unregister(this.el);