initial import
[roojs1] / Roo / dd / DragZone.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11
12
13 /**
14  * @class Roo.dd.DragZone
15  * @extends Roo.dd.DragSource
16  * This class provides a container DD instance that proxies for multiple child node sources.<br />
17  * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
18  * @constructor
19  * @param {String/HTMLElement/Element} el The container element
20  * @param {Object} config
21  */
22 Roo.dd.DragZone = function(el, config){
23     Roo.dd.DragZone.superclass.constructor.call(this, el, config);
24     if(this.containerScroll){
25         Roo.dd.ScrollManager.register(this.el);
26     }
27 };
28
29 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
30     /**
31      * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
32      * for auto scrolling during drag operations.
33      */
34     /**
35      * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
36      * method after a failed drop (defaults to "c3daf9" - light blue)
37      */
38
39     /**
40      * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
41      * for a valid target to drag based on the mouse down. Override this method
42      * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
43      * object has a "ddel" attribute (with an HTML Element) for other functions to work.
44      * @param {EventObject} e The mouse down event
45      * @return {Object} The dragData
46      */
47     getDragData : function(e){
48         return Roo.dd.Registry.getHandleFromEvent(e);
49     },
50     
51     /**
52      * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
53      * this.dragData.ddel
54      * @param {Number} x The x position of the click on the dragged object
55      * @param {Number} y The y position of the click on the dragged object
56      * @return {Boolean} true to continue the drag, false to cancel
57      */
58     onInitDrag : function(x, y){
59         this.proxy.update(this.dragData.ddel.cloneNode(true));
60         this.onStartDrag(x, y);
61         return true;
62     },
63     
64     /**
65      * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel 
66      */
67     afterRepair : function(){
68         if(Roo.enableFx){
69             Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
70         }
71         this.dragging = false;
72     },
73
74     /**
75      * Called before a repair of an invalid drop to get the XY to animate to. By default returns
76      * the XY of this.dragData.ddel
77      * @param {EventObject} e The mouse up event
78      * @return {Array} The xy location (e.g. [100, 200])
79      */
80     getRepairXY : function(e){
81         return Roo.Element.fly(this.dragData.ddel).getXY();  
82     }
83 });