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