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.

373 lines
17 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. // special markup used throughout Ext when box wrapping elements
  22. Ext.Element.boxMarkup = '&lt;div class=&quot;{0}-tl&quot;&gt;&lt;div class=&quot;{0}-tr&quot;&gt;&lt;div class=&quot;{0}-tc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;{0}-ml&quot;&gt;&lt;div class=&quot;{0}-mr&quot;&gt;&lt;div class=&quot;{0}-mc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;{0}-bl&quot;&gt;&lt;div class=&quot;{0}-br&quot;&gt;&lt;div class=&quot;{0}-bc&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;';
  23. Ext.Element.addMethods(function(){
  24. var INTERNAL = &quot;_internal&quot;,
  25. pxMatch = /(\d+\.?\d+)px/;
  26. return {
  27. <span id='Ext-Element-method-applyStyles'> /**
  28. </span> * More flexible version of {@link #setStyle} for setting style properties.
  29. * @param {String/Object/Function} styles A style specification string, e.g. &quot;width:100px&quot;, or object in the form {width:&quot;100px&quot;}, or
  30. * a function which returns such a specification.
  31. * @return {Ext.Element} this
  32. */
  33. applyStyles : function(style){
  34. Ext.DomHelper.applyStyles(this.dom, style);
  35. return this;
  36. },
  37. <span id='Ext-Element-method-getStyles'> /**
  38. </span> * Returns an object with properties matching the styles requested.
  39. * For example, el.getStyles('color', 'font-size', 'width') might return
  40. * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
  41. * @param {String} style1 A style name
  42. * @param {String} style2 A style name
  43. * @param {String} etc.
  44. * @return {Object} The style object
  45. */
  46. getStyles : function(){
  47. var ret = {};
  48. Ext.each(arguments, function(v) {
  49. ret[v] = this.getStyle(v);
  50. },
  51. this);
  52. return ret;
  53. },
  54. // private ==&gt; used by ext full
  55. setOverflow : function(v){
  56. var dom = this.dom;
  57. if(v=='auto' &amp;&amp; Ext.isMac &amp;&amp; Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  58. dom.style.overflow = 'hidden';
  59. (function(){dom.style.overflow = 'auto';}).defer(1);
  60. }else{
  61. dom.style.overflow = v;
  62. }
  63. },
  64. <span id='Ext-Element-method-boxWrap'> /**
  65. </span> * &lt;p&gt;Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  66. * a gray container with a gradient background, rounded corners and a 4-way shadow.&lt;/p&gt;
  67. * &lt;p&gt;This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
  68. * {@link Ext.Panel} when &lt;tt&gt;{@link Ext.Panel#frame frame=true}&lt;/tt&gt;, {@link Ext.Window}). The markup
  69. * is of this form:&lt;/p&gt;
  70. * &lt;pre&gt;&lt;code&gt;
  71. Ext.Element.boxMarkup =
  72. &amp;#39;&amp;lt;div class=&quot;{0}-tl&quot;&gt;&amp;lt;div class=&quot;{0}-tr&quot;&gt;&amp;lt;div class=&quot;{0}-tc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;
  73. &amp;lt;div class=&quot;{0}-ml&quot;&gt;&amp;lt;div class=&quot;{0}-mr&quot;&gt;&amp;lt;div class=&quot;{0}-mc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;
  74. &amp;lt;div class=&quot;{0}-bl&quot;&gt;&amp;lt;div class=&quot;{0}-br&quot;&gt;&amp;lt;div class=&quot;{0}-bc&quot;&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;lt;/div&gt;&amp;#39;;
  75. * &lt;/code&gt;&lt;/pre&gt;
  76. * &lt;p&gt;Example usage:&lt;/p&gt;
  77. * &lt;pre&gt;&lt;code&gt;
  78. // Basic box wrap
  79. Ext.get(&quot;foo&quot;).boxWrap();
  80. // You can also add a custom class and use CSS inheritance rules to customize the box look.
  81. // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  82. // for how to create a custom box wrap style.
  83. Ext.get(&quot;foo&quot;).boxWrap().addClass(&quot;x-box-blue&quot;);
  84. * &lt;/code&gt;&lt;/pre&gt;
  85. * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
  86. * (defaults to &lt;tt&gt;'x-box'&lt;/tt&gt;). Note that there are a number of CSS rules that are dependent on
  87. * this name to make the overall effect work, so if you supply an alternate base class, make sure you
  88. * also supply all of the necessary rules.
  89. * @return {Ext.Element} The outermost wrapping element of the created box structure.
  90. */
  91. boxWrap : function(cls){
  92. cls = cls || 'x-box';
  93. var el = Ext.get(this.insertHtml(&quot;beforeBegin&quot;, &quot;&lt;div class='&quot; + cls + &quot;'&gt;&quot; + String.format(Ext.Element.boxMarkup, cls) + &quot;&lt;/div&gt;&quot;)); //String.format('&lt;div class=&quot;{0}&quot;&gt;'+Ext.Element.boxMarkup+'&lt;/div&gt;', cls)));
  94. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  95. return el;
  96. },
  97. <span id='Ext-Element-method-setSize'> /**
  98. </span> * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  99. * @param {Mixed} width The new width. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  100. * &lt;li&gt;A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  101. * &lt;li&gt;A String used to set the CSS width style. Animation may &lt;b&gt;not&lt;/b&gt; be used.
  102. * &lt;li&gt;A size object in the format &lt;code&gt;{width: widthValue, height: heightValue}&lt;/code&gt;.&lt;/li&gt;
  103. * &lt;/ul&gt;&lt;/div&gt;
  104. * @param {Mixed} height The new height. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  105. * &lt;li&gt;A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  106. * &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;
  107. * &lt;/ul&gt;&lt;/div&gt;
  108. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  109. * @return {Ext.Element} this
  110. */
  111. setSize : function(width, height, animate){
  112. var me = this;
  113. if(typeof width == 'object'){ // in case of object from getSize()
  114. height = width.height;
  115. width = width.width;
  116. }
  117. width = me.adjustWidth(width);
  118. height = me.adjustHeight(height);
  119. if(!animate || !me.anim){
  120. me.dom.style.width = me.addUnits(width);
  121. me.dom.style.height = me.addUnits(height);
  122. }else{
  123. me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
  124. }
  125. return me;
  126. },
  127. <span id='Ext-Element-method-getComputedHeight'> /**
  128. </span> * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  129. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  130. * if a height has not been set using CSS.
  131. * @return {Number}
  132. */
  133. getComputedHeight : function(){
  134. var me = this,
  135. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  136. if(!h){
  137. h = parseFloat(me.getStyle('height')) || 0;
  138. if(!me.isBorderBox()){
  139. h += me.getFrameWidth('tb');
  140. }
  141. }
  142. return h;
  143. },
  144. <span id='Ext-Element-method-getComputedWidth'> /**
  145. </span> * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  146. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  147. * if a width has not been set using CSS.
  148. * @return {Number}
  149. */
  150. getComputedWidth : function(){
  151. var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
  152. if(!w){
  153. w = parseFloat(this.getStyle('width')) || 0;
  154. if(!this.isBorderBox()){
  155. w += this.getFrameWidth('lr');
  156. }
  157. }
  158. return w;
  159. },
  160. <span id='Ext-Element-method-getFrameWidth'> /**
  161. </span> * Returns the sum width of the padding and borders for the passed &quot;sides&quot;. See getBorderWidth()
  162. for more information about the sides.
  163. * @param {String} sides
  164. * @return {Number}
  165. */
  166. getFrameWidth : function(sides, onlyContentBox){
  167. return onlyContentBox &amp;&amp; this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  168. },
  169. <span id='Ext-Element-method-addClassOnOver'> /**
  170. </span> * Sets up event handlers to add and remove a css class when the mouse is over this element
  171. * @param {String} className
  172. * @return {Ext.Element} this
  173. */
  174. addClassOnOver : function(className){
  175. this.hover(
  176. function(){
  177. Ext.fly(this, INTERNAL).addClass(className);
  178. },
  179. function(){
  180. Ext.fly(this, INTERNAL).removeClass(className);
  181. }
  182. );
  183. return this;
  184. },
  185. <span id='Ext-Element-method-addClassOnFocus'> /**
  186. </span> * Sets up event handlers to add and remove a css class when this element has the focus
  187. * @param {String} className
  188. * @return {Ext.Element} this
  189. */
  190. addClassOnFocus : function(className){
  191. this.on(&quot;focus&quot;, function(){
  192. Ext.fly(this, INTERNAL).addClass(className);
  193. }, this.dom);
  194. this.on(&quot;blur&quot;, function(){
  195. Ext.fly(this, INTERNAL).removeClass(className);
  196. }, this.dom);
  197. return this;
  198. },
  199. <span id='Ext-Element-method-addClassOnClick'> /**
  200. </span> * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  201. * @param {String} className
  202. * @return {Ext.Element} this
  203. */
  204. addClassOnClick : function(className){
  205. var dom = this.dom;
  206. this.on(&quot;mousedown&quot;, function(){
  207. Ext.fly(dom, INTERNAL).addClass(className);
  208. var d = Ext.getDoc(),
  209. fn = function(){
  210. Ext.fly(dom, INTERNAL).removeClass(className);
  211. d.removeListener(&quot;mouseup&quot;, fn);
  212. };
  213. d.on(&quot;mouseup&quot;, fn);
  214. });
  215. return this;
  216. },
  217. <span id='Ext-Element-method-getViewSize'> /**
  218. </span> * &lt;p&gt;Returns the dimensions of the element available to lay content out in.&lt;p&gt;
  219. * &lt;p&gt;If the element (or any ancestor element) has CSS style &lt;code&gt;display : none&lt;/code&gt;, the dimensions will be zero.&lt;/p&gt;
  220. * example:&lt;pre&gt;&lt;code&gt;
  221. var vpSize = Ext.getBody().getViewSize();
  222. // all Windows created afterwards will have a default value of 90% height and 95% width
  223. Ext.Window.override({
  224. width: vpSize.width * 0.9,
  225. height: vpSize.height * 0.95
  226. });
  227. // To handle window resizing you would have to hook onto onWindowResize.
  228. * &lt;/code&gt;&lt;/pre&gt;
  229. *
  230. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  231. * To obtain the size including scrollbars, use getStyleSize
  232. *
  233. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  234. */
  235. getViewSize : function(){
  236. var doc = document,
  237. d = this.dom,
  238. isDoc = (d == doc || d == doc.body);
  239. // If the body, use Ext.lib.Dom
  240. if (isDoc) {
  241. var extdom = Ext.lib.Dom;
  242. return {
  243. width : extdom.getViewWidth(),
  244. height : extdom.getViewHeight()
  245. };
  246. // Else use clientHeight/clientWidth
  247. } else {
  248. return {
  249. width : d.clientWidth,
  250. height : d.clientHeight
  251. };
  252. }
  253. },
  254. <span id='Ext-Element-method-getStyleSize'> /**
  255. </span> * &lt;p&gt;Returns the dimensions of the element available to lay content out in.&lt;p&gt;
  256. *
  257. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
  258. * To obtain the size excluding scrollbars, use getViewSize
  259. *
  260. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  261. */
  262. getStyleSize : function(){
  263. var me = this,
  264. w, h,
  265. doc = document,
  266. d = this.dom,
  267. isDoc = (d == doc || d == doc.body),
  268. s = d.style;
  269. // If the body, use Ext.lib.Dom
  270. if (isDoc) {
  271. var extdom = Ext.lib.Dom;
  272. return {
  273. width : extdom.getViewWidth(),
  274. height : extdom.getViewHeight()
  275. };
  276. }
  277. // Use Styles if they are set
  278. if(s.width &amp;&amp; s.width != 'auto'){
  279. w = parseFloat(s.width);
  280. if(me.isBorderBox()){
  281. w -= me.getFrameWidth('lr');
  282. }
  283. }
  284. // Use Styles if they are set
  285. if(s.height &amp;&amp; s.height != 'auto'){
  286. h = parseFloat(s.height);
  287. if(me.isBorderBox()){
  288. h -= me.getFrameWidth('tb');
  289. }
  290. }
  291. // Use getWidth/getHeight if style not set.
  292. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  293. },
  294. <span id='Ext-Element-method-getSize'> /**
  295. </span> * Returns the size of the element.
  296. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
  297. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  298. */
  299. getSize : function(contentSize){
  300. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  301. },
  302. <span id='Ext-Element-method-repaint'> /**
  303. </span> * Forces the browser to repaint this element
  304. * @return {Ext.Element} this
  305. */
  306. repaint : function(){
  307. var dom = this.dom;
  308. this.addClass(&quot;x-repaint&quot;);
  309. setTimeout(function(){
  310. Ext.fly(dom).removeClass(&quot;x-repaint&quot;);
  311. }, 1);
  312. return this;
  313. },
  314. <span id='Ext-Element-method-unselectable'> /**
  315. </span> * Disables text selection for this element (normalized across browsers)
  316. * @return {Ext.Element} this
  317. */
  318. unselectable : function(){
  319. this.dom.unselectable = &quot;on&quot;;
  320. return this.swallowEvent(&quot;selectstart&quot;, true).
  321. addClass(&quot;x-unselectable&quot;);
  322. },
  323. <span id='Ext-Element-method-getMargins'> /**
  324. </span> * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  325. * then it returns the calculated width of the sides (see getPadding)
  326. * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
  327. * @return {Object/Number}
  328. */
  329. getMargins : function(side){
  330. var me = this,
  331. key,
  332. hash = {t:&quot;top&quot;, l:&quot;left&quot;, r:&quot;right&quot;, b: &quot;bottom&quot;},
  333. o = {};
  334. if (!side) {
  335. for (key in me.margins){
  336. o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
  337. }
  338. return o;
  339. } else {
  340. return me.addStyles.call(me, side, me.margins);
  341. }
  342. }
  343. };
  344. }());
  345. </pre>
  346. </body>
  347. </html>