3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.list.ColumnResizer"></div>/**
16 * @class Ext.list.ColumnResizer
17 * @extends Ext.util.Observable
18 * <p>Supporting Class for Ext.list.ListView</p>
20 * @param {Object} config
22 Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, {
23 <div id="cfg-Ext.list.ColumnResizer-minPct"></div>/**
24 * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)
28 constructor: function(config){
29 Ext.apply(this, config);
30 Ext.list.ColumnResizer.superclass.constructor.call(this);
32 init : function(listView){
34 listView.on('render', this.initEvents, this);
37 initEvents : function(view){
38 view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);
39 this.tracker = new Ext.dd.DragTracker({
40 onBeforeStart: this.onBeforeStart.createDelegate(this),
41 onStart: this.onStart.createDelegate(this),
42 onDrag: this.onDrag.createDelegate(this),
43 onEnd: this.onEnd.createDelegate(this),
47 this.tracker.initEl(view.innerHd);
48 view.on('beforedestroy', this.tracker.destroy, this.tracker);
51 handleHdMove : function(e, t){
54 header = e.getTarget('em', 3, true);
56 var region = header.getRegion(),
57 style = header.dom.style,
58 parentNode = header.dom.parentNode;
60 if(x - region.left <= handleWidth && parentNode != parentNode.parentNode.firstChild){
61 this.activeHd = Ext.get(parentNode.previousSibling.firstChild);
62 style.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
63 } else if(region.right - x <= handleWidth && parentNode != parentNode.parentNode.lastChild.previousSibling){
64 this.activeHd = header;
65 style.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
73 onBeforeStart : function(e){
74 this.dragHd = this.activeHd;
82 dragHeader = me.dragHd,
83 x = me.tracker.getXY()[0];
85 me.proxy = view.el.createChild({cls:'x-list-resizer'});
86 me.dragX = dragHeader.getX();
87 me.headerIndex = view.findHeaderIndex(dragHeader);
89 me.headersDisabled = view.disableHeaders;
90 view.disableHeaders = true;
92 me.proxy.setHeight(view.el.getHeight());
93 me.proxy.setX(me.dragX);
94 me.proxy.setWidth(x - me.dragX);
100 // Sets up the boundaries for the drag/drop operation
101 setBoundaries: function(relativeX){
102 var view = this.view,
103 headerIndex = this.headerIndex,
104 width = view.innerHd.getWidth(),
105 relativeX = view.innerHd.getX(),
106 minWidth = Math.ceil(width * this.minPct),
107 maxWidth = width - minWidth,
108 numColumns = view.columns.length,
109 headers = view.innerHd.select('em', true),
110 minX = minWidth + relativeX,
111 maxX = maxWidth + relativeX,
114 if (numColumns == 2) {
118 header = headers.item(headerIndex + 2);
119 this.minX = headers.item(headerIndex).getX() + minWidth;
120 this.maxX = header ? header.getX() - minWidth : maxX;
121 if (headerIndex == 0) {
124 } else if (headerIndex == numColumns - 2) {
133 cursorX = me.tracker.getXY()[0].constrain(me.minX, me.maxX);
135 me.proxy.setWidth(cursorX - this.dragX);
139 /* calculate desired width by measuring proxy and then remove it */
140 var newWidth = this.proxy.getWidth(),
141 index = this.headerIndex,
143 columns = view.columns,
144 width = view.innerHd.getWidth(),
145 newPercent = Math.ceil(newWidth * view.maxColumnWidth / width) / 100,
146 disabled = this.headersDisabled,
147 headerCol = columns[index],
148 otherCol = columns[index + 1],
149 totalPercent = headerCol.width + otherCol.width;
153 headerCol.width = newPercent;
154 otherCol.width = totalPercent - newPercent;
160 setTimeout(function(){
161 view.disableHeaders = disabled;
166 // Backwards compatibility alias
167 Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;</pre>