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.

314 lines
13 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. (function(){
  22. var D = Ext.lib.Dom,
  23. LEFT = &quot;left&quot;,
  24. RIGHT = &quot;right&quot;,
  25. TOP = &quot;top&quot;,
  26. BOTTOM = &quot;bottom&quot;,
  27. POSITION = &quot;position&quot;,
  28. STATIC = &quot;static&quot;,
  29. RELATIVE = &quot;relative&quot;,
  30. AUTO = &quot;auto&quot;,
  31. ZINDEX = &quot;z-index&quot;;
  32. Ext.Element.addMethods({
  33. <span id='Ext-Element-method-getX'> /**
  34. </span> * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  35. * @return {Number} The X position of the element
  36. */
  37. getX : function(){
  38. return D.getX(this.dom);
  39. },
  40. <span id='Ext-Element-method-getY'> /**
  41. </span> * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  42. * @return {Number} The Y position of the element
  43. */
  44. getY : function(){
  45. return D.getY(this.dom);
  46. },
  47. <span id='Ext-Element-method-getXY'> /**
  48. </span> * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  49. * @return {Array} The XY position of the element
  50. */
  51. getXY : function(){
  52. return D.getXY(this.dom);
  53. },
  54. <span id='Ext-Element-method-getOffsetsTo'> /**
  55. </span> * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
  56. * @param {Mixed} element The element to get the offsets from.
  57. * @return {Array} The XY page offsets (e.g. [100, -200])
  58. */
  59. getOffsetsTo : function(el){
  60. var o = this.getXY(),
  61. e = Ext.fly(el, '_internal').getXY();
  62. return [o[0]-e[0],o[1]-e[1]];
  63. },
  64. <span id='Ext-Element-method-setX'> /**
  65. </span> * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  66. * @param {Number} The X position of the element
  67. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  68. * @return {Ext.Element} this
  69. */
  70. setX : function(x, animate){
  71. return this.setXY([x, this.getY()], this.animTest(arguments, animate, 1));
  72. },
  73. <span id='Ext-Element-method-setY'> /**
  74. </span> * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  75. * @param {Number} The Y position of the element
  76. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  77. * @return {Ext.Element} this
  78. */
  79. setY : function(y, animate){
  80. return this.setXY([this.getX(), y], this.animTest(arguments, animate, 1));
  81. },
  82. <span id='Ext-Element-method-setLeft'> /**
  83. </span> * Sets the element's left position directly using CSS style (instead of {@link #setX}).
  84. * @param {String} left The left CSS property value
  85. * @return {Ext.Element} this
  86. */
  87. setLeft : function(left){
  88. this.setStyle(LEFT, this.addUnits(left));
  89. return this;
  90. },
  91. <span id='Ext-Element-method-setTop'> /**
  92. </span> * Sets the element's top position directly using CSS style (instead of {@link #setY}).
  93. * @param {String} top The top CSS property value
  94. * @return {Ext.Element} this
  95. */
  96. setTop : function(top){
  97. this.setStyle(TOP, this.addUnits(top));
  98. return this;
  99. },
  100. <span id='Ext-Element-method-setRight'> /**
  101. </span> * Sets the element's CSS right style.
  102. * @param {String} right The right CSS property value
  103. * @return {Ext.Element} this
  104. */
  105. setRight : function(right){
  106. this.setStyle(RIGHT, this.addUnits(right));
  107. return this;
  108. },
  109. <span id='Ext-Element-method-setBottom'> /**
  110. </span> * Sets the element's CSS bottom style.
  111. * @param {String} bottom The bottom CSS property value
  112. * @return {Ext.Element} this
  113. */
  114. setBottom : function(bottom){
  115. this.setStyle(BOTTOM, this.addUnits(bottom));
  116. return this;
  117. },
  118. <span id='Ext-Element-method-setXY'> /**
  119. </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  120. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  121. * @param {Array} pos Contains X &amp; Y [x, y] values for new position (coordinates are page-based)
  122. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  123. * @return {Ext.Element} this
  124. */
  125. setXY : function(pos, animate){
  126. var me = this;
  127. if(!animate || !me.anim){
  128. D.setXY(me.dom, pos);
  129. }else{
  130. me.anim({points: {to: pos}}, me.preanim(arguments, 1), 'motion');
  131. }
  132. return me;
  133. },
  134. <span id='Ext-Element-method-setLocation'> /**
  135. </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  136. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  137. * @param {Number} x X value for new position (coordinates are page-based)
  138. * @param {Number} y Y value for new position (coordinates are page-based)
  139. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  140. * @return {Ext.Element} this
  141. */
  142. setLocation : function(x, y, animate){
  143. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  144. },
  145. <span id='Ext-Element-method-moveTo'> /**
  146. </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  147. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  148. * @param {Number} x X value for new position (coordinates are page-based)
  149. * @param {Number} y Y value for new position (coordinates are page-based)
  150. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  151. * @return {Ext.Element} this
  152. */
  153. moveTo : function(x, y, animate){
  154. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  155. },
  156. <span id='Ext-Element-method-getLeft'> /**
  157. </span> * Gets the left X coordinate
  158. * @param {Boolean} local True to get the local css position instead of page coordinate
  159. * @return {Number}
  160. */
  161. getLeft : function(local){
  162. return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
  163. },
  164. <span id='Ext-Element-method-getRight'> /**
  165. </span> * Gets the right X coordinate of the element (element X position + element width)
  166. * @param {Boolean} local True to get the local css position instead of page coordinate
  167. * @return {Number}
  168. */
  169. getRight : function(local){
  170. var me = this;
  171. return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
  172. },
  173. <span id='Ext-Element-method-getTop'> /**
  174. </span> * Gets the top Y coordinate
  175. * @param {Boolean} local True to get the local css position instead of page coordinate
  176. * @return {Number}
  177. */
  178. getTop : function(local) {
  179. return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
  180. },
  181. <span id='Ext-Element-method-getBottom'> /**
  182. </span> * Gets the bottom Y coordinate of the element (element Y position + element height)
  183. * @param {Boolean} local True to get the local css position instead of page coordinate
  184. * @return {Number}
  185. */
  186. getBottom : function(local){
  187. var me = this;
  188. return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
  189. },
  190. <span id='Ext-Element-method-position'> /**
  191. </span> * Initializes positioning on this element. If a desired position is not passed, it will make the
  192. * the element positioned relative IF it is not already positioned.
  193. * @param {String} pos (optional) Positioning to use &quot;relative&quot;, &quot;absolute&quot; or &quot;fixed&quot;
  194. * @param {Number} zIndex (optional) The zIndex to apply
  195. * @param {Number} x (optional) Set the page X position
  196. * @param {Number} y (optional) Set the page Y position
  197. */
  198. position : function(pos, zIndex, x, y){
  199. var me = this;
  200. if(!pos &amp;&amp; me.isStyle(POSITION, STATIC)){
  201. me.setStyle(POSITION, RELATIVE);
  202. } else if(pos) {
  203. me.setStyle(POSITION, pos);
  204. }
  205. if(zIndex){
  206. me.setStyle(ZINDEX, zIndex);
  207. }
  208. if(x || y) me.setXY([x || false, y || false]);
  209. },
  210. <span id='Ext-Element-method-clearPositioning'> /**
  211. </span> * Clear positioning back to the default when the document was loaded
  212. * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
  213. * @return {Ext.Element} this
  214. */
  215. clearPositioning : function(value){
  216. value = value || '';
  217. this.setStyle({
  218. left : value,
  219. right : value,
  220. top : value,
  221. bottom : value,
  222. &quot;z-index&quot; : &quot;&quot;,
  223. position : STATIC
  224. });
  225. return this;
  226. },
  227. <span id='Ext-Element-method-getPositioning'> /**
  228. </span> * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
  229. * snapshot before performing an update and then restoring the element.
  230. * @return {Object}
  231. */
  232. getPositioning : function(){
  233. var l = this.getStyle(LEFT);
  234. var t = this.getStyle(TOP);
  235. return {
  236. &quot;position&quot; : this.getStyle(POSITION),
  237. &quot;left&quot; : l,
  238. &quot;right&quot; : l ? &quot;&quot; : this.getStyle(RIGHT),
  239. &quot;top&quot; : t,
  240. &quot;bottom&quot; : t ? &quot;&quot; : this.getStyle(BOTTOM),
  241. &quot;z-index&quot; : this.getStyle(ZINDEX)
  242. };
  243. },
  244. <span id='Ext-Element-method-setPositioning'> /**
  245. </span> * Set positioning with an object returned by getPositioning().
  246. * @param {Object} posCfg
  247. * @return {Ext.Element} this
  248. */
  249. setPositioning : function(pc){
  250. var me = this,
  251. style = me.dom.style;
  252. me.setStyle(pc);
  253. if(pc.right == AUTO){
  254. style.right = &quot;&quot;;
  255. }
  256. if(pc.bottom == AUTO){
  257. style.bottom = &quot;&quot;;
  258. }
  259. return me;
  260. },
  261. <span id='Ext-Element-method-translatePoints'> /**
  262. </span> * Translates the passed page coordinates into left/top css values for this element
  263. * @param {Number/Array} x The page x or an array containing [x, y]
  264. * @param {Number} y (optional) The page y, required if x is not an array
  265. * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
  266. */
  267. translatePoints : function(x, y){
  268. y = isNaN(x[1]) ? y : x[1];
  269. x = isNaN(x[0]) ? x : x[0];
  270. var me = this,
  271. relative = me.isStyle(POSITION, RELATIVE),
  272. o = me.getXY(),
  273. l = parseInt(me.getStyle(LEFT), 10),
  274. t = parseInt(me.getStyle(TOP), 10);
  275. l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
  276. t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
  277. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  278. },
  279. animTest : function(args, animate, i) {
  280. return !!animate &amp;&amp; this.preanim ? this.preanim(args, i) : false;
  281. }
  282. });
  283. })();</pre>
  284. </body>
  285. </html>