You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

784 lines
26 KiB

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