3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.list.ColumnResizer"></div>/**
\r
10 * @class Ext.list.ColumnResizer
\r
11 * @extends Ext.util.Observable
\r
12 * <p>Supporting Class for Ext.list.ListView</p>
\r
14 * @param {Object} config
\r
16 Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, {
\r
17 <div id="cfg-Ext.list.ColumnResizer-minPct"></div>/**
\r
18 * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)
\r
22 constructor: function(config){
\r
23 Ext.apply(this, config);
\r
24 Ext.list.ColumnResizer.superclass.constructor.call(this);
\r
26 init : function(listView){
\r
27 this.view = listView;
\r
28 listView.on('render', this.initEvents, this);
\r
31 initEvents : function(view){
\r
32 view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);
\r
33 this.tracker = new Ext.dd.DragTracker({
\r
34 onBeforeStart: this.onBeforeStart.createDelegate(this),
\r
35 onStart: this.onStart.createDelegate(this),
\r
36 onDrag: this.onDrag.createDelegate(this),
\r
37 onEnd: this.onEnd.createDelegate(this),
\r
41 this.tracker.initEl(view.innerHd);
\r
42 view.on('beforedestroy', this.tracker.destroy, this.tracker);
\r
45 handleHdMove : function(e, t){
\r
48 hd = e.getTarget('em', 3, true);
\r
50 var r = hd.getRegion(),
\r
52 pn = hd.dom.parentNode;
\r
54 if(x - r.left <= hw && pn != pn.parentNode.firstChild){
\r
55 this.activeHd = Ext.get(pn.previousSibling.firstChild);
\r
56 ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
\r
57 } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){
\r
59 ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
\r
61 delete this.activeHd;
\r
67 onBeforeStart : function(e){
\r
68 this.dragHd = this.activeHd;
\r
69 return !!this.dragHd;
\r
72 onStart: function(e){
\r
73 this.view.disableHeaders = true;
\r
74 this.proxy = this.view.el.createChild({cls:'x-list-resizer'});
\r
75 this.proxy.setHeight(this.view.el.getHeight());
\r
77 var x = this.tracker.getXY()[0],
\r
78 w = this.view.innerHd.getWidth();
\r
80 this.hdX = this.dragHd.getX();
\r
81 this.hdIndex = this.view.findHeaderIndex(this.dragHd);
\r
83 this.proxy.setX(this.hdX);
\r
84 this.proxy.setWidth(x-this.hdX);
\r
86 this.minWidth = w*this.minPct;
\r
87 this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex));
\r
90 onDrag: function(e){
\r
91 var cursorX = this.tracker.getXY()[0];
\r
92 this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
\r
96 /* calculate desired width by measuring proxy and then remove it */
\r
97 var nw = this.proxy.getWidth();
\r
98 this.proxy.remove();
\r
100 var index = this.hdIndex,
\r
104 w = this.view.innerHd.getWidth(),
\r
105 minPct = this.minPct * 100,
\r
106 pct = Math.ceil((nw * vw.maxWidth) / w),
\r
107 diff = (cs[index].width * 100) - pct,
\r
108 each = Math.floor(diff / (len-1-index)),
\r
109 mod = diff - (each * (len-1-index));
\r
111 for(var i = index+1; i < len; i++){
\r
112 var cw = (cs[i].width * 100) + each,
\r
113 ncw = Math.max(minPct, cw);
\r
117 cs[i].width = ncw / 100;
\r
119 cs[index].width = pct / 100;
\r
120 cs[index+1].width += (mod / 100);
\r
121 delete this.dragHd;
\r
124 setTimeout(function(){
\r
125 vw.disableHeaders = false;
\r
130 // Backwards compatibility alias
\r
131 Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;</pre>
\r