3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.dd.DragZone"></div>/**
16 * @class Ext.dd.DragZone
17 * @extends Ext.dd.DragSource
18 * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
19 * <p>This class does not move the drag target nodes, but a proxy element which may contain
20 * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
21 * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
22 * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
23 * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
24 * is the most efficient way to "activate" those nodes.</p>
25 * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
26 * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
27 * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
28 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
29 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
30 * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
31 * technique. Knowledge of the use of the DataView is required:</p><pre><code>
32 myDataView.on('render', function(v) {
33 myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
35 // On receipt of a mousedown event, see if it is within a DataView node.
36 // Return a drag data object if so.
37 getDragData: function(e) {
39 // Use the DataView's own itemSelector (a mandatory property) to
40 // test if the mousedown is within one of the DataView's nodes.
41 var sourceEl = e.getTarget(v.itemSelector, 10);
43 // If the mousedown is within a DataView node, clone the node to produce
44 // a ddel element for use by the drag proxy. Also add application data
45 // to the returned data object.
47 d = sourceEl.cloneNode(true);
52 repairXY: Ext.fly(sourceEl).getXY(),
54 draggedRecord: v.{@link Ext.DataView#getRecord getRecord}(sourceEl)
59 // Provide coordinates for the proxy to slide back to on failed drag.
60 // This is the original XY coordinates of the draggable element captured
61 // in the getDragData method.
62 getRepairXY: function() {
63 return this.dragData.repairXY;
67 * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
68 * cooperates with this DragZone.
70 * @param {Mixed} el The container element
71 * @param {Object} config
73 Ext.dd.DragZone = function(el, config){
74 Ext.dd.DragZone.superclass.constructor.call(this, el, config);
75 if(this.containerScroll){
76 Ext.dd.ScrollManager.register(this.el);
80 Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
81 <div id="prop-Ext.dd.DragZone-dragData"></div>/**
82 * This property contains the data representing the dragged object. This data is set up by the implementation
83 * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
84 * any other data according to the application's needs.
88 <div id="cfg-Ext.dd.DragZone-containerScroll"></div>/**
89 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
90 * for auto scrolling during drag operations.
92 <div id="cfg-Ext.dd.DragZone-hlColor"></div>/**
93 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
94 * method after a failed drop (defaults to "c3daf9" - light blue)
97 <div id="method-Ext.dd.DragZone-getDragData"></div>/**
98 * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
99 * for a valid target to drag based on the mouse down. Override this method
100 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
101 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
102 * @param {EventObject} e The mouse down event
103 * @return {Object} The dragData
105 getDragData : function(e){
106 return Ext.dd.Registry.getHandleFromEvent(e);
109 <div id="method-Ext.dd.DragZone-onInitDrag"></div>/**
110 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
112 * @param {Number} x The x position of the click on the dragged object
113 * @param {Number} y The y position of the click on the dragged object
114 * @return {Boolean} true to continue the drag, false to cancel
116 onInitDrag : function(x, y){
117 this.proxy.update(this.dragData.ddel.cloneNode(true));
118 this.onStartDrag(x, y);
122 <div id="method-Ext.dd.DragZone-afterRepair"></div>/**
123 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
125 afterRepair : function(){
127 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
129 this.dragging = false;
132 <div id="method-Ext.dd.DragZone-getRepairXY"></div>/**
133 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
134 * the XY of this.dragData.ddel
135 * @param {EventObject} e The mouse up event
136 * @return {Array} The xy location (e.g. [100, 200])
138 getRepairXY : function(e){
139 return Ext.Element.fly(this.dragData.ddel).getXY();