68dfda8c7ab7f703389357d2488d461e7c2d6317
[roojs1] / Roo / tree / TreeDragZone.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 if(Roo.dd.DragZone){
14 Roo.tree.TreeDragZone = function(tree, config){
15     Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
16     this.tree = tree;
17 };
18
19 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
20     ddGroup : "TreeDD",
21    
22     onBeforeDrag : function(data, e){
23         var n = data.node;
24         return n && n.draggable && !n.disabled;
25     },
26      
27     
28     onInitDrag : function(e){
29         var data = this.dragData;
30         this.tree.getSelectionModel().select(data.node);
31         this.proxy.update("");
32         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
33         this.tree.fireEvent("startdrag", this.tree, data.node, e);
34     },
35     
36     getRepairXY : function(e, data){
37         return data.node.ui.getDDRepairXY();
38     },
39     
40     onEndDrag : function(data, e){
41         this.tree.fireEvent("enddrag", this.tree, data.node, e);
42         
43         
44     },
45     
46     onValidDrop : function(dd, e, id){
47         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
48         this.hideProxy();
49     },
50     
51     beforeInvalidDrop : function(e, id){
52         // this scrolls the original position back into view
53         var sm = this.tree.getSelectionModel();
54         sm.clearSelections();
55         sm.select(this.dragData.node);
56     },
57     autoScroll: function(x, y, h, w) {
58         Roo.log("drop zone - autoscroll called");
59         
60         Roo.log( [ x, y, h , w, this.scroll ] );
61         Roo.log(this.el.getBox());
62          Roo.log(this.el.getScroll());
63         if (this.scroll) {
64             
65             var box = this.el.getBox();
66             var scroll = this.el.getScroll();
67             
68              // The client height
69             var clientH = box.height;
70
71             // The client width
72             var clientW = box.width;
73
74             // The amt scrolled down
75             var st = scroll.top;
76
77             // The amt scrolled right
78             var sl = scroll.left;
79
80             // Location of the bottom of the element
81             var bot = h + y;
82
83             // Location of the right of the element
84             var right = w + x;
85
86             // The distance from the cursor to the bottom of the visible area,
87             // adjusted so that we don't scroll if the cursor is beyond the
88             // element drag constraints
89             var toBot = (clientH + st - y - this.deltaY);
90
91             // The distance from the cursor to the right of the visible area
92             var toRight = (clientW + sl - x - this.deltaX);
93
94
95             // How close to the edge the cursor must be before we scroll
96             // var thresh = (document.all) ? 100 : 40;
97             var thresh = 40;
98
99             // How many pixels to scroll per autoscroll op.  This helps to reduce
100             // clunky scrolling. IE is more sensitive about this ... it needs this
101             // value to be higher.
102             var scrAmt = 80; //(document.all) ? 80 : 30;
103
104             // Scroll down if we are near the bottom of the visible page and the
105             // obj extends below the crease
106             if ( bot > clientH && toBot < thresh ) {
107                 this.el.scroll('d', scrAmt);
108             }
109
110             // Scroll up if the window is scrolled down and the top of the object
111             // goes above the top border
112             if ( y < st && st > 0 && y - st < thresh ) {
113                 this.el.scroll('t', scrAmt);
114             }
115
116             // Scroll right if the obj is beyond the right border and the cursor is
117             // near the border.
118             if ( right > clientW && toRight < thresh ) {
119                 this.el.scroll('r', scrAmt);
120             }
121
122             // Scroll left if the window has been scrolled to the right and the obj
123             // extends past the left border
124             if ( x < sl && sl > 0 && x - sl < thresh ) {
125                 this.el.scroll('l', scrAmt);
126             }
127         }
128     }
129 });
130 }