source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/list/ColumnResizer.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 3.9 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/**
8 * @class Ext.ListView.ColumnResizer
9 * @extends Ext.util.Observable
10 * <p>Supporting Class for Ext.ListView.</p>
11 * @constructor
12 * @param {Object} config
13 */
14Ext.ListView.ColumnResizer = Ext.extend(Ext.util.Observable, {
15    /**
16     * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)
17     */
18    minPct: .05,
19
20    constructor: function(config){
21        Ext.apply(this, config);
22        Ext.ListView.ColumnResizer.superclass.constructor.call(this);
23    },
24    init : function(listView){
25        this.view = listView;
26        listView.on('render', this.initEvents, this);
27    },
28
29    initEvents : function(view){
30        view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);
31        this.tracker = new Ext.dd.DragTracker({
32            onBeforeStart: this.onBeforeStart.createDelegate(this),
33            onStart: this.onStart.createDelegate(this),
34            onDrag: this.onDrag.createDelegate(this),
35            onEnd: this.onEnd.createDelegate(this),
36            tolerance: 3,
37            autoStart: 300
38        });
39        this.tracker.initEl(view.innerHd);
40        view.on('beforedestroy', this.tracker.destroy, this.tracker);
41    },
42
43    handleHdMove : function(e, t){
44        var hw = 5;
45        var x = e.getPageX();
46        var hd = e.getTarget('em', 3, true);
47        if(hd){
48            var r = hd.getRegion();
49            var ss = hd.dom.style;
50            var pn = hd.dom.parentNode;
51
52            if(x - r.left <= hw && pn != pn.parentNode.firstChild){
53                this.activeHd = Ext.get(pn.previousSibling.firstChild);
54                                ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
55            } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){
56                this.activeHd = hd;
57                                ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
58            } else{
59                delete this.activeHd;
60                ss.cursor = '';
61            }
62        }
63    },
64
65    onBeforeStart : function(e){
66        this.dragHd = this.activeHd;
67        return !!this.dragHd;
68    },
69
70    onStart: function(e){
71        this.view.disableHeaders = true;
72        this.proxy = this.view.el.createChild({cls:'x-list-resizer'});
73        this.proxy.setHeight(this.view.el.getHeight());
74
75        var x = this.tracker.getXY()[0];
76        var w = this.view.innerHd.getWidth();
77
78        this.hdX = this.dragHd.getX();
79        this.hdIndex = this.view.findHeaderIndex(this.dragHd);
80
81        this.proxy.setX(this.hdX);
82        this.proxy.setWidth(x-this.hdX);
83
84        this.minWidth = w*this.minPct;
85        this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex));
86    },
87
88    onDrag: function(e){
89        var cursorX = this.tracker.getXY()[0];
90        this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
91    },
92
93    onEnd: function(e){
94        var nw = this.proxy.getWidth();
95        this.proxy.remove();
96
97        var index = this.hdIndex;
98        var vw = this.view, cs = vw.columns, len = cs.length;
99        var w = this.view.innerHd.getWidth(), minPct = this.minPct * 100;
100
101        var pct = Math.ceil((nw*100) / w);
102        var diff = cs[index].width - pct;
103        var each = Math.floor(diff / (len-1-index));
104        var mod = diff - (each * (len-1-index));
105
106        for(var i = index+1; i < len; i++){
107            var cw = cs[i].width + each;
108            var ncw = Math.max(minPct, cw);
109            if(cw != ncw){
110                mod += cw - ncw;
111            }
112            cs[i].width = ncw;
113        }
114        cs[index].width = pct;
115        cs[index+1].width += mod;
116        delete this.dragHd;
117        this.view.setHdWidths();
118        this.view.refresh();
119        setTimeout(function(){
120            vw.disableHeaders = false;
121        }, 100);
122    }
123});
Note: See TracBrowser for help on using the repository browser.