4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-resizer-ResizeTracker'>/**
19 </span> * @class Ext.resizer.ResizeTracker
20 * @extends Ext.dd.DragTracker
22 Ext.define('Ext.resizer.ResizeTracker', {
23 extend: 'Ext.dd.DragTracker',
27 // Default to no constraint
30 constructor: function(config) {
34 if (config.target.isComponent) {
35 me.el = config.target.getEl();
37 me.el = config.target;
40 this.callParent(arguments);
42 // Ensure that if we are preserving aspect ratio, the largest minimum is honoured
43 if (me.preserveRatio && me.minWidth && me.minHeight) {
44 var widthRatio = me.minWidth / me.el.getWidth(),
45 heightRatio = me.minHeight / me.el.getHeight();
47 // largest ratio of minimum:size must be preserved.
48 // So if a 400x200 pixel image has
49 // minWidth: 50, maxWidth: 50, the maxWidth will be 400 * (50/200)... that is 100
50 if (heightRatio > widthRatio) {
51 me.minWidth = me.el.getWidth() * heightRatio;
53 me.minHeight = me.el.getHeight() * widthRatio;
57 // If configured as throttled, create an instance version of resize which calls
58 // a throttled function to perform the resize operation.
60 var throttledResizeFn = Ext.Function.createThrottled(function() {
61 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
64 me.resize = function(box, direction, atEnd) {
66 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
68 throttledResizeFn.apply(null, arguments);
74 onBeforeStart: function(e) {
75 // record the startBox
76 this.startBox = this.el.getBox();
79 <span id='Ext-resizer-ResizeTracker-method-getDynamicTarget'> /**
81 * Returns the object that will be resized on every mousemove event.
82 * If dynamic is false, this will be a proxy, otherwise it will be our actual target.
84 getDynamicTarget: function() {
88 } else if (!this.proxy) {
89 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());
90 this.proxy.removeCls(Ext.baseCSSPrefix + 'proxy-el');
96 onStart: function(e) {
97 // returns the Ext.ResizeHandle that the user started dragging
98 this.activeResizeHandle = Ext.getCmp(this.getDragTarget().id);
100 // If we are using a proxy, ensure it is sized.
102 this.resize(this.startBox, {
109 onDrag: function(e) {
110 // dynamic resizing, update dimensions during resize
111 if (this.dynamic || this.proxy) {
112 this.updateDimensions(e);
116 updateDimensions: function(e, atEnd) {
118 region = me.activeResizeHandle.region,
119 offset = me.getOffset(me.constrainTo ? 'dragTarget' : null),
127 horizDir = offset[0] < 0 ? 'right' : 'left',
128 vertDir = offset[1] < 0 ? 'down' : 'up',
130 axis; // 1 = x, 2 = y, 3 = x and y.
134 heightAdjust = offset[1];
138 heightAdjust = -offset[1];
139 adjustY = -heightAdjust;
143 widthAdjust = offset[0];
147 widthAdjust = -offset[0];
148 adjustX = -widthAdjust;
152 heightAdjust = -offset[1];
153 adjustY = -heightAdjust;
154 widthAdjust = offset[0];
155 oppositeCorner = [box.x, box.y + box.height];
159 heightAdjust = offset[1];
160 widthAdjust = offset[0];
161 oppositeCorner = [box.x, box.y];
165 widthAdjust = -offset[0];
166 adjustX = -widthAdjust;
167 heightAdjust = offset[1];
168 oppositeCorner = [box.x + box.width, box.y];
172 heightAdjust = -offset[1];
173 adjustY = -heightAdjust;
174 widthAdjust = -offset[0];
175 adjustX = -widthAdjust;
176 oppositeCorner = [box.x + box.width, box.y + box.height];
182 width: box.width + widthAdjust,
183 height: box.height + heightAdjust,
189 if (newBox.width < me.minWidth || newBox.width > me.maxWidth) {
190 newBox.width = Ext.Number.constrain(newBox.width, me.minWidth, me.maxWidth);
192 // Re-adjust the X position if we were dragging the west side
194 newBox.x = box.x + (box.width - newBox.width);
199 if (newBox.height < me.minHeight || newBox.height > me.maxHeight) {
200 newBox.height = Ext.Number.constrain(newBox.height, me.minHeight, me.maxHeight);
202 // Re-adjust the Y position if we were dragging the north side
204 newBox.y = box.y + (box.height - newBox.height);
210 // If this is configured to preserve the aspect ratio, or they are dragging using the shift key
211 if (me.preserveRatio || e.shiftKey) {
215 ratio = me.startBox.width / me.startBox.height;
217 // Calculate aspect ratio constrained values.
218 newHeight = Math.min(Math.max(me.minHeight, newBox.width / ratio), me.maxHeight);
219 newWidth = Math.min(Math.max(me.minWidth, newBox.height * ratio), me.maxWidth);
221 // X axis: width-only change, height must obey
223 newBox.height = newHeight;
226 // Y axis: height-only change, width must obey
227 else if (axis == 2) {
228 newBox.width = newWidth;
233 // Drag ratio is the ratio of the mouse point from the opposite corner.
234 // Basically what edge we are dragging, a horizontal edge or a vertical edge.
235 dragRatio = Math.abs(oppositeCorner[0] - this.lastXY[0]) / Math.abs(oppositeCorner[1] - this.lastXY[1]);
237 // If drag ratio > aspect ratio then width is dominant and height must obey
238 if (dragRatio > ratio) {
239 newBox.height = newHeight;
241 newBox.width = newWidth;
244 // Handle dragging start coordinates
245 if (region == 'northeast') {
246 newBox.y = box.y - (newBox.height - box.height);
247 } else if (region == 'northwest') {
248 newBox.y = box.y - (newBox.height - box.height);
249 newBox.x = box.x - (newBox.width - box.width);
250 } else if (region == 'southwest') {
251 newBox.x = box.x - (newBox.width - box.width);
256 if (heightAdjust === 0) {
259 if (widthAdjust === 0) {
263 horizontal: horizDir,
268 getResizeTarget: function(atEnd) {
269 return atEnd ? this.target : this.getDynamicTarget();
272 resize: function(box, direction, atEnd) {
273 var target = this.getResizeTarget(atEnd);
274 if (target.isComponent) {
275 if (target.floating) {
276 target.setPagePosition(box.x, box.y);
278 target.setSize(box.width, box.height);
281 // update the originalTarget if this was wrapped.
282 if (this.originalTarget) {
283 this.originalTarget.setBox(box);
289 this.updateDimensions(e, true);