Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / src / widgets / list / ColumnResizer.js
index e3b1531..6b9abab 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-/**\r
- * @class Ext.list.ColumnResizer\r
- * @extends Ext.util.Observable\r
- * <p>Supporting Class for Ext.list.ListView</p>\r
- * @constructor\r
- * @param {Object} config\r
- */\r
-Ext.list.ColumnResizer = Ext.extend(Ext.util.Observable, {\r
-    /**\r
-     * @cfg {Number} minPct The minimum percentage to allot for any column (defaults to <tt>.05</tt>)\r
-     */\r
-    minPct: .05,\r
-\r
-    constructor: function(config){\r
-        Ext.apply(this, config);\r
-        Ext.list.ColumnResizer.superclass.constructor.call(this);\r
-    },\r
-    init : function(listView){\r
-        this.view = listView;\r
-        listView.on('render', this.initEvents, this);\r
-    },\r
-\r
-    initEvents : function(view){\r
-        view.mon(view.innerHd, 'mousemove', this.handleHdMove, this);\r
-        this.tracker = new Ext.dd.DragTracker({\r
-            onBeforeStart: this.onBeforeStart.createDelegate(this),\r
-            onStart: this.onStart.createDelegate(this),\r
-            onDrag: this.onDrag.createDelegate(this),\r
-            onEnd: this.onEnd.createDelegate(this),\r
-            tolerance: 3,\r
-            autoStart: 300\r
-        });\r
-        this.tracker.initEl(view.innerHd);\r
-        view.on('beforedestroy', this.tracker.destroy, this.tracker);\r
-    },\r
-\r
-    handleHdMove : function(e, t){\r
-        var hw = 5,\r
-            x = e.getPageX(),\r
-            hd = e.getTarget('em', 3, true);\r
-        if(hd){\r
-            var r = hd.getRegion(),\r
-                ss = hd.dom.style,\r
-                pn = hd.dom.parentNode;\r
-\r
-            if(x - r.left <= hw && pn != pn.parentNode.firstChild){\r
-                this.activeHd = Ext.get(pn.previousSibling.firstChild);\r
-                ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';\r
-            } else if(r.right - x <= hw && pn != pn.parentNode.lastChild.previousSibling){\r
-                this.activeHd = hd;\r
-                ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';\r
-            } else{\r
-                delete this.activeHd;\r
-                ss.cursor = '';\r
-            }\r
-        }\r
-    },\r
-\r
-    onBeforeStart : function(e){\r
-        this.dragHd = this.activeHd;\r
-        return !!this.dragHd;\r
-    },\r
-\r
-    onStart: function(e){\r
-        this.view.disableHeaders = true;\r
-        this.proxy = this.view.el.createChild({cls:'x-list-resizer'});\r
-        this.proxy.setHeight(this.view.el.getHeight());\r
-\r
-        var x = this.tracker.getXY()[0],\r
-            w = this.view.innerHd.getWidth();\r
-\r
-        this.hdX = this.dragHd.getX();\r
-        this.hdIndex = this.view.findHeaderIndex(this.dragHd);\r
-\r
-        this.proxy.setX(this.hdX);\r
-        this.proxy.setWidth(x-this.hdX);\r
-\r
-        this.minWidth = w*this.minPct;\r
-        this.maxWidth = w - (this.minWidth*(this.view.columns.length-1-this.hdIndex));\r
-    },\r
-\r
-    onDrag: function(e){\r
-        var cursorX = this.tracker.getXY()[0];\r
-        this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));\r
-    },\r
-\r
-    onEnd: function(e){\r
-        /* calculate desired width by measuring proxy and then remove it */\r
-        var nw = this.proxy.getWidth();\r
-        this.proxy.remove();\r
-\r
-        var index = this.hdIndex,\r
-            vw = this.view,\r
-            cs = vw.columns,\r
-            len = cs.length,\r
-            w = this.view.innerHd.getWidth(),\r
-            minPct = this.minPct * 100,\r
-            pct = Math.ceil((nw * vw.maxWidth) / w),\r
-            diff = (cs[index].width * 100) - pct,\r
-            each = Math.floor(diff / (len-1-index)),\r
-            mod = diff - (each * (len-1-index));\r
-\r
-        for(var i = index+1; i < len; i++){\r
-            var cw = (cs[i].width * 100) + each,\r
-                ncw = Math.max(minPct, cw);\r
-            if(cw != ncw){\r
-                mod += cw - ncw;\r
-            }\r
-            cs[i].width = ncw / 100;\r
-        }\r
-        cs[index].width = pct / 100;\r
-        cs[index+1].width += (mod / 100);\r
-        delete this.dragHd;\r
-        vw.setHdWidths();\r
-        vw.refresh();\r
-        setTimeout(function(){\r
-            vw.disableHeaders = false;\r
-        }, 100);\r
-    }\r
-});\r
-\r
-// Backwards compatibility alias\r
+/**
+ * @class Ext.list.ColumnResizer
+ * @extends Ext.util.Observable
+ * <p>Supporting Class for Ext.list.ListView</p>
+ * @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 <tt>.05</tt>)
+     */
+    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 hw = 5,
+            x = e.getPageX(),
+            hd = e.getTarget('em', 3, true);
+        if(hd){
+            var r = hd.getRegion(),
+                ss = hd.dom.style,
+                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],
+            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){
+        /* calculate desired width by measuring proxy and then remove it */
+        var nw = this.proxy.getWidth();
+        this.proxy.remove();
+
+        var index = this.hdIndex,
+            vw = this.view,
+            cs = vw.columns,
+            len = cs.length,
+            w = this.view.innerHd.getWidth(),
+            minPct = this.minPct * 100,
+            pct = Math.ceil((nw * vw.maxWidth) / w),
+            diff = (cs[index].width * 100) - pct,
+            eachItem = Math.floor(diff / (len-1-index)),
+            mod = diff - (eachItem * (len-1-index));
+
+        for(var i = index+1; i < len; i++){
+            var cw = (cs[i].width * 100) + eachItem,
+                ncw = Math.max(minPct, cw);
+            if(cw != ncw){
+                mod += cw - ncw;
+            }
+            cs[i].width = ncw / 100;
+        }
+        cs[index].width = pct / 100;
+        cs[index+1].width += (mod / 100);
+        delete this.dragHd;
+        vw.setHdWidths();
+        vw.refresh();
+        setTimeout(function(){
+            vw.disableHeaders = false;
+        }, 100);
+    }
+});
+
+// Backwards compatibility alias
 Ext.ListView.ColumnResizer = Ext.list.ColumnResizer;
\ No newline at end of file