Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / widgets / Resizable.js
1 /*!
2  * Ext JS Library 3.1.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.Resizable\r
9  * @extends Ext.util.Observable\r
10  * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element \r
11  * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap\r
12  * 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
13  * the element will be wrapped for you automatically.</p>\r
14  * <p>Here is the list of valid resize handles:</p>\r
15  * <pre>\r
16 Value   Description\r
17 ------  -------------------\r
18  'n'     north\r
19  's'     south\r
20  'e'     east\r
21  'w'     west\r
22  'nw'    northwest\r
23  'sw'    southwest\r
24  'se'    southeast\r
25  'ne'    northeast\r
26  'all'   all\r
27 </pre>\r
28  * <p>Here's an example showing the creation of a typical Resizable:</p>\r
29  * <pre><code>\r
30 var resizer = new Ext.Resizable('element-id', {\r
31     handles: 'all',\r
32     minWidth: 200,\r
33     minHeight: 100,\r
34     maxWidth: 500,\r
35     maxHeight: 400,\r
36     pinned: true\r
37 });\r
38 resizer.on('resize', myHandler);\r
39 </code></pre>\r
40  * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>\r
41  * resizer.east.setDisplayed(false);</p>\r
42  * @constructor\r
43  * Create a new resizable component\r
44  * @param {Mixed} el The id or element to resize\r
45  * @param {Object} config configuration options\r
46   */\r
47 Ext.Resizable = function(el, config){\r
48     this.el = Ext.get(el);\r
49     \r
50     if(config && config.wrap){\r
51         config.resizeChild = this.el;\r
52         this.el = this.el.wrap(typeof config.wrap == 'object' ? config.wrap : {cls:'xresizable-wrap'});\r
53         this.el.id = this.el.dom.id = config.resizeChild.id + '-rzwrap';\r
54         this.el.setStyle('overflow', 'hidden');\r
55         this.el.setPositioning(config.resizeChild.getPositioning());\r
56         config.resizeChild.clearPositioning();\r
57         if(!config.width || !config.height){\r
58             var csize = config.resizeChild.getSize();\r
59             this.el.setSize(csize.width, csize.height);\r
60         }\r
61         if(config.pinned && !config.adjustments){\r
62             config.adjustments = 'auto';\r
63         }\r
64     }\r
65 \r
66     /**\r
67      * The proxy Element that is resized in place of the real Element during the resize operation.\r
68      * This may be queried using {@link Ext.Element#getBox} to provide the new area to resize to.\r
69      * Read only.\r
70      * @type Ext.Element.\r
71      * @property proxy\r
72      */\r
73     this.proxy = this.el.createProxy({tag: 'div', cls: 'x-resizable-proxy', id: this.el.id + '-rzproxy'}, Ext.getBody());\r
74     this.proxy.unselectable();\r
75     this.proxy.enableDisplayMode('block');\r
76 \r
77     Ext.apply(this, config);\r
78     \r
79     if(this.pinned){\r
80         this.disableTrackOver = true;\r
81         this.el.addClass('x-resizable-pinned');\r
82     }\r
83     // if the element isn't positioned, make it relative\r
84     var position = this.el.getStyle('position');\r
85     if(position != 'absolute' && position != 'fixed'){\r
86         this.el.setStyle('position', 'relative');\r
87     }\r
88     if(!this.handles){ // no handles passed, must be legacy style\r
89         this.handles = 's,e,se';\r
90         if(this.multiDirectional){\r
91             this.handles += ',n,w';\r
92         }\r
93     }\r
94     if(this.handles == 'all'){\r
95         this.handles = 'n s e w ne nw se sw';\r
96     }\r
97     var hs = this.handles.split(/\s*?[,;]\s*?| /);\r
98     var ps = Ext.Resizable.positions;\r
99     for(var i = 0, len = hs.length; i < len; i++){\r
100         if(hs[i] && ps[hs[i]]){\r
101             var pos = ps[hs[i]];\r
102             this[pos] = new Ext.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);\r
103         }\r
104     }\r
105     // legacy\r
106     this.corner = this.southeast;\r
107     \r
108     if(this.handles.indexOf('n') != -1 || this.handles.indexOf('w') != -1){\r
109         this.updateBox = true;\r
110     }   \r
111    \r
112     this.activeHandle = null;\r
113     \r
114     if(this.resizeChild){\r
115         if(typeof this.resizeChild == 'boolean'){\r
116             this.resizeChild = Ext.get(this.el.dom.firstChild, true);\r
117         }else{\r
118             this.resizeChild = Ext.get(this.resizeChild, true);\r
119         }\r
120     }\r
121     \r
122     if(this.adjustments == 'auto'){\r
123         var rc = this.resizeChild;\r
124         var hw = this.west, he = this.east, hn = this.north, hs = this.south;\r
125         if(rc && (hw || hn)){\r
126             rc.position('relative');\r
127             rc.setLeft(hw ? hw.el.getWidth() : 0);\r
128             rc.setTop(hn ? hn.el.getHeight() : 0);\r
129         }\r
130         this.adjustments = [\r
131             (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),\r
132             (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1 \r
133         ];\r
134     }\r
135     \r
136     if(this.draggable){\r
137         this.dd = this.dynamic ? \r
138             this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});\r
139         this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);\r
140         if(this.constrainTo){\r
141             this.dd.constrainTo(this.constrainTo);\r
142         }\r
143     }\r
144     \r
145     this.addEvents(\r
146         /**\r
147          * @event beforeresize\r
148          * Fired before resize is allowed. Set {@link #enabled} to false to cancel resize.\r
149          * @param {Ext.Resizable} this\r
150          * @param {Ext.EventObject} e The mousedown event\r
151          */\r
152         'beforeresize',\r
153         /**\r
154          * @event resize\r
155          * Fired after a resize.\r
156          * @param {Ext.Resizable} this\r
157          * @param {Number} width The new width\r
158          * @param {Number} height The new height\r
159          * @param {Ext.EventObject} e The mouseup event\r
160          */\r
161         'resize'\r
162     );\r
163     \r
164     if(this.width !== null && this.height !== null){\r
165         this.resizeTo(this.width, this.height);\r
166     }else{\r
167         this.updateChildSize();\r
168     }\r
169     if(Ext.isIE){\r
170         this.el.dom.style.zoom = 1;\r
171     }\r
172     Ext.Resizable.superclass.constructor.call(this);\r
173 };\r
174 \r
175 Ext.extend(Ext.Resizable, Ext.util.Observable, {\r
176 \r
177     /**\r
178      * @cfg {Array/String} adjustments String 'auto' or an array [width, height] with values to be <b>added</b> to the\r
179      * resize operation's new size (defaults to <tt>[0, 0]</tt>)\r
180      */\r
181     adjustments : [0, 0],\r
182     /**\r
183      * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)\r
184      */\r
185     animate : false,\r
186     /**\r
187      * @cfg {Mixed} constrainTo Constrain the resize to a particular element\r
188      */\r
189     /**\r
190      * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)\r
191      */\r
192     disableTrackOver : false,\r
193     /**\r
194      * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)\r
195      */\r
196     draggable: false,\r
197     /**\r
198      * @cfg {Number} duration Animation duration if animate = true (defaults to 0.35)\r
199      */\r
200     duration : 0.35,\r
201     /**\r
202      * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)\r
203      */\r
204     dynamic : false,\r
205     /**\r
206      * @cfg {String} easing Animation easing if animate = true (defaults to <tt>'easingOutStrong'</tt>)\r
207      */\r
208     easing : 'easeOutStrong',\r
209     /**\r
210      * @cfg {Boolean} enabled False to disable resizing (defaults to true)\r
211      */\r
212     enabled : true,\r
213     /**\r
214      * @property enabled Writable. False if resizing is disabled.\r
215      * @type Boolean \r
216      */\r
217     /**\r
218      * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined).\r
219      * Specify either <tt>'all'</tt> or any of <tt>'n s e w ne nw se sw'</tt>.\r
220      */\r
221     handles : false,\r
222     /**\r
223      * @cfg {Boolean} multiDirectional <b>Deprecated</b>.  Deprecated style of adding multi-direction resize handles.\r
224      */\r
225     multiDirectional : false,\r
226     /**\r
227      * @cfg {Number} height The height of the element in pixels (defaults to null)\r
228      */\r
229     height : null,\r
230     /**\r
231      * @cfg {Number} width The width of the element in pixels (defaults to null)\r
232      */\r
233     width : null,\r
234     /**\r
235      * @cfg {Number} heightIncrement The increment to snap the height resize in pixels\r
236      * (only applies if <code>{@link #dynamic}==true</code>). Defaults to <tt>0</tt>.\r
237      */\r
238     heightIncrement : 0,\r
239     /**\r
240      * @cfg {Number} widthIncrement The increment to snap the width resize in pixels\r
241      * (only applies if <code>{@link #dynamic}==true</code>). Defaults to <tt>0</tt>.\r
242      */\r
243     widthIncrement : 0,\r
244     /**\r
245      * @cfg {Number} minHeight The minimum height for the element (defaults to 5)\r
246      */\r
247     minHeight : 5,\r
248     /**\r
249      * @cfg {Number} minWidth The minimum width for the element (defaults to 5)\r
250      */\r
251     minWidth : 5,\r
252     /**\r
253      * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)\r
254      */\r
255     maxHeight : 10000,\r
256     /**\r
257      * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)\r
258      */\r
259     maxWidth : 10000,\r
260     /**\r
261      * @cfg {Number} minX The minimum x for the element (defaults to 0)\r
262      */\r
263     minX: 0,\r
264     /**\r
265      * @cfg {Number} minY The minimum x for the element (defaults to 0)\r
266      */\r
267     minY: 0,\r
268     /**\r
269      * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the\r
270      * user mouses over the resizable borders. This is only applied at config time. (defaults to false)\r
271      */\r
272     pinned : false,\r
273     /**\r
274      * @cfg {Boolean} preserveRatio True to preserve the original ratio between height\r
275      * and width during resize (defaults to false)\r
276      */\r
277     preserveRatio : false,\r
278     /**\r
279      * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false) \r
280      */ \r
281     resizeChild : false,\r
282     /**\r
283      * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)\r
284      */\r
285     transparent: false,\r
286     /**\r
287      * @cfg {Ext.lib.Region} resizeRegion Constrain the resize to a particular region\r
288      */\r
289     /**\r
290      * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)\r
291      * in favor of the handles config option (defaults to false)\r
292      */\r
293 \r
294     \r
295     /**\r
296      * Perform a manual resize and fires the 'resize' event.\r
297      * @param {Number} width\r
298      * @param {Number} height\r
299      */\r
300     resizeTo : function(width, height){\r
301         this.el.setSize(width, height);\r
302         this.updateChildSize();\r
303         this.fireEvent('resize', this, width, height, null);\r
304     },\r
305 \r
306     // private\r
307     startSizing : function(e, handle){\r
308         this.fireEvent('beforeresize', this, e);\r
309         if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler\r
310 \r
311             if(!this.overlay){\r
312                 this.overlay = this.el.createProxy({tag: 'div', cls: 'x-resizable-overlay', html: '&#160;'}, Ext.getBody());\r
313                 this.overlay.unselectable();\r
314                 this.overlay.enableDisplayMode('block');\r
315                 this.overlay.on({\r
316                     scope: this,\r
317                     mousemove: this.onMouseMove,\r
318                     mouseup: this.onMouseUp\r
319                 });\r
320             }\r
321             this.overlay.setStyle('cursor', handle.el.getStyle('cursor'));\r
322 \r
323             this.resizing = true;\r
324             this.startBox = this.el.getBox();\r
325             this.startPoint = e.getXY();\r
326             this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],\r
327                             (this.startBox.y + this.startBox.height) - this.startPoint[1]];\r
328 \r
329             this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));\r
330             this.overlay.show();\r
331 \r
332             if(this.constrainTo) {\r
333                 var ct = Ext.get(this.constrainTo);\r
334                 this.resizeRegion = ct.getRegion().adjust(\r
335                     ct.getFrameWidth('t'),\r
336                     ct.getFrameWidth('l'),\r
337                     -ct.getFrameWidth('b'),\r
338                     -ct.getFrameWidth('r')\r
339                 );\r
340             }\r
341 \r
342             this.proxy.setStyle('visibility', 'hidden'); // workaround display none\r
343             this.proxy.show();\r
344             this.proxy.setBox(this.startBox);\r
345             if(!this.dynamic){\r
346                 this.proxy.setStyle('visibility', 'visible');\r
347             }\r
348         }\r
349     },\r
350 \r
351     // private\r
352     onMouseDown : function(handle, e){\r
353         if(this.enabled){\r
354             e.stopEvent();\r
355             this.activeHandle = handle;\r
356             this.startSizing(e, handle);\r
357         }          \r
358     },\r
359 \r
360     // private\r
361     onMouseUp : function(e){\r
362         this.activeHandle = null;\r
363         var size = this.resizeElement();\r
364         this.resizing = false;\r
365         this.handleOut();\r
366         this.overlay.hide();\r
367         this.proxy.hide();\r
368         this.fireEvent('resize', this, size.width, size.height, e);\r
369     },\r
370 \r
371     // private\r
372     updateChildSize : function(){\r
373         if(this.resizeChild){\r
374             var el = this.el;\r
375             var child = this.resizeChild;\r
376             var adj = this.adjustments;\r
377             if(el.dom.offsetWidth){\r
378                 var b = el.getSize(true);\r
379                 child.setSize(b.width+adj[0], b.height+adj[1]);\r
380             }\r
381             // Second call here for IE\r
382             // The first call enables instant resizing and\r
383             // the second call corrects scroll bars if they\r
384             // exist\r
385             if(Ext.isIE){\r
386                 setTimeout(function(){\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
390                     }\r
391                 }, 10);\r
392             }\r
393         }\r
394     },\r
395 \r
396     // private\r
397     snap : function(value, inc, min){\r
398         if(!inc || !value){\r
399             return value;\r
400         }\r
401         var newValue = value;\r
402         var m = value % inc;\r
403         if(m > 0){\r
404             if(m > (inc/2)){\r
405                 newValue = value + (inc-m);\r
406             }else{\r
407                 newValue = value - m;\r
408             }\r
409         }\r
410         return Math.max(min, newValue);\r
411     },\r
412 \r
413     /**\r
414      * <p>Performs resizing of the associated Element. This method is called internally by this\r
415      * class, and should not be called by user code.</p>\r
416      * <p>If a Resizable is being used to resize an Element which encapsulates a more complex UI\r
417      * component such as a Panel, this method may be overridden by specifying an implementation\r
418      * as a config option to provide appropriate behaviour at the end of the resize operation on\r
419      * mouseup, for example resizing the Panel, and relaying the Panel's content.</p>\r
420      * <p>The new area to be resized to is available by examining the state of the {@link #proxy}\r
421      * Element. Example:\r
422 <pre><code>\r
423 new Ext.Panel({\r
424     title: 'Resize me',\r
425     x: 100,\r
426     y: 100,\r
427     renderTo: Ext.getBody(),\r
428     floating: true,\r
429     frame: true,\r
430     width: 400,\r
431     height: 200,\r
432     listeners: {\r
433         render: function(p) {\r
434             new Ext.Resizable(p.getEl(), {\r
435                 handles: 'all',\r
436                 pinned: true,\r
437                 transparent: true,\r
438                 resizeElement: function() {\r
439                     var box = this.proxy.getBox();\r
440                     p.updateBox(box);\r
441                     if (p.layout) {\r
442                         p.doLayout();\r
443                     }\r
444                     return box;\r
445                 }\r
446            });\r
447        }\r
448     }\r
449 }).show();\r
450 </code></pre>\r
451      */\r
452     resizeElement : function(){\r
453         var box = this.proxy.getBox();\r
454         if(this.updateBox){\r
455             this.el.setBox(box, false, this.animate, this.duration, null, this.easing);\r
456         }else{\r
457             this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);\r
458         }\r
459         this.updateChildSize();\r
460         if(!this.dynamic){\r
461             this.proxy.hide();\r
462         }\r
463         if(this.draggable && this.constrainTo){\r
464             this.dd.resetConstraints();\r
465             this.dd.constrainTo(this.constrainTo);\r
466         }\r
467         return box;\r
468     },\r
469 \r
470     // private\r
471     constrain : function(v, diff, m, mx){\r
472         if(v - diff < m){\r
473             diff = v - m;    \r
474         }else if(v - diff > mx){\r
475             diff = v - mx; \r
476         }\r
477         return diff;                \r
478     },\r
479 \r
480     // private\r
481     onMouseMove : function(e){\r
482         if(this.enabled && this.activeHandle){\r
483             try{// try catch so if something goes wrong the user doesn't get hung\r
484 \r
485             if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {\r
486                 return;\r
487             }\r
488 \r
489             //var curXY = this.startPoint;\r
490             var curSize = this.curSize || this.startBox,\r
491                 x = this.startBox.x, y = this.startBox.y,\r
492                 ox = x, \r
493                 oy = y,\r
494                 w = curSize.width, \r
495                 h = curSize.height,\r
496                 ow = w, \r
497                 oh = h,\r
498                 mw = this.minWidth, \r
499                 mh = this.minHeight,\r
500                 mxw = this.maxWidth, \r
501                 mxh = this.maxHeight,\r
502                 wi = this.widthIncrement,\r
503                 hi = this.heightIncrement,\r
504                 eventXY = e.getXY(),\r
505                 diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0])),\r
506                 diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1])),\r
507                 pos = this.activeHandle.position,\r
508                 tw,\r
509                 th;\r
510             \r
511             switch(pos){\r
512                 case 'east':\r
513                     w += diffX; \r
514                     w = Math.min(Math.max(mw, w), mxw);\r
515                     break;\r
516                 case 'south':\r
517                     h += diffY;\r
518                     h = Math.min(Math.max(mh, h), mxh);\r
519                     break;\r
520                 case 'southeast':\r
521                     w += diffX; \r
522                     h += diffY;\r
523                     w = Math.min(Math.max(mw, w), mxw);\r
524                     h = Math.min(Math.max(mh, h), mxh);\r
525                     break;\r
526                 case 'north':\r
527                     diffY = this.constrain(h, diffY, mh, mxh);\r
528                     y += diffY;\r
529                     h -= diffY;\r
530                     break;\r
531                 case 'west':\r
532                     diffX = this.constrain(w, diffX, mw, mxw);\r
533                     x += diffX;\r
534                     w -= diffX;\r
535                     break;\r
536                 case 'northeast':\r
537                     w += diffX; \r
538                     w = Math.min(Math.max(mw, w), mxw);\r
539                     diffY = this.constrain(h, diffY, mh, mxh);\r
540                     y += diffY;\r
541                     h -= diffY;\r
542                     break;\r
543                 case 'northwest':\r
544                     diffX = this.constrain(w, diffX, mw, mxw);\r
545                     diffY = this.constrain(h, diffY, mh, mxh);\r
546                     y += diffY;\r
547                     h -= diffY;\r
548                     x += diffX;\r
549                     w -= diffX;\r
550                     break;\r
551                case 'southwest':\r
552                     diffX = this.constrain(w, diffX, mw, mxw);\r
553                     h += diffY;\r
554                     h = Math.min(Math.max(mh, h), mxh);\r
555                     x += diffX;\r
556                     w -= diffX;\r
557                     break;\r
558             }\r
559             \r
560             var sw = this.snap(w, wi, mw);\r
561             var sh = this.snap(h, hi, mh);\r
562             if(sw != w || sh != h){\r
563                 switch(pos){\r
564                     case 'northeast':\r
565                         y -= sh - h;\r
566                     break;\r
567                     case 'north':\r
568                         y -= sh - h;\r
569                         break;\r
570                     case 'southwest':\r
571                         x -= sw - w;\r
572                     break;\r
573                     case 'west':\r
574                         x -= sw - w;\r
575                         break;\r
576                     case 'northwest':\r
577                         x -= sw - w;\r
578                         y -= sh - h;\r
579                     break;\r
580                 }\r
581                 w = sw;\r
582                 h = sh;\r
583             }\r
584             \r
585             if(this.preserveRatio){\r
586                 switch(pos){\r
587                     case 'southeast':\r
588                     case 'east':\r
589                         h = oh * (w/ow);\r
590                         h = Math.min(Math.max(mh, h), mxh);\r
591                         w = ow * (h/oh);\r
592                        break;\r
593                     case 'south':\r
594                         w = ow * (h/oh);\r
595                         w = Math.min(Math.max(mw, w), mxw);\r
596                         h = oh * (w/ow);\r
597                         break;\r
598                     case 'northeast':\r
599                         w = ow * (h/oh);\r
600                         w = Math.min(Math.max(mw, w), mxw);\r
601                         h = oh * (w/ow);\r
602                     break;\r
603                     case 'north':\r
604                         tw = w;\r
605                         w = ow * (h/oh);\r
606                         w = Math.min(Math.max(mw, w), mxw);\r
607                         h = oh * (w/ow);\r
608                         x += (tw - w) / 2;\r
609                         break;\r
610                     case 'southwest':\r
611                         h = oh * (w/ow);\r
612                         h = Math.min(Math.max(mh, h), mxh);\r
613                         tw = w;\r
614                         w = ow * (h/oh);\r
615                         x += tw - w;\r
616                         break;\r
617                     case 'west':\r
618                         th = h;\r
619                         h = oh * (w/ow);\r
620                         h = Math.min(Math.max(mh, h), mxh);\r
621                         y += (th - h) / 2;\r
622                         tw = w;\r
623                         w = ow * (h/oh);\r
624                         x += tw - w;\r
625                        break;\r
626                     case 'northwest':\r
627                         tw = w;\r
628                         th = h;\r
629                         h = oh * (w/ow);\r
630                         h = Math.min(Math.max(mh, h), mxh);\r
631                         w = ow * (h/oh);\r
632                         y += th - h;\r
633                         x += tw - w;\r
634                         break;\r
635                         \r
636                 }\r
637             }\r
638             this.proxy.setBounds(x, y, w, h);\r
639             if(this.dynamic){\r
640                 this.resizeElement();\r
641             }\r
642             }catch(ex){}\r
643         }\r
644     },\r
645 \r
646     // private\r
647     handleOver : function(){\r
648         if(this.enabled){\r
649             this.el.addClass('x-resizable-over');\r
650         }\r
651     },\r
652 \r
653     // private\r
654     handleOut : function(){\r
655         if(!this.resizing){\r
656             this.el.removeClass('x-resizable-over');\r
657         }\r
658     },\r
659     \r
660     /**\r
661      * Returns the element this component is bound to.\r
662      * @return {Ext.Element}\r
663      */\r
664     getEl : function(){\r
665         return this.el;\r
666     },\r
667     \r
668     /**\r
669      * Returns the resizeChild element (or null).\r
670      * @return {Ext.Element}\r
671      */\r
672     getResizeChild : function(){\r
673         return this.resizeChild;\r
674     },\r
675     \r
676     /**\r
677      * Destroys this resizable. If the element was wrapped and \r
678      * removeEl is not true then the element remains.\r
679      * @param {Boolean} removeEl (optional) true to remove the element from the DOM\r
680      */\r
681     destroy : function(removeEl){\r
682         Ext.destroy(this.dd, this.overlay, this.proxy);\r
683         this.overlay = null;\r
684         this.proxy = null;\r
685         \r
686         var ps = Ext.Resizable.positions;\r
687         for(var k in ps){\r
688             if(typeof ps[k] != 'function' && this[ps[k]]){\r
689                 this[ps[k]].destroy();\r
690             }\r
691         }\r
692         if(removeEl){\r
693             this.el.update('');\r
694             Ext.destroy(this.el);\r
695             this.el = null;\r
696         }\r
697         this.purgeListeners();\r
698     },\r
699 \r
700     syncHandleHeight : function(){\r
701         var h = this.el.getHeight(true);\r
702         if(this.west){\r
703             this.west.el.setHeight(h);\r
704         }\r
705         if(this.east){\r
706             this.east.el.setHeight(h);\r
707         }\r
708     }\r
709 });\r
710 \r
711 // private\r
712 // hash to map config positions to true positions\r
713 Ext.Resizable.positions = {\r
714     n: 'north', s: 'south', e: 'east', w: 'west', se: 'southeast', sw: 'southwest', nw: 'northwest', ne: 'northeast'\r
715 };\r
716 \r
717 // private\r
718 Ext.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){\r
719     if(!this.tpl){\r
720         // only initialize the template if resizable is used\r
721         var tpl = Ext.DomHelper.createTemplate(\r
722             {tag: 'div', cls: 'x-resizable-handle x-resizable-handle-{0}'}\r
723         );\r
724         tpl.compile();\r
725         Ext.Resizable.Handle.prototype.tpl = tpl;\r
726     }\r
727     this.position = pos;\r
728     this.rz = rz;\r
729     this.el = this.tpl.append(rz.el.dom, [this.position], true);\r
730     this.el.unselectable();\r
731     if(transparent){\r
732         this.el.setOpacity(0);\r
733     }\r
734     this.el.on('mousedown', this.onMouseDown, this);\r
735     if(!disableTrackOver){\r
736         this.el.on({\r
737             scope: this,\r
738             mouseover: this.onMouseOver,\r
739             mouseout: this.onMouseOut\r
740         });\r
741     }\r
742 };\r
743 \r
744 // private\r
745 Ext.Resizable.Handle.prototype = {\r
746     // private\r
747     afterResize : function(rz){\r
748         // do nothing    \r
749     },\r
750     // private\r
751     onMouseDown : function(e){\r
752         this.rz.onMouseDown(this, e);\r
753     },\r
754     // private\r
755     onMouseOver : function(e){\r
756         this.rz.handleOver(this, e);\r
757     },\r
758     // private\r
759     onMouseOut : function(e){\r
760         this.rz.handleOut(this, e);\r
761     },\r
762     // private\r
763     destroy : function(){\r
764         Ext.destroy(this.el);\r
765         this.el = null;\r
766     }\r
767 };\r