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
21 * Private utility class for Ext.resizer.Resizer.
24 Ext.define('Ext.resizer.ResizeTracker', {
25 extend: 'Ext.dd.DragTracker',
29 // Default to no constraint
32 constructor: function(config) {
36 if (config.target.isComponent) {
37 me.el = config.target.getEl();
39 me.el = config.target;
42 this.callParent(arguments);
44 // Ensure that if we are preserving aspect ratio, the largest minimum is honoured
45 if (me.preserveRatio && me.minWidth && me.minHeight) {
46 var widthRatio = me.minWidth / me.el.getWidth(),
47 heightRatio = me.minHeight / me.el.getHeight();
49 // largest ratio of minimum:size must be preserved.
50 // So if a 400x200 pixel image has
51 // minWidth: 50, maxWidth: 50, the maxWidth will be 400 * (50/200)... that is 100
52 if (heightRatio > widthRatio) {
53 me.minWidth = me.el.getWidth() * heightRatio;
55 me.minHeight = me.el.getHeight() * widthRatio;
59 // If configured as throttled, create an instance version of resize which calls
60 // a throttled function to perform the resize operation.
62 var throttledResizeFn = Ext.Function.createThrottled(function() {
63 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
66 me.resize = function(box, direction, atEnd) {
68 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
70 throttledResizeFn.apply(null, arguments);
76 onBeforeStart: function(e) {
77 // record the startBox
78 this.startBox = this.el.getBox();
81 <span id='Ext-resizer-ResizeTracker-method-getDynamicTarget'> /**
83 * Returns the object that will be resized on every mousemove event.
84 * If dynamic is false, this will be a proxy, otherwise it will be our actual target.
86 getDynamicTarget: function() {
90 } else if (!this.proxy) {
91 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());
92 this.proxy.removeCls(Ext.baseCSSPrefix + 'proxy-el');
98 onStart: function(e) {
99 // returns the Ext.ResizeHandle that the user started dragging
100 this.activeResizeHandle = Ext.getCmp(this.getDragTarget().id);
102 // If we are using a proxy, ensure it is sized.
104 this.resize(this.startBox, {
111 onDrag: function(e) {
112 // dynamic resizing, update dimensions during resize
113 if (this.dynamic || this.proxy) {
114 this.updateDimensions(e);
118 updateDimensions: function(e, atEnd) {
120 region = me.activeResizeHandle.region,
121 offset = me.getOffset(me.constrainTo ? 'dragTarget' : null),
131 horizDir = offset[0] < 0 ? 'right' : 'left',
132 vertDir = offset[1] < 0 ? 'down' : 'up',
134 axis; // 1 = x, 2 = y, 3 = x and y.
138 heightAdjust = offset[1];
142 heightAdjust = -offset[1];
143 adjustY = -heightAdjust;
147 widthAdjust = offset[0];
151 widthAdjust = -offset[0];
152 adjustX = -widthAdjust;
156 heightAdjust = -offset[1];
157 adjustY = -heightAdjust;
158 widthAdjust = offset[0];
159 oppositeCorner = [box.x, box.y + box.height];
163 heightAdjust = offset[1];
164 widthAdjust = offset[0];
165 oppositeCorner = [box.x, box.y];
169 widthAdjust = -offset[0];
170 adjustX = -widthAdjust;
171 heightAdjust = offset[1];
172 oppositeCorner = [box.x + box.width, box.y];
176 heightAdjust = -offset[1];
177 adjustY = -heightAdjust;
178 widthAdjust = -offset[0];
179 adjustX = -widthAdjust;
180 oppositeCorner = [box.x + box.width, box.y + box.height];
186 width: box.width + widthAdjust,
187 height: box.height + heightAdjust,
192 // Snap value between stops according to configured increments
193 snappedWidth = Ext.Number.snap(newBox.width, me.widthIncrement);
194 snappedHeight = Ext.Number.snap(newBox.height, me.heightIncrement);
195 if (snappedWidth != newBox.width || snappedHeight != newBox.height){
198 newBox.y -= snappedHeight - newBox.height;
201 newBox.y -= snappedHeight - newBox.height;
204 newBox.x -= snappedWidth - newBox.width;
207 newBox.x -= snappedWidth - newBox.width;
210 newBox.x -= snappedWidth - newBox.width;
211 newBox.y -= snappedHeight - newBox.height;
213 newBox.width = snappedWidth;
214 newBox.height = snappedHeight;
218 if (newBox.width < me.minWidth || newBox.width > me.maxWidth) {
219 newBox.width = Ext.Number.constrain(newBox.width, me.minWidth, me.maxWidth);
221 // Re-adjust the X position if we were dragging the west side
223 newBox.x = box.x + (box.width - newBox.width);
228 if (newBox.height < me.minHeight || newBox.height > me.maxHeight) {
229 newBox.height = Ext.Number.constrain(newBox.height, me.minHeight, me.maxHeight);
231 // Re-adjust the Y position if we were dragging the north side
233 newBox.y = box.y + (box.height - newBox.height);
239 // If this is configured to preserve the aspect ratio, or they are dragging using the shift key
240 if (me.preserveRatio || e.shiftKey) {
244 ratio = me.startBox.width / me.startBox.height;
246 // Calculate aspect ratio constrained values.
247 newHeight = Math.min(Math.max(me.minHeight, newBox.width / ratio), me.maxHeight);
248 newWidth = Math.min(Math.max(me.minWidth, newBox.height * ratio), me.maxWidth);
250 // X axis: width-only change, height must obey
252 newBox.height = newHeight;
255 // Y axis: height-only change, width must obey
256 else if (axis == 2) {
257 newBox.width = newWidth;
262 // Drag ratio is the ratio of the mouse point from the opposite corner.
263 // Basically what edge we are dragging, a horizontal edge or a vertical edge.
264 dragRatio = Math.abs(oppositeCorner[0] - this.lastXY[0]) / Math.abs(oppositeCorner[1] - this.lastXY[1]);
266 // If drag ratio > aspect ratio then width is dominant and height must obey
267 if (dragRatio > ratio) {
268 newBox.height = newHeight;
270 newBox.width = newWidth;
273 // Handle dragging start coordinates
274 if (region == 'northeast') {
275 newBox.y = box.y - (newBox.height - box.height);
276 } else if (region == 'northwest') {
277 newBox.y = box.y - (newBox.height - box.height);
278 newBox.x = box.x - (newBox.width - box.width);
279 } else if (region == 'southwest') {
280 newBox.x = box.x - (newBox.width - box.width);
285 if (heightAdjust === 0) {
288 if (widthAdjust === 0) {
292 horizontal: horizDir,
297 getResizeTarget: function(atEnd) {
298 return atEnd ? this.target : this.getDynamicTarget();
301 resize: function(box, direction, atEnd) {
302 var target = this.getResizeTarget(atEnd);
303 if (target.isComponent) {
304 if (target.floating) {
305 target.setPagePosition(box.x, box.y);
307 target.setSize(box.width, box.height);
310 // update the originalTarget if this was wrapped.
311 if (this.originalTarget) {
312 this.originalTarget.setBox(box);
318 this.updateDimensions(e, true);