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.Resizer'>/**
2 </span> * @class Ext.resizer.Resizer
3 * <p>Applies drag handles to an element or component to make it resizable. The
4 * drag handles are inserted into the element (or component's element) and
5 * positioned absolute.</p>
7 * <p>Textarea and img elements will be wrapped with an additional div because
8 * these elements do not support child nodes. The original element can be accessed
9 * through the originalTarget property.</p>
11 * <p>Here is the list of valid resize handles:</p>
14 ------ -------------------
25 * {@img Ext.resizer.Resizer/Ext.resizer.Resizer.png Ext.resizer.Resizer component}
26 * <p>Here's an example showing the creation of a typical Resizer:</p>
27 * <pre><code>
28 <div id="elToResize" style="width:200px; height:100px; background-color:#000000;"></div>
30 Ext.create('Ext.resizer.Resizer', {
39 </code></pre>
41 Ext.define('Ext.resizer.Resizer', {
43 observable: 'Ext.util.Observable'
45 uses: ['Ext.resizer.ResizeTracker', 'Ext.Component'],
47 alternateClassName: 'Ext.Resizable',
49 handleCls: Ext.baseCSSPrefix + 'resizable-handle',
50 pinnedCls: Ext.baseCSSPrefix + 'resizable-pinned',
51 overCls: Ext.baseCSSPrefix + 'resizable-over',
52 proxyCls: Ext.baseCSSPrefix + 'resizable-proxy',
53 wrapCls: Ext.baseCSSPrefix + 'resizable-wrap',
55 <span id='Ext-resizer.Resizer-cfg-dynamic'> /**
56 </span> * @cfg {Boolean} dynamic
57 * <p>Specify as true to update the {@link #target} (Element or {@link Ext.Component Component}) dynamically during dragging.
58 * This is <code>true</code> by default, but the {@link Ext.Component Component} class passes <code>false</code> when it
59 * is configured as {@link Ext.Component#resizable}.</p>
60 * <p>If specified as <code>false</code>, a proxy element is displayed during the resize operation, and the {@link #target}
61 * is updated on mouseup.</p>
65 <span id='Ext-resizer.Resizer-cfg-handles'> /**
66 </span> * @cfg {String} handles String consisting of the resize handles to display. Defaults to 's e se' for
67 * Elements and fixed position Components. Defaults to 8 point resizing for floating Components (such as Windows).
68 * Specify either <code>'all'</code> or any of <code>'n s e w ne nw se sw'</code>.
72 <span id='Ext-resizer.Resizer-cfg-height'> /**
73 </span> * @cfg {Number} height Optional. The height to set target to in pixels (defaults to null)
77 <span id='Ext-resizer.Resizer-cfg-width'> /**
78 </span> * @cfg {Number} width Optional. The width to set the target to in pixels (defaults to null)
82 <span id='Ext-resizer.Resizer-cfg-minHeight'> /**
83 </span> * @cfg {Number} minHeight The minimum height for the element (defaults to 20)
87 <span id='Ext-resizer.Resizer-cfg-minWidth'> /**
88 </span> * @cfg {Number} minWidth The minimum width for the element (defaults to 20)
92 <span id='Ext-resizer.Resizer-cfg-maxHeight'> /**
93 </span> * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
97 <span id='Ext-resizer.Resizer-cfg-maxWidth'> /**
98 </span> * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
102 <span id='Ext-resizer.Resizer-cfg-pinned'> /**
103 </span> * @cfg {Boolean} pinned True to ensure that the resize handles are always
104 * visible, false indicates resizing by cursor changes only (defaults to false)
108 <span id='Ext-resizer.Resizer-cfg-preserveRatio'> /**
109 </span> * @cfg {Boolean} preserveRatio True to preserve the original ratio between height
110 * and width during resize (defaults to false)
112 preserveRatio: false,
114 <span id='Ext-resizer.Resizer-cfg-transparent'> /**
115 </span> * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
119 <span id='Ext-resizer.Resizer-cfg-constrainTo'> /**
120 </span> * @cfg {Mixed} constrainTo Optional. An element, or a {@link Ext.util.Region} into which the resize operation
121 * must be constrained.
135 <span id='Ext-resizer.Resizer-cfg-target'> /**
136 </span> * @cfg {Mixed} target The Element or Component to resize.
139 <span id='Ext-resizer.Resizer-property-el'> /**
140 </span> * Outer element for resizing behavior.
141 * @type Ext.core.Element
145 constructor: function(config) {
149 handles = me.handles,
157 <span id='Ext-resizer.Resizer-event-beforeresize'> /**
158 </span> * @event beforeresize
159 * Fired before resize is allowed. Return false to cancel resize.
160 * @param {Ext.resizer.Resizer} this
161 * @param {Number} width The start width
162 * @param {Number} height The start height
163 * @param {Ext.EventObject} e The mousedown event
166 <span id='Ext-resizer.Resizer-event-resizedrag'> /**
167 </span> * @event resizedrag
168 * Fires during resizing. Return false to cancel resize.
169 * @param {Ext.resizer.Resizer} this
170 * @param {Number} width The new width
171 * @param {Number} height The new height
172 * @param {Ext.EventObject} e The mousedown event
175 <span id='Ext-resizer.Resizer-event-resize'> /**
176 </span> * @event resize
177 * Fired after a resize.
178 * @param {Ext.resizer.Resizer} this
179 * @param {Number} width The new width
180 * @param {Number} height The new height
181 * @param {Ext.EventObject} e The mouseup event
186 if (Ext.isString(config) || Ext.isElement(config) || config.dom) {
188 config = arguments[1] || {};
189 config.target = target;
191 // will apply config to this
192 me.mixins.observable.constructor.call(me, config);
194 // If target is a Component, ensure that we pull the element out.
195 // Resizer must examine the underlying Element.
198 if (target.isComponent) {
199 me.el = target.getEl();
200 if (target.minWidth) {
201 me.minWidth = target.minWidth;
203 if (target.minHeight) {
204 me.minHeight = target.minHeight;
206 if (target.maxWidth) {
207 me.maxWidth = target.maxWidth;
209 if (target.maxHeight) {
210 me.maxHeight = target.maxHeight;
212 if (target.floating) {
213 if (!this.hasOwnProperty('handles')) {
214 this.handles = 'n ne e se s sw w nw';
218 me.el = me.target = Ext.get(target);
221 // Backwards compatibility with Ext3.x's Resizable which used el as a config.
223 me.target = me.el = Ext.get(me.el);
226 // Tags like textarea and img cannot
227 // have children and therefore must
229 tag = me.el.dom.tagName;
230 if (tag == 'TEXTAREA' || tag == 'IMG') {
231 <span id='Ext-resizer.Resizer-property-originalTarget'> /**
232 </span> * Reference to the original resize target if the element of the original
233 * resize target was an IMG or a TEXTAREA which must be wrapped in a DIV.
235 * @property originalTarget
237 me.originalTarget = me.target;
238 me.target = me.el = me.el.wrap({
240 id: me.el.id + '-rzwrap'
243 // Transfer originalTarget's positioning/sizing
244 me.el.setPositioning(me.originalTarget.getPositioning());
245 me.originalTarget.clearPositioning();
246 var box = me.originalTarget.getBox();
250 // Position the element, this enables us to absolute position
251 // the handles within this.el
254 me.el.addCls(me.pinnedCls);
257 <span id='Ext-resizer.Resizer-property-resizeTracker'> /**
258 </span> * @type Ext.resizer.ResizeTracker
259 * @property resizeTracker
261 me.resizeTracker = Ext.create('Ext.resizer.ResizeTracker', {
262 disabled: me.disabled,
264 constrainTo: me.constrainTo,
266 throttle: me.throttle,
267 originalTarget: me.originalTarget,
268 delegate: '.' + me.handleCls,
270 preserveRatio: me.preserveRatio,
271 minHeight: me.minHeight,
272 maxHeight: me.maxHeight,
273 minWidth: me.minWidth,
274 maxWidth: me.maxWidth
277 // Relay the ResizeTracker's superclass events as our own resize events
278 me.resizeTracker.on('mousedown', me.onBeforeResize, me);
279 me.resizeTracker.on('drag', me.onResize, me);
280 me.resizeTracker.on('dragend', me.onResizeEnd, me);
282 if (me.handles == 'all') {
283 me.handles = 'n s e w ne nw se sw';
286 handles = me.handles = me.handles.split(/ |\s*?[,;]\s*?/);
287 possibles = me.possiblePositions;
288 len = handles.length;
289 handleCls = me.handleCls + ' ' + (this.target.isComponent ? (me.target.baseCls + '-handle ') : '') + me.handleCls + '-';
291 for(; i < len; i++){
292 // if specified and possible, create
293 if (handles[i] && possibles[handles[i]]) {
294 pos = possibles[handles[i]];
295 // store a reference in this.east, this.west, etc
297 me[pos] = Ext.create('Ext.Component', {
300 cls: handleCls + pos,
303 me[pos].el.unselectable();
304 if (me.transparent) {
305 me[pos].el.setOpacity(0);
310 // Constrain within configured maxima
311 if (Ext.isNumber(me.width)) {
312 me.width = Ext.Number.constrain(me.width, me.minWidth, me.maxWidth);
314 if (Ext.isNumber(me.height)) {
315 me.height = Ext.Number.constrain(me.height, me.minHeight, me.maxHeight);
319 if (me.width != null || me.height != null) {
320 if (me.originalTarget) {
321 me.originalTarget.setWidth(me.width);
322 me.originalTarget.setHeight(me.height);
324 me.resizeTo(me.width, me.height);
327 me.forceHandlesHeight();
330 disable: function() {
331 this.resizeTracker.disable();
335 this.resizeTracker.enable();
338 <span id='Ext-resizer.Resizer-method-onBeforeResize'> /**
339 </span> * @private Relay the Tracker's mousedown event as beforeresize
340 * @param tracker The Resizer
343 onBeforeResize: function(tracker, e) {
344 var b = this.target.getBox();
345 return this.fireEvent('beforeresize', this, b.width, b.height, e);
348 <span id='Ext-resizer.Resizer-method-onResize'> /**
349 </span> * @private Relay the Tracker's drag event as resizedrag
350 * @param tracker The Resizer
353 onResize: function(tracker, e) {
355 b = me.target.getBox();
356 me.forceHandlesHeight();
357 return me.fireEvent('resizedrag', me, b.width, b.height, e);
360 <span id='Ext-resizer.Resizer-method-onResizeEnd'> /**
361 </span> * @private Relay the Tracker's dragend event as resize
362 * @param tracker The Resizer
365 onResizeEnd: function(tracker, e) {
367 b = me.target.getBox();
368 me.forceHandlesHeight();
369 return me.fireEvent('resize', me, b.width, b.height, e);
372 <span id='Ext-resizer.Resizer-method-resizeTo'> /**
373 </span> * Perform a manual resize and fires the 'resize' event.
374 * @param {Number} width
375 * @param {Number} height
377 resizeTo : function(width, height){
378 this.target.setSize(width, height);
379 this.fireEvent('resize', this, width, height, null);
382 <span id='Ext-resizer.Resizer-method-getEl'> /**
383 </span> * <p>Returns the element that was configured with the el or target config property.
384 * If a component was configured with the target property then this will return the
385 * element of this component.<p>
386 * <p>Textarea and img elements will be wrapped with an additional div because
387 * these elements do not support child nodes. The original element can be accessed
388 * through the originalTarget property.</p>
389 * @return {Element} element
395 <span id='Ext-resizer.Resizer-method-getTarget'> /**
396 </span> * <p>Returns the element or component that was configured with the target config property.<p>
397 * <p>Textarea and img elements will be wrapped with an additional div because
398 * these elements do not support child nodes. The original element can be accessed
399 * through the originalTarget property.</p>
400 * @return {Element/Component}
402 getTarget: function() {
406 destroy: function() {
408 for (var i = 0, l = this.handles.length; i < l; i++) {
409 h = this[this.possiblePositions[this.handles[i]]];
415 <span id='Ext-resizer.Resizer-method-forceHandlesHeight'> /**
417 * Fix IE6 handle height issue.
419 forceHandlesHeight : function() {
425 handle.setHeight(me.el.getHeight());
429 handle.setHeight(me.el.getHeight());
435 </pre></pre></body></html>