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.

189 lines
8.4 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-Element'>/**
  19. </span> * @class Ext.Element
  20. */
  21. Ext.Element.addMethods({
  22. <span id='Ext-Element-method-setBox'> /**
  23. </span> * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
  24. * @param {Object} box The box to fill {x, y, width, height}
  25. * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
  26. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  27. * @return {Ext.Element} this
  28. */
  29. setBox : function(box, adjust, animate){
  30. var me = this,
  31. w = box.width,
  32. h = box.height;
  33. if((adjust &amp;&amp; !me.autoBoxAdjust) &amp;&amp; !me.isBorderBox()){
  34. w -= (me.getBorderWidth(&quot;lr&quot;) + me.getPadding(&quot;lr&quot;));
  35. h -= (me.getBorderWidth(&quot;tb&quot;) + me.getPadding(&quot;tb&quot;));
  36. }
  37. me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));
  38. return me;
  39. },
  40. <span id='Ext-Element-method-getBox'> /**
  41. </span> * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  42. * set another Element's size/location to match this element.
  43. * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
  44. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
  45. * @return {Object} box An object in the format&lt;pre&gt;&lt;code&gt;
  46. {
  47. x: &amp;lt;Element's X position&gt;,
  48. y: &amp;lt;Element's Y position&gt;,
  49. width: &amp;lt;Element's width&gt;,
  50. height: &amp;lt;Element's height&gt;,
  51. bottom: &amp;lt;Element's lower bound&gt;,
  52. right: &amp;lt;Element's rightmost bound&gt;
  53. }
  54. &lt;/code&gt;&lt;/pre&gt;
  55. * The returned object may also be addressed as an Array where index 0 contains the X position
  56. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  57. */
  58. getBox : function(contentBox, local) {
  59. var me = this,
  60. xy,
  61. left,
  62. top,
  63. getBorderWidth = me.getBorderWidth,
  64. getPadding = me.getPadding,
  65. l,
  66. r,
  67. t,
  68. b;
  69. if(!local){
  70. xy = me.getXY();
  71. }else{
  72. left = parseInt(me.getStyle(&quot;left&quot;), 10) || 0;
  73. top = parseInt(me.getStyle(&quot;top&quot;), 10) || 0;
  74. xy = [left, top];
  75. }
  76. var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
  77. if(!contentBox){
  78. bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
  79. }else{
  80. l = getBorderWidth.call(me, &quot;l&quot;) + getPadding.call(me, &quot;l&quot;);
  81. r = getBorderWidth.call(me, &quot;r&quot;) + getPadding.call(me, &quot;r&quot;);
  82. t = getBorderWidth.call(me, &quot;t&quot;) + getPadding.call(me, &quot;t&quot;);
  83. b = getBorderWidth.call(me, &quot;b&quot;) + getPadding.call(me, &quot;b&quot;);
  84. bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
  85. }
  86. bx.right = bx.x + bx.width;
  87. bx.bottom = bx.y + bx.height;
  88. return bx;
  89. },
  90. <span id='Ext-Element-method-move'> /**
  91. </span> * Move this element relative to its current position.
  92. * @param {String} direction Possible values are: &quot;l&quot; (or &quot;left&quot;), &quot;r&quot; (or &quot;right&quot;), &quot;t&quot; (or &quot;top&quot;, or &quot;up&quot;), &quot;b&quot; (or &quot;bottom&quot;, or &quot;down&quot;).
  93. * @param {Number} distance How far to move the element in pixels
  94. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  95. * @return {Ext.Element} this
  96. */
  97. move : function(direction, distance, animate){
  98. var me = this,
  99. xy = me.getXY(),
  100. x = xy[0],
  101. y = xy[1],
  102. left = [x - distance, y],
  103. right = [x + distance, y],
  104. top = [x, y - distance],
  105. bottom = [x, y + distance],
  106. hash = {
  107. l : left,
  108. left : left,
  109. r : right,
  110. right : right,
  111. t : top,
  112. top : top,
  113. up : top,
  114. b : bottom,
  115. bottom : bottom,
  116. down : bottom
  117. };
  118. direction = direction.toLowerCase();
  119. me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));
  120. },
  121. <span id='Ext-Element-method-setLeftTop'> /**
  122. </span> * Quick set left and top adding default units
  123. * @param {String} left The left CSS property value
  124. * @param {String} top The top CSS property value
  125. * @return {Ext.Element} this
  126. */
  127. setLeftTop : function(left, top){
  128. var me = this,
  129. style = me.dom.style;
  130. style.left = me.addUnits(left);
  131. style.top = me.addUnits(top);
  132. return me;
  133. },
  134. <span id='Ext-Element-method-getRegion'> /**
  135. </span> * Returns the region of the given element.
  136. * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
  137. * @return {Region} A Ext.lib.Region containing &quot;top, left, bottom, right&quot; member data.
  138. */
  139. getRegion : function(){
  140. return Ext.lib.Dom.getRegion(this.dom);
  141. },
  142. <span id='Ext-Element-method-setBounds'> /**
  143. </span> * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
  144. * @param {Number} x X value for new position (coordinates are page-based)
  145. * @param {Number} y Y value for new position (coordinates are page-based)
  146. * @param {Mixed} width The new width. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  147. * &lt;li&gt;A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)&lt;/li&gt;
  148. * &lt;li&gt;A String used to set the CSS width style. Animation may &lt;b&gt;not&lt;/b&gt; be used.
  149. * &lt;/ul&gt;&lt;/div&gt;
  150. * @param {Mixed} height The new height. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  151. * &lt;li&gt;A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)&lt;/li&gt;
  152. * &lt;li&gt;A String used to set the CSS height style. Animation may &lt;b&gt;not&lt;/b&gt; be used.&lt;/li&gt;
  153. * &lt;/ul&gt;&lt;/div&gt;
  154. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  155. * @return {Ext.Element} this
  156. */
  157. setBounds : function(x, y, width, height, animate){
  158. var me = this;
  159. if (!animate || !me.anim) {
  160. me.setSize(width, height);
  161. me.setLocation(x, y);
  162. } else {
  163. me.anim({points: {to: [x, y]},
  164. width: {to: me.adjustWidth(width)},
  165. height: {to: me.adjustHeight(height)}},
  166. me.preanim(arguments, 4),
  167. 'motion');
  168. }
  169. return me;
  170. },
  171. <span id='Ext-Element-method-setRegion'> /**
  172. </span> * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.
  173. * @param {Ext.lib.Region} region The region to fill
  174. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  175. * @return {Ext.Element} this
  176. */
  177. setRegion : function(region, animate) {
  178. return this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.animTest.call(this, arguments, animate, 1));
  179. }
  180. });</pre>
  181. </body>
  182. </html>