X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..e9397f91ede62d446aed37d23256e8938fc4c335:/docs/source/ColumnResizer.html diff --git a/docs/source/ColumnResizer.html b/docs/source/ColumnResizer.html index 94552fc3..f55dbf73 100644 --- a/docs/source/ColumnResizer.html +++ b/docs/source/ColumnResizer.html @@ -1,126 +1,169 @@ - - - The source code - - - - -
/** - * @class Ext.ListView.ColumnResizer - * @extends Ext.util.Observable - *

Supporting Class for Ext.ListView.

- * @constructor - * @param {Object} config - */ -Ext.ListView.ColumnResizer = Ext.extend(Ext.util.Observable, { -
/** - * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to .05) - */ - minPct: .05, - - constructor: function(config){ - Ext.apply(this, config); - Ext.ListView.ColumnResizer.superclass.constructor.call(this); - }, - init : function(listView){ - this.view = listView; - listView.on('render', this.initEvents, this); - }, - - initEvents : function(view){ - view.mon(view.innerHd, 'mousemove', this.handleHdMove, this); - this.tracker = new Ext.dd.DragTracker({ - onBeforeStart: this.onBeforeStart.createDelegate(this), - onStart: this.onStart.createDelegate(this), - onDrag: this.onDrag.createDelegate(this), - onEnd: this.onEnd.createDelegate(this), - tolerance: 3, - autoStart: 300 - }); - this.tracker.initEl(view.innerHd); - view.on('beforedestroy', this.tracker.destroy, this.tracker); - }, - - handleHdMove : function(e, t){ - var hw = 5; - var x = e.getPageX(); - var hd = e.getTarget('em', 3, true); - if(hd){ - var r = hd.getRegion(); - var ss = hd.dom.style; - var pn = hd.dom.parentNode; - - if(x - r.left <= hw && pn != pn.parentNode.firstChild){ - this.activeHd = Ext.get(pn.previousSibling.firstChild); - ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize'; - } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){ - this.activeHd = hd; - ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize'; - } else{ - delete this.activeHd; - ss.cursor = ''; - } - } - }, - - onBeforeStart : function(e){ - this.dragHd = this.activeHd; - return !!this.dragHd; - }, - - onStart: function(e){ - this.view.disableHeaders = true; - this.proxy = this.view.el.createChild({cls:'x-list-resizer'}); - this.proxy.setHeight(this.view.el.getHeight()); - - var x = this.tracker.getXY()[0]; - var w = this.view.innerHd.getWidth(); - - this.hdX = this.dragHd.getX(); - this.hdIndex = this.view.findHeaderIndex(this.dragHd); - - this.proxy.setX(this.hdX); - this.proxy.setWidth(x-this.hdX); - - this.minWidth = w*this.minPct; - this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex)); - }, - - onDrag: function(e){ - var cursorX = this.tracker.getXY()[0]; - this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth)); - }, - - onEnd: function(e){ - var nw = this.proxy.getWidth(); - this.proxy.remove(); - - var index = this.hdIndex; - var vw = this.view, cs = vw.columns, len = cs.length; - var w = this.view.innerHd.getWidth(), minPct = this.minPct * 100; - - var pct = Math.ceil((nw*100) / w); - var diff = cs[index].width - pct; - var each = Math.floor(diff / (len-1-index)); - var mod = diff - (each * (len-1-index)); - - for(var i = index+1; i < len; i++){ - var cw = cs[i].width + each; - var ncw = Math.max(minPct, cw); - if(cw != ncw){ - mod += cw - ncw; - } - cs[i].width = ncw; - } - cs[index].width = pct; - cs[index+1].width += mod; - delete this.dragHd; - this.view.setHdWidths(); - this.view.refresh(); - setTimeout(function(){ - vw.disableHeaders = false; - }, 100); - } -});
- + + + + The source code + + + + +
/*!
+ * Ext JS Library 3.3.1
+ * Copyright(c) 2006-2010 Sencha Inc.
+ * licensing@sencha.com
+ * http://www.sencha.com/license
+ */
+
/** + * @class Ext.list.ColumnResizer + * @extends Ext.util.Observable + *

Supporting Class for Ext.list.ListView

+ * @constructor + * @param {Object} config + */ +Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, { +
/** + * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to .05) + */ + minPct: .05, + + constructor: function(config){ + Ext.apply(this, config); + Ext.list.ColumnResizer.superclass.constructor.call(this); + }, + init : function(listView){ + this.view = listView; + listView.on('render', this.initEvents, this); + }, + + initEvents : function(view){ + view.mon(view.innerHd, 'mousemove', this.handleHdMove, this); + this.tracker = new Ext.dd.DragTracker({ + onBeforeStart: this.onBeforeStart.createDelegate(this), + onStart: this.onStart.createDelegate(this), + onDrag: this.onDrag.createDelegate(this), + onEnd: this.onEnd.createDelegate(this), + tolerance: 3, + autoStart: 300 + }); + this.tracker.initEl(view.innerHd); + view.on('beforedestroy', this.tracker.destroy, this.tracker); + }, + + handleHdMove : function(e, t){ + var handleWidth = 5, + x = e.getPageX(), + header = e.getTarget('em', 3, true); + if(header){ + var region = header.getRegion(), + style = header.dom.style, + parentNode = header.dom.parentNode; + + if(x - region.left <= handleWidth && parentNode != parentNode.parentNode.firstChild){ + this.activeHd = Ext.get(parentNode.previousSibling.firstChild); + style.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize'; + } else if(region.right - x <= handleWidth && parentNode != parentNode.parentNode.lastChild.previousSibling){ + this.activeHd = header; + style.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize'; + } else{ + delete this.activeHd; + style.cursor = ''; + } + } + }, + + onBeforeStart : function(e){ + this.dragHd = this.activeHd; + return !!this.dragHd; + }, + + onStart: function(e){ + + var me = this, + view = me.view, + dragHeader = me.dragHd, + x = me.tracker.getXY()[0]; + + me.proxy = view.el.createChild({cls:'x-list-resizer'}); + me.dragX = dragHeader.getX(); + me.headerIndex = view.findHeaderIndex(dragHeader); + + me.headersDisabled = view.disableHeaders; + view.disableHeaders = true; + + me.proxy.setHeight(view.el.getHeight()); + me.proxy.setX(me.dragX); + me.proxy.setWidth(x - me.dragX); + + this.setBoundaries(); + + }, + + // Sets up the boundaries for the drag/drop operation + setBoundaries: function(relativeX){ + var view = this.view, + headerIndex = this.headerIndex, + width = view.innerHd.getWidth(), + relativeX = view.innerHd.getX(), + minWidth = Math.ceil(width * this.minPct), + maxWidth = width - minWidth, + numColumns = view.columns.length, + headers = view.innerHd.select('em', true), + minX = minWidth + relativeX, + maxX = maxWidth + relativeX, + header; + + if (numColumns == 2) { + this.minX = minX; + this.maxX = maxX; + }else{ + header = headers.item(headerIndex + 2); + this.minX = headers.item(headerIndex).getX() + minWidth; + this.maxX = header ? header.getX() - minWidth : maxX; + if (headerIndex == 0) { + // First + this.minX = minX; + } else if (headerIndex == numColumns - 2) { + // Last + this.maxX = maxX; + } + } + }, + + onDrag: function(e){ + var me = this, + cursorX = me.tracker.getXY()[0].constrain(me.minX, me.maxX); + + me.proxy.setWidth(cursorX - this.dragX); + }, + + onEnd: function(e){ + /* calculate desired width by measuring proxy and then remove it */ + var newWidth = this.proxy.getWidth(), + index = this.headerIndex, + view = this.view, + columns = view.columns, + width = view.innerHd.getWidth(), + newPercent = Math.ceil(newWidth * view.maxColumnWidth / width) / 100, + disabled = this.headersDisabled, + headerCol = columns[index], + otherCol = columns[index + 1], + totalPercent = headerCol.width + otherCol.width; + + this.proxy.remove(); + + headerCol.width = newPercent; + otherCol.width = totalPercent - newPercent; + + delete this.dragHd; + view.setHdWidths(); + view.refresh(); + + setTimeout(function(){ + view.disableHeaders = disabled; + }, 100); + } +}); + +// Backwards compatibility alias +Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;
+ \ No newline at end of file