4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
14 Roo.tree.TreeDragZone = function(tree, config){
15 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
19 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
21 scroller : false, // 't' or 'b'
24 onBeforeDrag : function(data, e){
26 return n && n.draggable && !n.disabled;
29 onDragOut : function(e, id)
33 var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragOut.call(this, e, id);
35 // if it's gone off top and bottom, start the scroller
39 if (this.scroller === false) {
40 Roo.log('start interval');
41 this.scroller = window.setInterval(
42 this.scrollAct.createDelegate(this),
47 //Roo.log(this.el.dom);
51 onDragEnter : function(e, id)
53 var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragEnter.call(this, e, id);
54 Roo.log('ondrageneter');
55 if (this.scroller !== false) {
56 Roo.log('clear scroller');
57 window.clearInterval(this.scroller);
73 if (this.scrollDir === false) {
77 this.el.scroll(this.scrollDir, 20, true);
82 onInitDrag : function(e){
83 var data = this.dragData;
84 this.tree.getSelectionModel().select(data.node);
85 this.proxy.update("");
86 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
87 this.tree.fireEvent("startdrag", this.tree, data.node, e);
90 getRepairXY : function(e, data){
91 return data.node.ui.getDDRepairXY();
94 onEndDrag : function(data, e){
95 this.tree.fireEvent("enddrag", this.tree, data.node, e);
96 if (this.scroller !== false) {
97 Roo.log('clear scroller');
98 window.clearInterval(this.scroller);
105 onValidDrop : function(dd, e, id){
106 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
110 beforeInvalidDrop : function(e, id){
111 // this scrolls the original position back into view
112 var sm = this.tree.getSelectionModel();
113 sm.clearSelections();
114 sm.select(this.dragData.node);
116 autoScroll: function(x, y, h, w) {
117 Roo.log("drop zone - autoscroll called");
119 Roo.log(this.scroll ? "scroll=y": "scroll=m" );
122 var clientH = Roo.lib.Dom.getViewWidth();
125 var clientW = Roo.lib.Dom.getViewHeight();
127 // The amt scrolled down
128 var st = this.DDM.getScrollTop();
130 // The amt scrolled right
131 var sl = this.DDM.getScrollLeft();
133 // Location of the bottom of the element
136 // Location of the right of the element
139 // The distance from the cursor to the bottom of the visible area,
140 // adjusted so that we don't scroll if the cursor is beyond the
141 // element drag constraints
142 var toBot = (clientH + st - y - this.deltaY);
144 // The distance from the cursor to the right of the visible area
145 var toRight = (clientW + sl - x - this.deltaX);
148 // How close to the edge the cursor must be before we scroll
149 // var thresh = (document.all) ? 100 : 40;
152 // How many pixels to scroll per autoscroll op. This helps to reduce
153 // clunky scrolling. IE is more sensitive about this ... it needs this
154 // value to be higher.
155 var scrAmt = (document.all) ? 80 : 30;
157 // Scroll down if we are near the bottom of the visible page and the
158 // obj extends below the crease
159 if ( bot > clientH && toBot < thresh ) {
160 window.scrollTo(sl, st + scrAmt);
163 // Scroll up if the window is scrolled down and the top of the object
164 // goes above the top border
165 if ( y < st && st > 0 && y - st < thresh ) {
166 window.scrollTo(sl, st - scrAmt);
169 // Scroll right if the obj is beyond the right border and the cursor is
171 if ( right > clientW && toRight < thresh ) {
172 window.scrollTo(sl + scrAmt, st);
175 // Scroll left if the window has been scrolled to the right and the obj
176 // extends past the left border
177 if ( x < sl && sl > 0 && x - sl < thresh ) {
178 window.scrollTo(sl - scrAmt, st);