1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-resizer.ResizeTracker'>/**
2 </span> * @class Ext.resizer.ResizeTracker
3 * @extends Ext.dd.DragTracker
5 Ext.define('Ext.resizer.ResizeTracker', {
6 extend: 'Ext.dd.DragTracker',
10 // Default to no constraint
13 constructor: function(config) {
17 if (config.target.isComponent) {
18 me.el = config.target.getEl();
20 me.el = config.target;
23 this.callParent(arguments);
25 // Ensure that if we are preserving aspect ratio, the largest minimum is honoured
26 if (me.preserveRatio && me.minWidth && me.minHeight) {
27 var widthRatio = me.minWidth / me.el.getWidth(),
28 heightRatio = me.minHeight / me.el.getHeight();
30 // largest ratio of minimum:size must be preserved.
31 // So if a 400x200 pixel image has
32 // minWidth: 50, maxWidth: 50, the maxWidth will be 400 * (50/200)... that is 100
33 if (heightRatio > widthRatio) {
34 me.minWidth = me.el.getWidth() * heightRatio;
36 me.minHeight = me.el.getHeight() * widthRatio;
40 // If configured as throttled, create an instance version of resize which calls
41 // a throttled function to perform the resize operation.
43 var throttledResizeFn = Ext.Function.createThrottled(function() {
44 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
47 me.resize = function(box, direction, atEnd) {
49 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
51 throttledResizeFn.apply(null, arguments);
57 onBeforeStart: function(e) {
58 // record the startBox
59 this.startBox = this.el.getBox();
62 <span id='Ext-resizer.ResizeTracker-method-getDynamicTarget'> /**
64 * Returns the object that will be resized on every mousemove event.
65 * If dynamic is false, this will be a proxy, otherwise it will be our actual target.
67 getDynamicTarget: function() {
71 } else if (!this.proxy) {
72 this.proxy = d.isComponent ? d.getProxy().addCls(Ext.baseCSSPrefix + 'resizable-proxy') : d.createProxy({tag: 'div', cls: Ext.baseCSSPrefix + 'resizable-proxy', id: d.id + '-rzproxy'}, Ext.getBody());
73 this.proxy.removeCls(Ext.baseCSSPrefix + 'proxy-el');
79 onStart: function(e) {
80 // returns the Ext.ResizeHandle that the user started dragging
81 this.activeResizeHandle = Ext.getCmp(this.getDragTarget().id);
83 // If we are using a proxy, ensure it is sized.
85 this.resize(this.startBox, {
93 // dynamic resizing, update dimensions during resize
94 if (this.dynamic || this.proxy) {
95 this.updateDimensions(e);
99 updateDimensions: function(e, atEnd) {
101 region = me.activeResizeHandle.region,
102 offset = me.getOffset(me.constrainTo ? 'dragTarget' : null),
110 horizDir = offset[0] < 0 ? 'right' : 'left',
111 vertDir = offset[1] < 0 ? 'down' : 'up',
113 axis; // 1 = x, 2 = y, 3 = x and y.
117 heightAdjust = offset[1];
121 heightAdjust = -offset[1];
122 adjustY = -heightAdjust;
126 widthAdjust = offset[0];
130 widthAdjust = -offset[0];
131 adjustX = -widthAdjust;
135 heightAdjust = -offset[1];
136 adjustY = -heightAdjust;
137 widthAdjust = offset[0];
138 oppositeCorner = [box.x, box.y + box.height];
142 heightAdjust = offset[1];
143 widthAdjust = offset[0];
144 oppositeCorner = [box.x, box.y];
148 widthAdjust = -offset[0];
149 adjustX = -widthAdjust;
150 heightAdjust = offset[1];
151 oppositeCorner = [box.x + box.width, box.y];
155 heightAdjust = -offset[1];
156 adjustY = -heightAdjust;
157 widthAdjust = -offset[0];
158 adjustX = -widthAdjust;
159 oppositeCorner = [box.x + box.width, box.y + box.height];
165 width: box.width + widthAdjust,
166 height: box.height + heightAdjust,
172 if (newBox.width < me.minWidth || newBox.width > me.maxWidth) {
173 newBox.width = Ext.Number.constrain(newBox.width, me.minWidth, me.maxWidth);
174 newBox.x = me.lastX || newBox.x;
178 if (newBox.height < me.minHeight || newBox.height > me.maxHeight) {
179 newBox.height = Ext.Number.constrain(newBox.height, me.minHeight, me.maxHeight);
180 newBox.y = me.lastY || newBox.y;
185 // If this is configured to preserve the aspect ratio, or they are dragging using the shift key
186 if (me.preserveRatio || e.shiftKey) {
190 ratio = me.startBox.width / me.startBox.height;
192 // Calculate aspect ratio constrained values.
193 newHeight = Math.min(Math.max(me.minHeight, newBox.width / ratio), me.maxHeight);
194 newWidth = Math.min(Math.max(me.minWidth, newBox.height * ratio), me.maxWidth);
196 // X axis: width-only change, height must obey
198 newBox.height = newHeight;
201 // Y axis: height-only change, width must obey
202 else if (axis == 2) {
203 newBox.width = newWidth;
208 // Drag ratio is the ratio of the mouse point from the opposite corner.
209 // Basically what edge we are dragging, a horizontal edge or a vertical edge.
210 dragRatio = Math.abs(oppositeCorner[0] - this.lastXY[0]) / Math.abs(oppositeCorner[1] - this.lastXY[1]);
212 // If drag ratio > aspect ratio then width is dominant and height must obey
213 if (dragRatio > ratio) {
214 newBox.height = newHeight;
216 newBox.width = newWidth;
219 // Handle dragging start coordinates
220 if (region == 'northeast') {
221 newBox.y = box.y - (newBox.height - box.height);
222 } else if (region == 'northwest') {
223 newBox.y = box.y - (newBox.height - box.height);
224 newBox.x = box.x - (newBox.width - box.width);
225 } else if (region == 'southwest') {
226 newBox.x = box.x - (newBox.width - box.width);
231 if (heightAdjust === 0) {
234 if (widthAdjust === 0) {
238 horizontal: horizDir,
243 getResizeTarget: function(atEnd) {
244 return atEnd ? this.target : this.getDynamicTarget();
247 resize: function(box, direction, atEnd) {
248 var target = this.getResizeTarget(atEnd);
249 if (target.isComponent) {
250 if (target.floating) {
251 target.setPagePosition(box.x, box.y);
253 target.setSize(box.width, box.height);
256 // update the originalTarget if this was wrapped.
257 if (this.originalTarget) {
258 this.originalTarget.setBox(box);
264 this.updateDimensions(e, true);
270 </pre></pre></body></html>