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
28 KiB

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