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.

517 lines
21 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(function(){
  22. // local style camelizing for speed
  23. var supports = Ext.supports,
  24. propCache = {},
  25. camelRe = /(-[a-z])/gi,
  26. view = document.defaultView,
  27. opacityRe = /alpha\(opacity=(.*)\)/i,
  28. trimRe = /^\s+|\s+$/g,
  29. EL = Ext.Element,
  30. spacesRe = /\s+/,
  31. wordsRe = /\w/g,
  32. PADDING = &quot;padding&quot;,
  33. MARGIN = &quot;margin&quot;,
  34. BORDER = &quot;border&quot;,
  35. LEFT = &quot;-left&quot;,
  36. RIGHT = &quot;-right&quot;,
  37. TOP = &quot;-top&quot;,
  38. BOTTOM = &quot;-bottom&quot;,
  39. WIDTH = &quot;-width&quot;,
  40. MATH = Math,
  41. HIDDEN = 'hidden',
  42. ISCLIPPED = 'isClipped',
  43. OVERFLOW = 'overflow',
  44. OVERFLOWX = 'overflow-x',
  45. OVERFLOWY = 'overflow-y',
  46. ORIGINALCLIP = 'originalClip',
  47. // special markup used throughout Ext when box wrapping elements
  48. borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
  49. paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
  50. margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
  51. data = Ext.Element.data;
  52. // private
  53. function camelFn(m, a) {
  54. return a.charAt(1).toUpperCase();
  55. }
  56. function chkCache(prop) {
  57. return propCache[prop] || (propCache[prop] = prop == 'float' ? (supports.cssFloat ? 'cssFloat' : 'styleFloat') : prop.replace(camelRe, camelFn));
  58. }
  59. return {
  60. // private ==&gt; used by Fx
  61. adjustWidth : function(width) {
  62. var me = this;
  63. var isNum = (typeof width == &quot;number&quot;);
  64. if(isNum &amp;&amp; me.autoBoxAdjust &amp;&amp; !me.isBorderBox()){
  65. width -= (me.getBorderWidth(&quot;lr&quot;) + me.getPadding(&quot;lr&quot;));
  66. }
  67. return (isNum &amp;&amp; width &lt; 0) ? 0 : width;
  68. },
  69. // private ==&gt; used by Fx
  70. adjustHeight : function(height) {
  71. var me = this;
  72. var isNum = (typeof height == &quot;number&quot;);
  73. if(isNum &amp;&amp; me.autoBoxAdjust &amp;&amp; !me.isBorderBox()){
  74. height -= (me.getBorderWidth(&quot;tb&quot;) + me.getPadding(&quot;tb&quot;));
  75. }
  76. return (isNum &amp;&amp; height &lt; 0) ? 0 : height;
  77. },
  78. <span id='Ext-Element-method-addClass'> /**
  79. </span> * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  80. * @param {String/Array} className The CSS class to add, or an array of classes
  81. * @return {Ext.Element} this
  82. */
  83. addClass : function(className){
  84. var me = this,
  85. i,
  86. len,
  87. v,
  88. cls = [];
  89. // Separate case is for speed
  90. if (!Ext.isArray(className)) {
  91. if (typeof className == 'string' &amp;&amp; !this.hasClass(className)) {
  92. me.dom.className += &quot; &quot; + className;
  93. }
  94. }
  95. else {
  96. for (i = 0, len = className.length; i &lt; len; i++) {
  97. v = className[i];
  98. if (typeof v == 'string' &amp;&amp; (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
  99. cls.push(v);
  100. }
  101. }
  102. if (cls.length) {
  103. me.dom.className += &quot; &quot; + cls.join(&quot; &quot;);
  104. }
  105. }
  106. return me;
  107. },
  108. <span id='Ext-Element-method-removeClass'> /**
  109. </span> * Removes one or more CSS classes from the element.
  110. * @param {String/Array} className The CSS class to remove, or an array of classes
  111. * @return {Ext.Element} this
  112. */
  113. removeClass : function(className){
  114. var me = this,
  115. i,
  116. idx,
  117. len,
  118. cls,
  119. elClasses;
  120. if (!Ext.isArray(className)){
  121. className = [className];
  122. }
  123. if (me.dom &amp;&amp; me.dom.className) {
  124. elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
  125. for (i = 0, len = className.length; i &lt; len; i++) {
  126. cls = className[i];
  127. if (typeof cls == 'string') {
  128. cls = cls.replace(trimRe, '');
  129. idx = elClasses.indexOf(cls);
  130. if (idx != -1) {
  131. elClasses.splice(idx, 1);
  132. }
  133. }
  134. }
  135. me.dom.className = elClasses.join(&quot; &quot;);
  136. }
  137. return me;
  138. },
  139. <span id='Ext-Element-method-radioClass'> /**
  140. </span> * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  141. * @param {String/Array} className The CSS class to add, or an array of classes
  142. * @return {Ext.Element} this
  143. */
  144. radioClass : function(className){
  145. var cn = this.dom.parentNode.childNodes,
  146. v,
  147. i,
  148. len;
  149. className = Ext.isArray(className) ? className : [className];
  150. for (i = 0, len = cn.length; i &lt; len; i++) {
  151. v = cn[i];
  152. if (v &amp;&amp; v.nodeType == 1) {
  153. Ext.fly(v, '_internal').removeClass(className);
  154. }
  155. };
  156. return this.addClass(className);
  157. },
  158. <span id='Ext-Element-method-toggleClass'> /**
  159. </span> * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  160. * @param {String} className The CSS class to toggle
  161. * @return {Ext.Element} this
  162. */
  163. toggleClass : function(className){
  164. return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  165. },
  166. <span id='Ext-Element-method-hasClass'> /**
  167. </span> * Checks if the specified CSS class exists on this element's DOM node.
  168. * @param {String} className The CSS class to check for
  169. * @return {Boolean} True if the class exists, else false
  170. */
  171. hasClass : function(className){
  172. return className &amp;&amp; (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
  173. },
  174. <span id='Ext-Element-method-replaceClass'> /**
  175. </span> * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  176. * @param {String} oldClassName The CSS class to replace
  177. * @param {String} newClassName The replacement CSS class
  178. * @return {Ext.Element} this
  179. */
  180. replaceClass : function(oldClassName, newClassName){
  181. return this.removeClass(oldClassName).addClass(newClassName);
  182. },
  183. isStyle : function(style, val) {
  184. return this.getStyle(style) == val;
  185. },
  186. <span id='Ext-Element-method-getStyle'> /**
  187. </span> * Normalizes currentStyle and computedStyle.
  188. * @param {String} property The style property whose value is returned.
  189. * @return {String} The current value of the style property for this element.
  190. */
  191. getStyle : function(){
  192. return view &amp;&amp; view.getComputedStyle ?
  193. function(prop){
  194. var el = this.dom,
  195. v,
  196. cs,
  197. out,
  198. display;
  199. if(el == document){
  200. return null;
  201. }
  202. prop = chkCache(prop);
  203. out = (v = el.style[prop]) ? v :
  204. (cs = view.getComputedStyle(el, &quot;&quot;)) ? cs[prop] : null;
  205. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  206. // numbers larger.
  207. if(prop == 'marginRight' &amp;&amp; out != '0px' &amp;&amp; !supports.correctRightMargin){
  208. display = el.style.display;
  209. el.style.display = 'inline-block';
  210. out = view.getComputedStyle(el, '').marginRight;
  211. el.style.display = display;
  212. }
  213. if(prop == 'backgroundColor' &amp;&amp; out == 'rgba(0, 0, 0, 0)' &amp;&amp; !supports.correctTransparentColor){
  214. out = 'transparent';
  215. }
  216. return out;
  217. } :
  218. function(prop){
  219. var el = this.dom,
  220. m,
  221. cs;
  222. if(el == document) return null;
  223. if (prop == 'opacity') {
  224. if (el.style.filter.match) {
  225. if(m = el.style.filter.match(opacityRe)){
  226. var fv = parseFloat(m[1]);
  227. if(!isNaN(fv)){
  228. return fv ? fv / 100 : 0;
  229. }
  230. }
  231. }
  232. return 1;
  233. }
  234. prop = chkCache(prop);
  235. return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
  236. };
  237. }(),
  238. <span id='Ext-Element-method-getColor'> /**
  239. </span> * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
  240. * are convert to standard 6 digit hex color.
  241. * @param {String} attr The css attribute
  242. * @param {String} defaultValue The default value to use when a valid color isn't found
  243. * @param {String} prefix (optional) defaults to #. Use an empty string when working with
  244. * color anims.
  245. */
  246. getColor : function(attr, defaultValue, prefix){
  247. var v = this.getStyle(attr),
  248. color = (typeof prefix != 'undefined') ? prefix : '#',
  249. h;
  250. if(!v || (/transparent|inherit/.test(v))) {
  251. return defaultValue;
  252. }
  253. if(/^r/.test(v)){
  254. Ext.each(v.slice(4, v.length -1).split(','), function(s){
  255. h = parseInt(s, 10);
  256. color += (h &lt; 16 ? '0' : '') + h.toString(16);
  257. });
  258. }else{
  259. v = v.replace('#', '');
  260. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  261. }
  262. return(color.length &gt; 5 ? color.toLowerCase() : defaultValue);
  263. },
  264. <span id='Ext-Element-method-setStyle'> /**
  265. </span> * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  266. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  267. * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
  268. * @return {Ext.Element} this
  269. */
  270. setStyle : function(prop, value){
  271. var tmp, style;
  272. if (typeof prop != 'object') {
  273. tmp = {};
  274. tmp[prop] = value;
  275. prop = tmp;
  276. }
  277. for (style in prop) {
  278. value = prop[style];
  279. style == 'opacity' ?
  280. this.setOpacity(value) :
  281. this.dom.style[chkCache(style)] = value;
  282. }
  283. return this;
  284. },
  285. <span id='Ext-Element-method-setOpacity'> /**
  286. </span> * Set the opacity of the element
  287. * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  288. * @param {Boolean/Object} animate (optional) a standard Element animation config object or &lt;tt&gt;true&lt;/tt&gt; for
  289. * the default animation (&lt;tt&gt;{duration: .35, easing: 'easeIn'}&lt;/tt&gt;)
  290. * @return {Ext.Element} this
  291. */
  292. setOpacity : function(opacity, animate){
  293. var me = this,
  294. s = me.dom.style;
  295. if(!animate || !me.anim){
  296. if(Ext.isIE9m){
  297. var opac = opacity &lt; 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
  298. val = s.filter.replace(opacityRe, '').replace(trimRe, '');
  299. s.zoom = 1;
  300. s.filter = val + (val.length &gt; 0 ? ' ' : '') + opac;
  301. }else{
  302. s.opacity = opacity;
  303. }
  304. }else{
  305. me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
  306. }
  307. return me;
  308. },
  309. <span id='Ext-Element-method-clearOpacity'> /**
  310. </span> * Clears any opacity settings from this element. Required in some cases for IE.
  311. * @return {Ext.Element} this
  312. */
  313. clearOpacity : function(){
  314. var style = this.dom.style;
  315. if(Ext.isIE9m){
  316. if(!Ext.isEmpty(style.filter)){
  317. style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
  318. }
  319. }else{
  320. style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
  321. }
  322. return this;
  323. },
  324. <span id='Ext-Element-method-getHeight'> /**
  325. </span> * Returns the offset height of the element
  326. * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
  327. * @return {Number} The element's height
  328. */
  329. getHeight : function(contentHeight){
  330. var me = this,
  331. dom = me.dom,
  332. hidden = Ext.isIE9m &amp;&amp; me.isStyle('display', 'none'),
  333. h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
  334. h = !contentHeight ? h : h - me.getBorderWidth(&quot;tb&quot;) - me.getPadding(&quot;tb&quot;);
  335. return h &lt; 0 ? 0 : h;
  336. },
  337. <span id='Ext-Element-method-getWidth'> /**
  338. </span> * Returns the offset width of the element
  339. * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
  340. * @return {Number} The element's width
  341. */
  342. getWidth : function(contentWidth){
  343. var me = this,
  344. dom = me.dom,
  345. hidden = Ext.isIE9m &amp;&amp; me.isStyle('display', 'none'),
  346. w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
  347. w = !contentWidth ? w : w - me.getBorderWidth(&quot;lr&quot;) - me.getPadding(&quot;lr&quot;);
  348. return w &lt; 0 ? 0 : w;
  349. },
  350. <span id='Ext-Element-method-setWidth'> /**
  351. </span> * Set the width of this Element.
  352. * @param {Mixed} width The new width. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  353. * &lt;li&gt;A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).&lt;/li&gt;
  354. * &lt;li&gt;A String used to set the CSS width style. Animation may &lt;b&gt;not&lt;/b&gt; be used.
  355. * &lt;/ul&gt;&lt;/div&gt;
  356. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  357. * @return {Ext.Element} this
  358. */
  359. setWidth : function(width, animate){
  360. var me = this;
  361. width = me.adjustWidth(width);
  362. !animate || !me.anim ?
  363. me.dom.style.width = me.addUnits(width) :
  364. me.anim({width : {to : width}}, me.preanim(arguments, 1));
  365. return me;
  366. },
  367. <span id='Ext-Element-method-setHeight'> /**
  368. </span> * Set the height of this Element.
  369. * &lt;pre&gt;&lt;code&gt;
  370. // change the height to 200px and animate with default configuration
  371. Ext.fly('elementId').setHeight(200, true);
  372. // change the height to 150px and animate with a custom configuration
  373. Ext.fly('elId').setHeight(150, {
  374. duration : .5, // animation will have a duration of .5 seconds
  375. // will change the content to &quot;finished&quot;
  376. callback: function(){ this.{@link #update}(&quot;finished&quot;); }
  377. });
  378. * &lt;/code&gt;&lt;/pre&gt;
  379. * @param {Mixed} height The new height. This may be one of:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  380. * &lt;li&gt;A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)&lt;/li&gt;
  381. * &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;
  382. * &lt;/ul&gt;&lt;/div&gt;
  383. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  384. * @return {Ext.Element} this
  385. */
  386. setHeight : function(height, animate){
  387. var me = this;
  388. height = me.adjustHeight(height);
  389. !animate || !me.anim ?
  390. me.dom.style.height = me.addUnits(height) :
  391. me.anim({height : {to : height}}, me.preanim(arguments, 1));
  392. return me;
  393. },
  394. <span id='Ext-Element-method-getBorderWidth'> /**
  395. </span> * Gets the width of the border(s) for the specified side(s)
  396. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  397. * passing &lt;tt&gt;'lr'&lt;/tt&gt; would get the border &lt;b&gt;&lt;u&gt;l&lt;/u&gt;&lt;/b&gt;eft width + the border &lt;b&gt;&lt;u&gt;r&lt;/u&gt;&lt;/b&gt;ight width.
  398. * @return {Number} The width of the sides passed added together
  399. */
  400. getBorderWidth : function(side){
  401. return this.addStyles(side, borders);
  402. },
  403. <span id='Ext-Element-method-getPadding'> /**
  404. </span> * Gets the width of the padding(s) for the specified side(s)
  405. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  406. * passing &lt;tt&gt;'lr'&lt;/tt&gt; would get the padding &lt;b&gt;&lt;u&gt;l&lt;/u&gt;&lt;/b&gt;eft + the padding &lt;b&gt;&lt;u&gt;r&lt;/u&gt;&lt;/b&gt;ight.
  407. * @return {Number} The padding of the sides passed added together
  408. */
  409. getPadding : function(side){
  410. return this.addStyles(side, paddings);
  411. },
  412. <span id='Ext-Element-method-clip'> /**
  413. </span> * Store the current overflow setting and clip overflow on the element - use &lt;tt&gt;{@link #unclip}&lt;/tt&gt; to remove
  414. * @return {Ext.Element} this
  415. */
  416. clip : function(){
  417. var me = this,
  418. dom = me.dom;
  419. if(!data(dom, ISCLIPPED)){
  420. data(dom, ISCLIPPED, true);
  421. data(dom, ORIGINALCLIP, {
  422. o: me.getStyle(OVERFLOW),
  423. x: me.getStyle(OVERFLOWX),
  424. y: me.getStyle(OVERFLOWY)
  425. });
  426. me.setStyle(OVERFLOW, HIDDEN);
  427. me.setStyle(OVERFLOWX, HIDDEN);
  428. me.setStyle(OVERFLOWY, HIDDEN);
  429. }
  430. return me;
  431. },
  432. <span id='Ext-Element-method-unclip'> /**
  433. </span> * Return clipping (overflow) to original clipping before &lt;tt&gt;{@link #clip}&lt;/tt&gt; was called
  434. * @return {Ext.Element} this
  435. */
  436. unclip : function(){
  437. var me = this,
  438. dom = me.dom;
  439. if(data(dom, ISCLIPPED)){
  440. data(dom, ISCLIPPED, false);
  441. var o = data(dom, ORIGINALCLIP);
  442. if(o.o){
  443. me.setStyle(OVERFLOW, o.o);
  444. }
  445. if(o.x){
  446. me.setStyle(OVERFLOWX, o.x);
  447. }
  448. if(o.y){
  449. me.setStyle(OVERFLOWY, o.y);
  450. }
  451. }
  452. return me;
  453. },
  454. // private
  455. addStyles : function(sides, styles){
  456. var ttlSize = 0,
  457. sidesArr = sides.match(wordsRe),
  458. side,
  459. size,
  460. i,
  461. len = sidesArr.length;
  462. for (i = 0; i &lt; len; i++) {
  463. side = sidesArr[i];
  464. size = side &amp;&amp; parseInt(this.getStyle(styles[side]), 10);
  465. if (size) {
  466. ttlSize += MATH.abs(size);
  467. }
  468. }
  469. return ttlSize;
  470. },
  471. margins : margins
  472. };
  473. }()
  474. );
  475. </pre>
  476. </body>
  477. </html>