3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 // This is a support class used internally by the Grid components
\r
16 Ext.grid.HeaderDragZone = function(grid, hd, hd2){
\r
18 this.view = grid.getView();
\r
19 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
20 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
\r
22 this.setHandleElId(Ext.id(hd));
\r
23 this.setOuterHandleElId(Ext.id(hd2));
\r
25 this.scroll = false;
\r
27 Ext.extend(Ext.grid.HeaderDragZone, Ext.dd.DragZone, {
\r
29 getDragData : function(e){
\r
30 var t = Ext.lib.Event.getTarget(e);
\r
31 var h = this.view.findHeaderCell(t);
\r
33 return {ddel: h.firstChild, header:h};
\r
38 onInitDrag : function(e){
\r
39 this.view.headersDisabled = true;
\r
40 var clone = this.dragData.ddel.cloneNode(true);
\r
41 clone.id = Ext.id();
\r
42 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
\r
43 this.proxy.update(clone);
\r
47 afterValidDrop : function(){
\r
49 setTimeout(function(){
\r
50 v.headersDisabled = false;
\r
54 afterInvalidDrop : function(){
\r
56 setTimeout(function(){
\r
57 v.headersDisabled = false;
\r
63 // This is a support class used internally by the Grid components
\r
64 Ext.grid.HeaderDropZone = function(grid, hd, hd2){
\r
66 this.view = grid.getView();
\r
67 // split the proxies so they don't interfere with mouse events
\r
68 this.proxyTop = Ext.DomHelper.append(document.body, {
\r
69 cls:"col-move-top", html:" "
\r
71 this.proxyBottom = Ext.DomHelper.append(document.body, {
\r
72 cls:"col-move-bottom", html:" "
\r
74 this.proxyTop.hide = this.proxyBottom.hide = function(){
\r
75 this.setLeftTop(-100,-100);
\r
76 this.setStyle("visibility", "hidden");
\r
78 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
79 // temporarily disabled
\r
80 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
\r
81 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
\r
83 Ext.extend(Ext.grid.HeaderDropZone, Ext.dd.DropZone, {
\r
84 proxyOffsets : [-4, -9],
\r
85 fly: Ext.Element.fly,
\r
87 getTargetFromEvent : function(e){
\r
88 var t = Ext.lib.Event.getTarget(e);
\r
89 var cindex = this.view.findCellIndex(t);
\r
90 if(cindex !== false){
\r
91 return this.view.getHeaderCell(cindex);
\r
95 nextVisible : function(h){
\r
96 var v = this.view, cm = this.grid.colModel;
\r
99 if(!cm.isHidden(v.getCellIndex(h))){
\r
107 prevVisible : function(h){
\r
108 var v = this.view, cm = this.grid.colModel;
\r
111 if(!cm.isHidden(v.getCellIndex(h))){
\r
119 positionIndicator : function(h, n, e){
\r
120 var x = Ext.lib.Event.getPageX(e);
\r
121 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
122 var px, pt, py = r.top + this.proxyOffsets[1];
\r
123 if((r.right - x) <= (r.right-r.left)/2){
\r
124 px = r.right+this.view.borderWidth;
\r
131 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
\r
135 px += this.proxyOffsets[0];
\r
136 this.proxyTop.setLeftTop(px, py);
\r
137 this.proxyTop.show();
\r
138 if(!this.bottomOffset){
\r
139 this.bottomOffset = this.view.mainHd.getHeight();
\r
141 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
\r
142 this.proxyBottom.show();
\r
146 onNodeEnter : function(n, dd, e, data){
\r
147 if(data.header != n){
\r
148 this.positionIndicator(data.header, n, e);
\r
152 onNodeOver : function(n, dd, e, data){
\r
153 var result = false;
\r
154 if(data.header != n){
\r
155 result = this.positionIndicator(data.header, n, e);
\r
158 this.proxyTop.hide();
\r
159 this.proxyBottom.hide();
\r
161 return result ? this.dropAllowed : this.dropNotAllowed;
\r
164 onNodeOut : function(n, dd, e, data){
\r
165 this.proxyTop.hide();
\r
166 this.proxyBottom.hide();
\r
169 onNodeDrop : function(n, dd, e, data){
\r
170 var h = data.header;
\r
172 var cm = this.grid.colModel;
\r
173 var x = Ext.lib.Event.getPageX(e);
\r
174 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
175 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
\r
176 var oldIndex = this.view.getCellIndex(h);
\r
177 var newIndex = this.view.getCellIndex(n);
\r
181 if(oldIndex < newIndex){
\r
184 cm.moveColumn(oldIndex, newIndex);
\r
192 Ext.grid.GridView.ColumnDragZone = function(grid, hd){
\r
193 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
\r
194 this.proxy.el.addClass('x-grid3-col-dd');
\r
197 Ext.extend(Ext.grid.GridView.ColumnDragZone, Ext.grid.HeaderDragZone, {
\r
198 handleMouseDown : function(e){
\r
202 callHandleMouseDown : function(e){
\r
203 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
\r