4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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 proxyCls: Ext.baseCSSPrefix + 'resizable-proxy',
34 constructor: function(config) {
38 if (config.target.isComponent) {
39 me.el = config.target.getEl();
41 me.el = config.target;
44 this.callParent(arguments);
46 // Ensure that if we are preserving aspect ratio, the largest minimum is honoured
47 if (me.preserveRatio && me.minWidth && me.minHeight) {
48 var widthRatio = me.minWidth / me.el.getWidth(),
49 heightRatio = me.minHeight / me.el.getHeight();
51 // largest ratio of minimum:size must be preserved.
52 // So if a 400x200 pixel image has
53 // minWidth: 50, maxWidth: 50, the maxWidth will be 400 * (50/200)... that is 100
54 if (heightRatio > widthRatio) {
55 me.minWidth = me.el.getWidth() * heightRatio;
57 me.minHeight = me.el.getHeight() * widthRatio;
61 // If configured as throttled, create an instance version of resize which calls
62 // a throttled function to perform the resize operation.
64 var throttledResizeFn = Ext.Function.createThrottled(function() {
65 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
68 me.resize = function(box, direction, atEnd) {
70 Ext.resizer.ResizeTracker.prototype.resize.apply(me, arguments);
72 throttledResizeFn.apply(null, arguments);
78 onBeforeStart: function(e) {
79 // record the startBox
80 this.startBox = this.el.getBox();
83 <span id='Ext-resizer-ResizeTracker-method-getDynamicTarget'> /**
85 * Returns the object that will be resized on every mousemove event.
86 * If dynamic is false, this will be a proxy, otherwise it will be our actual target.
88 getDynamicTarget: function() {
94 } else if (!me.proxy) {
95 me.proxy = me.createProxy(target);
101 <span id='Ext-resizer-ResizeTracker-method-createProxy'> /**
102 </span> * Create a proxy for this resizer
103 * @param {Ext.Component/Ext.Element} target The target
104 * @return {Ext.Element} A proxy element
106 createProxy: function(target){
111 if (target.isComponent) {
112 proxy = target.getProxy().addCls(cls);
114 renderTo = Ext.getBody();
115 if (Ext.scopeResetCSS) {
116 renderTo = Ext.getBody().createChild({
117 cls: Ext.baseCSSPrefix + 'reset'
120 proxy = target.createProxy({
123 id: target.id + '-rzproxy'
126 proxy.removeCls(Ext.baseCSSPrefix + 'proxy-el');
130 onStart: function(e) {
131 // returns the Ext.ResizeHandle that the user started dragging
132 this.activeResizeHandle = Ext.getCmp(this.getDragTarget().id);
134 // If we are using a proxy, ensure it is sized.
136 this.resize(this.startBox, {
143 onDrag: function(e) {
144 // dynamic resizing, update dimensions during resize
145 if (this.dynamic || this.proxy) {
146 this.updateDimensions(e);
150 updateDimensions: function(e, atEnd) {
152 region = me.activeResizeHandle.region,
153 offset = me.getOffset(me.constrainTo ? 'dragTarget' : null),
163 horizDir = offset[0] < 0 ? 'right' : 'left',
164 vertDir = offset[1] < 0 ? 'down' : 'up',
166 axis; // 1 = x, 2 = y, 3 = x and y.
170 heightAdjust = offset[1];
174 heightAdjust = -offset[1];
175 adjustY = -heightAdjust;
179 widthAdjust = offset[0];
183 widthAdjust = -offset[0];
184 adjustX = -widthAdjust;
188 heightAdjust = -offset[1];
189 adjustY = -heightAdjust;
190 widthAdjust = offset[0];
191 oppositeCorner = [box.x, box.y + box.height];
195 heightAdjust = offset[1];
196 widthAdjust = offset[0];
197 oppositeCorner = [box.x, box.y];
201 widthAdjust = -offset[0];
202 adjustX = -widthAdjust;
203 heightAdjust = offset[1];
204 oppositeCorner = [box.x + box.width, box.y];
208 heightAdjust = -offset[1];
209 adjustY = -heightAdjust;
210 widthAdjust = -offset[0];
211 adjustX = -widthAdjust;
212 oppositeCorner = [box.x + box.width, box.y + box.height];
218 width: box.width + widthAdjust,
219 height: box.height + heightAdjust,
224 // Snap value between stops according to configured increments
225 snappedWidth = Ext.Number.snap(newBox.width, me.widthIncrement);
226 snappedHeight = Ext.Number.snap(newBox.height, me.heightIncrement);
227 if (snappedWidth != newBox.width || snappedHeight != newBox.height){
230 newBox.y -= snappedHeight - newBox.height;
233 newBox.y -= snappedHeight - newBox.height;
236 newBox.x -= snappedWidth - newBox.width;
239 newBox.x -= snappedWidth - newBox.width;
242 newBox.x -= snappedWidth - newBox.width;
243 newBox.y -= snappedHeight - newBox.height;
245 newBox.width = snappedWidth;
246 newBox.height = snappedHeight;
250 if (newBox.width < me.minWidth || newBox.width > me.maxWidth) {
251 newBox.width = Ext.Number.constrain(newBox.width, me.minWidth, me.maxWidth);
253 // Re-adjust the X position if we were dragging the west side
255 newBox.x = box.x + (box.width - newBox.width);
260 if (newBox.height < me.minHeight || newBox.height > me.maxHeight) {
261 newBox.height = Ext.Number.constrain(newBox.height, me.minHeight, me.maxHeight);
263 // Re-adjust the Y position if we were dragging the north side
265 newBox.y = box.y + (box.height - newBox.height);
271 // If this is configured to preserve the aspect ratio, or they are dragging using the shift key
272 if (me.preserveRatio || e.shiftKey) {
276 ratio = me.startBox.width / me.startBox.height;
278 // Calculate aspect ratio constrained values.
279 newHeight = Math.min(Math.max(me.minHeight, newBox.width / ratio), me.maxHeight);
280 newWidth = Math.min(Math.max(me.minWidth, newBox.height * ratio), me.maxWidth);
282 // X axis: width-only change, height must obey
284 newBox.height = newHeight;
287 // Y axis: height-only change, width must obey
288 else if (axis == 2) {
289 newBox.width = newWidth;
294 // Drag ratio is the ratio of the mouse point from the opposite corner.
295 // Basically what edge we are dragging, a horizontal edge or a vertical edge.
296 dragRatio = Math.abs(oppositeCorner[0] - this.lastXY[0]) / Math.abs(oppositeCorner[1] - this.lastXY[1]);
298 // If drag ratio > aspect ratio then width is dominant and height must obey
299 if (dragRatio > ratio) {
300 newBox.height = newHeight;
302 newBox.width = newWidth;
305 // Handle dragging start coordinates
306 if (region == 'northeast') {
307 newBox.y = box.y - (newBox.height - box.height);
308 } else if (region == 'northwest') {
309 newBox.y = box.y - (newBox.height - box.height);
310 newBox.x = box.x - (newBox.width - box.width);
311 } else if (region == 'southwest') {
312 newBox.x = box.x - (newBox.width - box.width);
317 if (heightAdjust === 0) {
320 if (widthAdjust === 0) {
324 horizontal: horizDir,
329 getResizeTarget: function(atEnd) {
330 return atEnd ? this.target : this.getDynamicTarget();
333 resize: function(box, direction, atEnd) {
334 var target = this.getResizeTarget(atEnd);
335 if (target.isComponent) {
336 if (target.floating) {
337 target.setPagePosition(box.x, box.y);
339 target.setSize(box.width, box.height);
342 // update the originalTarget if this was wrapped.
343 if (this.originalTarget) {
344 this.originalTarget.setBox(box);
350 this.updateDimensions(e, true);