3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.Resizable"></div>/**
16 * @class Ext.Resizable
17 * @extends Ext.util.Observable
18 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
19 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
20 * the textarea in a div and set 'resizeChild' to true (or to the id of the element), <b>or</b> set wrap:true in your config and
21 * the element will be wrapped for you automatically.</p>
22 * <p>Here is the list of valid resize handles:</p>
25 ------ -------------------
36 * <p>Here's an example showing the creation of a typical Resizable:</p>
38 var resizer = new Ext.Resizable('element-id', {
46 resizer.on('resize', myHandler);
48 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
49 * resizer.east.setDisplayed(false);</p>
51 * Create a new resizable component
52 * @param {Mixed} el The id or element to resize
53 * @param {Object} config configuration options
55 Ext.Resizable = Ext.extend(Ext.util.Observable, {
57 constructor: function(el, config){
58 this.el = Ext.get(el);
59 if(config && config.wrap){
60 config.resizeChild = this.el;
61 this.el = this.el.wrap(typeof config.wrap == 'object' ? config.wrap : {cls:'xresizable-wrap'});
62 this.el.id = this.el.dom.id = config.resizeChild.id + '-rzwrap';
63 this.el.setStyle('overflow', 'hidden');
64 this.el.setPositioning(config.resizeChild.getPositioning());
65 config.resizeChild.clearPositioning();
66 if(!config.width || !config.height){
67 var csize = config.resizeChild.getSize();
68 this.el.setSize(csize.width, csize.height);
70 if(config.pinned && !config.adjustments){
71 config.adjustments = 'auto';
75 <div id="prop-Ext.Resizable-proxy"></div>/**
76 * The proxy Element that is resized in place of the real Element during the resize operation.
77 * This may be queried using {@link Ext.Element#getBox} to provide the new area to resize to.
82 this.proxy = this.el.createProxy({tag: 'div', cls: 'x-resizable-proxy', id: this.el.id + '-rzproxy'}, Ext.getBody());
83 this.proxy.unselectable();
84 this.proxy.enableDisplayMode('block');
86 Ext.apply(this, config);
89 this.disableTrackOver = true;
90 this.el.addClass('x-resizable-pinned');
92 // if the element isn't positioned, make it relative
93 var position = this.el.getStyle('position');
94 if(position != 'absolute' && position != 'fixed'){
95 this.el.setStyle('position', 'relative');
97 if(!this.handles){ // no handles passed, must be legacy style
98 this.handles = 's,e,se';
99 if(this.multiDirectional){
100 this.handles += ',n,w';
103 if(this.handles == 'all'){
104 this.handles = 'n s e w ne nw se sw';
106 var hs = this.handles.split(/\s*?[,;]\s*?| /);
107 var ps = Ext.Resizable.positions;
108 for(var i = 0, len = hs.length; i < len; i++){
109 if(hs[i] && ps[hs[i]]){
111 this[pos] = new Ext.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent, this.handleCls);
115 this.corner = this.southeast;
117 if(this.handles.indexOf('n') != -1 || this.handles.indexOf('w') != -1){
118 this.updateBox = true;
121 this.activeHandle = null;
123 if(this.resizeChild){
124 if(typeof this.resizeChild == 'boolean'){
125 this.resizeChild = Ext.get(this.el.dom.firstChild, true);
127 this.resizeChild = Ext.get(this.resizeChild, true);
131 if(this.adjustments == 'auto'){
132 var rc = this.resizeChild;
133 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
134 if(rc && (hw || hn)){
135 rc.position('relative');
136 rc.setLeft(hw ? hw.el.getWidth() : 0);
137 rc.setTop(hn ? hn.el.getHeight() : 0);
140 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
141 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
146 this.dd = this.dynamic ?
147 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
148 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
149 if(this.constrainTo){
150 this.dd.constrainTo(this.constrainTo);
155 <div id="event-Ext.Resizable-beforeresize"></div>/**
156 * @event beforeresize
157 * Fired before resize is allowed. Set {@link #enabled} to false to cancel resize.
158 * @param {Ext.Resizable} this
159 * @param {Ext.EventObject} e The mousedown event
162 <div id="event-Ext.Resizable-resize"></div>/**
164 * Fired after a resize.
165 * @param {Ext.Resizable} this
166 * @param {Number} width The new width
167 * @param {Number} height The new height
168 * @param {Ext.EventObject} e The mouseup event
173 if(this.width !== null && this.height !== null){
174 this.resizeTo(this.width, this.height);
176 this.updateChildSize();
179 this.el.dom.style.zoom = 1;
181 Ext.Resizable.superclass.constructor.call(this);
184 <div id="cfg-Ext.Resizable-adjustments"></div>/**
185 * @cfg {Array/String} adjustments String 'auto' or an array [width, height] with values to be <b>added</b> to the
186 * resize operation's new size (defaults to <tt>[0, 0]</tt>)
188 adjustments : [0, 0],
189 <div id="cfg-Ext.Resizable-animate"></div>/**
190 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
193 <div id="cfg-Ext.Resizable-constrainTo"></div>/**
194 * @cfg {Mixed} constrainTo Constrain the resize to a particular element
196 <div id="cfg-Ext.Resizable-disableTrackOver"></div>/**
197 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
199 disableTrackOver : false,
200 <div id="cfg-Ext.Resizable-draggable"></div>/**
201 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
204 <div id="cfg-Ext.Resizable-duration"></div>/**
205 * @cfg {Number} duration Animation duration if animate = true (defaults to 0.35)
208 <div id="cfg-Ext.Resizable-dynamic"></div>/**
209 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
212 <div id="cfg-Ext.Resizable-easing"></div>/**
213 * @cfg {String} easing Animation easing if animate = true (defaults to <tt>'easingOutStrong'</tt>)
215 easing : 'easeOutStrong',
216 <div id="cfg-Ext.Resizable-enabled"></div>/**
217 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
220 <div id="prop-Ext.Resizable-enabled"></div>/**
221 * @property enabled Writable. False if resizing is disabled.
224 <div id="cfg-Ext.Resizable-handles"></div>/**
225 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined).
226 * Specify either <tt>'all'</tt> or any of <tt>'n s e w ne nw se sw'</tt>.
229 <div id="cfg-Ext.Resizable-multiDirectional"></div>/**
230 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. Deprecated style of adding multi-direction resize handles.
232 multiDirectional : false,
233 <div id="cfg-Ext.Resizable-height"></div>/**
234 * @cfg {Number} height The height of the element in pixels (defaults to null)
237 <div id="cfg-Ext.Resizable-width"></div>/**
238 * @cfg {Number} width The width of the element in pixels (defaults to null)
241 <div id="cfg-Ext.Resizable-heightIncrement"></div>/**
242 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels
243 * (only applies if <code>{@link #dynamic}==true</code>). Defaults to <tt>0</tt>.
246 <div id="cfg-Ext.Resizable-widthIncrement"></div>/**
247 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels
248 * (only applies if <code>{@link #dynamic}==true</code>). Defaults to <tt>0</tt>.
251 <div id="cfg-Ext.Resizable-minHeight"></div>/**
252 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
255 <div id="cfg-Ext.Resizable-minWidth"></div>/**
256 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
259 <div id="cfg-Ext.Resizable-maxHeight"></div>/**
260 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
263 <div id="cfg-Ext.Resizable-maxWidth"></div>/**
264 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
267 <div id="cfg-Ext.Resizable-minX"></div>/**
268 * @cfg {Number} minX The minimum x for the element (defaults to 0)
271 <div id="cfg-Ext.Resizable-minY"></div>/**
272 * @cfg {Number} minY The minimum x for the element (defaults to 0)
275 <div id="cfg-Ext.Resizable-pinned"></div>/**
276 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
277 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
280 <div id="cfg-Ext.Resizable-preserveRatio"></div>/**
281 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height
282 * and width during resize (defaults to false)
284 preserveRatio : false,
285 <div id="cfg-Ext.Resizable-resizeChild"></div>/**
286 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
289 <div id="cfg-Ext.Resizable-transparent"></div>/**
290 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
293 <div id="cfg-Ext.Resizable-resizeRegion"></div>/**
294 * @cfg {Ext.lib.Region} resizeRegion Constrain the resize to a particular region
296 <div id="cfg-Ext.Resizable-wrap"></div>/**
297 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
298 * in favor of the handles config option (defaults to false)
300 <div id="cfg-Ext.Resizable-handleCls"></div>/**
301 * @cfg {String} handleCls A css class to add to each handle. Defaults to <tt>''</tt>.
305 <div id="method-Ext.Resizable-resizeTo"></div>/**
306 * Perform a manual resize and fires the 'resize' event.
307 * @param {Number} width
308 * @param {Number} height
310 resizeTo : function(width, height){
311 this.el.setSize(width, height);
312 this.updateChildSize();
313 this.fireEvent('resize', this, width, height, null);
317 startSizing : function(e, handle){
318 this.fireEvent('beforeresize', this, e);
319 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
322 this.overlay = this.el.createProxy({tag: 'div', cls: 'x-resizable-overlay', html: ' '}, Ext.getBody());
323 this.overlay.unselectable();
324 this.overlay.enableDisplayMode('block');
327 mousemove: this.onMouseMove,
328 mouseup: this.onMouseUp
331 this.overlay.setStyle('cursor', handle.el.getStyle('cursor'));
333 this.resizing = true;
334 this.startBox = this.el.getBox();
335 this.startPoint = e.getXY();
336 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
337 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
339 this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
342 if(this.constrainTo) {
343 var ct = Ext.get(this.constrainTo);
344 this.resizeRegion = ct.getRegion().adjust(
345 ct.getFrameWidth('t'),
346 ct.getFrameWidth('l'),
347 -ct.getFrameWidth('b'),
348 -ct.getFrameWidth('r')
352 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
354 this.proxy.setBox(this.startBox);
356 this.proxy.setStyle('visibility', 'visible');
362 onMouseDown : function(handle, e){
365 this.activeHandle = handle;
366 this.startSizing(e, handle);
371 onMouseUp : function(e){
372 this.activeHandle = null;
373 var size = this.resizeElement();
374 this.resizing = false;
378 this.fireEvent('resize', this, size.width, size.height, e);
382 updateChildSize : function(){
383 if(this.resizeChild){
385 var child = this.resizeChild;
386 var adj = this.adjustments;
387 if(el.dom.offsetWidth){
388 var b = el.getSize(true);
389 child.setSize(b.width+adj[0], b.height+adj[1]);
391 // Second call here for IE
392 // The first call enables instant resizing and
393 // the second call corrects scroll bars if they
396 setTimeout(function(){
397 if(el.dom.offsetWidth){
398 var b = el.getSize(true);
399 child.setSize(b.width+adj[0], b.height+adj[1]);
407 snap : function(value, inc, min){
411 var newValue = value;
415 newValue = value + (inc-m);
417 newValue = value - m;
420 return Math.max(min, newValue);
423 <div id="method-Ext.Resizable-resizeElement"></div>/**
424 * <p>Performs resizing of the associated Element. This method is called internally by this
425 * class, and should not be called by user code.</p>
426 * <p>If a Resizable is being used to resize an Element which encapsulates a more complex UI
427 * component such as a Panel, this method may be overridden by specifying an implementation
428 * as a config option to provide appropriate behaviour at the end of the resize operation on
429 * mouseup, for example resizing the Panel, and relaying the Panel's content.</p>
430 * <p>The new area to be resized to is available by examining the state of the {@link #proxy}
437 renderTo: Ext.getBody(),
443 render: function(p) {
444 new Ext.Resizable(p.getEl(), {
448 resizeElement: function() {
449 var box = this.proxy.getBox();
462 resizeElement : function(){
463 var box = this.proxy.getBox();
465 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
467 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
469 this.updateChildSize();
473 if(this.draggable && this.constrainTo){
474 this.dd.resetConstraints();
475 this.dd.constrainTo(this.constrainTo);
481 constrain : function(v, diff, m, mx){
484 }else if(v - diff > mx){
491 onMouseMove : function(e){
492 if(this.enabled && this.activeHandle){
493 try{// try catch so if something goes wrong the user doesn't get hung
495 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
499 //var curXY = this.startPoint;
500 var curSize = this.curSize || this.startBox,
501 x = this.startBox.x, y = this.startBox.y,
511 mxh = this.maxHeight,
512 wi = this.widthIncrement,
513 hi = this.heightIncrement,
515 diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0])),
516 diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1])),
517 pos = this.activeHandle.position,
524 w = Math.min(Math.max(mw, w), mxw);
528 h = Math.min(Math.max(mh, h), mxh);
533 w = Math.min(Math.max(mw, w), mxw);
534 h = Math.min(Math.max(mh, h), mxh);
537 diffY = this.constrain(h, diffY, mh, mxh);
542 diffX = this.constrain(w, diffX, mw, mxw);
548 w = Math.min(Math.max(mw, w), mxw);
549 diffY = this.constrain(h, diffY, mh, mxh);
554 diffX = this.constrain(w, diffX, mw, mxw);
555 diffY = this.constrain(h, diffY, mh, mxh);
562 diffX = this.constrain(w, diffX, mw, mxw);
564 h = Math.min(Math.max(mh, h), mxh);
570 var sw = this.snap(w, wi, mw);
571 var sh = this.snap(h, hi, mh);
572 if(sw != w || sh != h){
595 if(this.preserveRatio){
600 h = Math.min(Math.max(mh, h), mxh);
605 w = Math.min(Math.max(mw, w), mxw);
610 w = Math.min(Math.max(mw, w), mxw);
616 w = Math.min(Math.max(mw, w), mxw);
622 h = Math.min(Math.max(mh, h), mxh);
630 h = Math.min(Math.max(mh, h), mxh);
640 h = Math.min(Math.max(mh, h), mxh);
648 this.proxy.setBounds(x, y, w, h);
650 this.resizeElement();
657 handleOver : function(){
659 this.el.addClass('x-resizable-over');
664 handleOut : function(){
666 this.el.removeClass('x-resizable-over');
670 <div id="method-Ext.Resizable-getEl"></div>/**
671 * Returns the element this component is bound to.
672 * @return {Ext.Element}
678 <div id="method-Ext.Resizable-getResizeChild"></div>/**
679 * Returns the resizeChild element (or null).
680 * @return {Ext.Element}
682 getResizeChild : function(){
683 return this.resizeChild;
686 <div id="method-Ext.Resizable-destroy"></div>/**
687 * Destroys this resizable. If the element was wrapped and
688 * removeEl is not true then the element remains.
689 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
691 destroy : function(removeEl){
692 Ext.destroy(this.dd, this.overlay, this.proxy);
696 var ps = Ext.Resizable.positions;
698 if(typeof ps[k] != 'function' && this[ps[k]]){
699 this[ps[k]].destroy();
704 Ext.destroy(this.el);
707 this.purgeListeners();
710 syncHandleHeight : function(){
711 var h = this.el.getHeight(true);
713 this.west.el.setHeight(h);
716 this.east.el.setHeight(h);
722 // hash to map config positions to true positions
723 Ext.Resizable.positions = {
724 n: 'north', s: 'south', e: 'east', w: 'west', se: 'southeast', sw: 'southwest', nw: 'northwest', ne: 'northeast'
727 Ext.Resizable.Handle = Ext.extend(Object, {
728 constructor : function(rz, pos, disableTrackOver, transparent, cls){
730 // only initialize the template if resizable is used
731 var tpl = Ext.DomHelper.createTemplate(
732 {tag: 'div', cls: 'x-resizable-handle x-resizable-handle-{0}'}
735 Ext.Resizable.Handle.prototype.tpl = tpl;
739 this.el = this.tpl.append(rz.el.dom, [this.position], true);
740 this.el.unselectable();
742 this.el.setOpacity(0);
744 if(!Ext.isEmpty(cls)){
745 this.el.addClass(cls);
747 this.el.on('mousedown', this.onMouseDown, this);
748 if(!disableTrackOver){
751 mouseover: this.onMouseOver,
752 mouseout: this.onMouseOut
758 afterResize : function(rz){
762 onMouseDown : function(e){
763 this.rz.onMouseDown(this, e);
766 onMouseOver : function(e){
767 this.rz.handleOver(this, e);
770 onMouseOut : function(e){
771 this.rz.handleOut(this, e);
774 destroy : function(){
775 Ext.destroy(this.el);