/javascripts/lib/docs/source/Element.fx.html

https://bitbucket.org/ksokmesa/sina-asian · HTML · 368 lines · 352 code · 16 blank · 0 comment · 0 complexity · df4833b27f8609c29287ebccc8eb3964 MD5 · raw file

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.2.1
  11. * Copyright(c) 2006-2010 Ext JS, Inc.
  12. * licensing@extjs.com
  13. * http://www.extjs.com/license
  14. */
  15. /**
  16. * @class Ext.Element
  17. */
  18. <div id="prop-Ext.Element-VISIBILITY"></div>/**
  19. * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
  20. * @static
  21. * @type Number
  22. */
  23. Ext.Element.VISIBILITY = 1;
  24. <div id="prop-Ext.Element-DISPLAY"></div>/**
  25. * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
  26. * @static
  27. * @type Number
  28. */
  29. Ext.Element.DISPLAY = 2;
  30. Ext.Element.addMethods(function(){
  31. var VISIBILITY = "visibility",
  32. DISPLAY = "display",
  33. HIDDEN = "hidden",
  34. OFFSETS = "offsets",
  35. NONE = "none",
  36. ORIGINALDISPLAY = 'originalDisplay',
  37. VISMODE = 'visibilityMode',
  38. ELDISPLAY = Ext.Element.DISPLAY,
  39. data = Ext.Element.data,
  40. getDisplay = function(dom){
  41. var d = data(dom, ORIGINALDISPLAY);
  42. if(d === undefined){
  43. data(dom, ORIGINALDISPLAY, d = '');
  44. }
  45. return d;
  46. },
  47. getVisMode = function(dom){
  48. var m = data(dom, VISMODE);
  49. if(m === undefined){
  50. data(dom, VISMODE, m = 1);
  51. }
  52. return m;
  53. };
  54. return {
  55. <div id="prop-Ext.Element-originalDisplay"></div>/**
  56. * The element's default display mode (defaults to "")
  57. * @type String
  58. */
  59. originalDisplay : "",
  60. visibilityMode : 1,
  61. <div id="method-Ext.Element-setVisibilityMode"></div>/**
  62. * Sets the element's visibility mode. When setVisible() is called it
  63. * will use this to determine whether to set the visibility or the display property.
  64. * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
  65. * @return {Ext.Element} this
  66. */
  67. setVisibilityMode : function(visMode){
  68. data(this.dom, VISMODE, visMode);
  69. return this;
  70. },
  71. <div id="method-Ext.Element-animate"></div>/**
  72. * Perform custom animation on this element.
  73. * <div><ul class="mdetail-params">
  74. * <li><u>Animation Properties</u></li>
  75. *
  76. * <p>The Animation Control Object enables gradual transitions for any member of an
  77. * element's style object that takes a numeric value including but not limited to
  78. * these properties:</p><div><ul class="mdetail-params">
  79. * <li><tt>bottom, top, left, right</tt></li>
  80. * <li><tt>height, width</tt></li>
  81. * <li><tt>margin, padding</tt></li>
  82. * <li><tt>borderWidth</tt></li>
  83. * <li><tt>opacity</tt></li>
  84. * <li><tt>fontSize</tt></li>
  85. * <li><tt>lineHeight</tt></li>
  86. * </ul></div>
  87. *
  88. *
  89. * <li><u>Animation Property Attributes</u></li>
  90. *
  91. * <p>Each Animation Property is a config object with optional properties:</p>
  92. * <div><ul class="mdetail-params">
  93. * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
  94. * <li><tt>from</tt> : ignore current value, start from this value</li>
  95. * <li><tt>to</tt>* : start at current value, go to this value</li>
  96. * <li><tt>unit</tt> : any allowable unit specification</li>
  97. * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
  98. * </ul></div>
  99. *
  100. * <li><u>Animation Types</u></li>
  101. *
  102. * <p>The supported animation types:</p><div><ul class="mdetail-params">
  103. * <li><tt>'run'</tt> : Default
  104. * <pre><code>
  105. var el = Ext.get('complexEl');
  106. el.animate(
  107. // animation control object
  108. {
  109. borderWidth: {to: 3, from: 0},
  110. opacity: {to: .3, from: 1},
  111. height: {to: 50, from: el.getHeight()},
  112. width: {to: 300, from: el.getWidth()},
  113. top : {by: - 100, unit: 'px'},
  114. },
  115. 0.35, // animation duration
  116. null, // callback
  117. 'easeOut', // easing method
  118. 'run' // animation type ('run','color','motion','scroll')
  119. );
  120. * </code></pre>
  121. * </li>
  122. * <li><tt>'color'</tt>
  123. * <p>Animates transition of background, text, or border colors.</p>
  124. * <pre><code>
  125. el.animate(
  126. // animation control object
  127. {
  128. color: { to: '#06e' },
  129. backgroundColor: { to: '#e06' }
  130. },
  131. 0.35, // animation duration
  132. null, // callback
  133. 'easeOut', // easing method
  134. 'color' // animation type ('run','color','motion','scroll')
  135. );
  136. * </code></pre>
  137. * </li>
  138. *
  139. * <li><tt>'motion'</tt>
  140. * <p>Animates the motion of an element to/from specific points using optional bezier
  141. * way points during transit.</p>
  142. * <pre><code>
  143. el.animate(
  144. // animation control object
  145. {
  146. borderWidth: {to: 3, from: 0},
  147. opacity: {to: .3, from: 1},
  148. height: {to: 50, from: el.getHeight()},
  149. width: {to: 300, from: el.getWidth()},
  150. top : {by: - 100, unit: 'px'},
  151. points: {
  152. to: [50, 100], // go to this point
  153. control: [ // optional bezier way points
  154. [ 600, 800],
  155. [-100, 200]
  156. ]
  157. }
  158. },
  159. 3000, // animation duration (milliseconds!)
  160. null, // callback
  161. 'easeOut', // easing method
  162. 'motion' // animation type ('run','color','motion','scroll')
  163. );
  164. * </code></pre>
  165. * </li>
  166. * <li><tt>'scroll'</tt>
  167. * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
  168. * <pre><code>
  169. el.animate(
  170. // animation control object
  171. {
  172. scroll: {to: [400, 300]}
  173. },
  174. 0.35, // animation duration
  175. null, // callback
  176. 'easeOut', // easing method
  177. 'scroll' // animation type ('run','color','motion','scroll')
  178. );
  179. * </code></pre>
  180. * </li>
  181. * </ul></div>
  182. *
  183. * </ul></div>
  184. *
  185. * @param {Object} args The animation control args
  186. * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
  187. * @param {Function} onComplete (optional) Function to call when animation completes
  188. * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
  189. * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
  190. * <tt>'motion'</tt>, or <tt>'scroll'</tt>
  191. * @return {Ext.Element} this
  192. */
  193. animate : function(args, duration, onComplete, easing, animType){
  194. this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
  195. return this;
  196. },
  197. /*
  198. * @private Internal animation call
  199. */
  200. anim : function(args, opt, animType, defaultDur, defaultEase, cb){
  201. animType = animType || 'run';
  202. opt = opt || {};
  203. var me = this,
  204. anim = Ext.lib.Anim[animType](
  205. me.dom,
  206. args,
  207. (opt.duration || defaultDur) || .35,
  208. (opt.easing || defaultEase) || 'easeOut',
  209. function(){
  210. if(cb) cb.call(me);
  211. if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
  212. },
  213. me
  214. );
  215. opt.anim = anim;
  216. return anim;
  217. },
  218. // private legacy anim prep
  219. preanim : function(a, i){
  220. return !a[i] ? false : (typeof a[i] == 'object' ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
  221. },
  222. <div id="method-Ext.Element-isVisible"></div>/**
  223. * Checks whether the element is currently visible using both visibility and display properties.
  224. * @return {Boolean} True if the element is currently visible, else false
  225. */
  226. isVisible : function() {
  227. return !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE);
  228. },
  229. <div id="method-Ext.Element-setVisible"></div>/**
  230. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  231. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  232. * @param {Boolean} visible Whether the element is visible
  233. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  234. * @return {Ext.Element} this
  235. */
  236. setVisible : function(visible, animate){
  237. var me = this, isDisplay, isVisible, isOffsets,
  238. dom = me.dom;
  239. // hideMode string override
  240. if (typeof animate == 'string'){
  241. isDisplay = animate == DISPLAY;
  242. isVisible = animate == VISIBILITY;
  243. isOffsets = animate == OFFSETS;
  244. animate = false;
  245. } else {
  246. isDisplay = getVisMode(this.dom) == ELDISPLAY;
  247. isVisible = !isDisplay;
  248. }
  249. if (!animate || !me.anim) {
  250. if (isDisplay){
  251. me.setDisplayed(visible);
  252. } else if (isOffsets){
  253. if (!visible){
  254. me.hideModeStyles = {
  255. position: me.getStyle('position'),
  256. top: me.getStyle('top'),
  257. left: me.getStyle('left')
  258. };
  259. me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
  260. } else {
  261. me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
  262. }
  263. }else{
  264. me.fixDisplay();
  265. dom.style.visibility = visible ? "visible" : HIDDEN;
  266. }
  267. }else{
  268. // closure for composites
  269. if (visible){
  270. me.setOpacity(.01);
  271. me.setVisible(true);
  272. }
  273. me.anim({opacity: { to: (visible?1:0) }},
  274. me.preanim(arguments, 1),
  275. null,
  276. .35,
  277. 'easeIn',
  278. function(){
  279. if(!visible){
  280. dom.style[isDisplay ? DISPLAY : VISIBILITY] = (isDisplay) ? NONE : HIDDEN;
  281. Ext.fly(dom).setOpacity(1);
  282. }
  283. });
  284. }
  285. return me;
  286. },
  287. <div id="method-Ext.Element-toggle"></div>/**
  288. * Toggles the element's visibility or display, depending on visibility mode.
  289. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  290. * @return {Ext.Element} this
  291. */
  292. toggle : function(animate){
  293. var me = this;
  294. me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
  295. return me;
  296. },
  297. <div id="method-Ext.Element-setDisplayed"></div>/**
  298. * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
  299. * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
  300. * @return {Ext.Element} this
  301. */
  302. setDisplayed : function(value) {
  303. if(typeof value == "boolean"){
  304. value = value ? getDisplay(this.dom) : NONE;
  305. }
  306. this.setStyle(DISPLAY, value);
  307. return this;
  308. },
  309. // private
  310. fixDisplay : function(){
  311. var me = this;
  312. if(me.isStyle(DISPLAY, NONE)){
  313. me.setStyle(VISIBILITY, HIDDEN);
  314. me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
  315. if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
  316. me.setStyle(DISPLAY, "block");
  317. }
  318. }
  319. },
  320. <div id="method-Ext.Element-hide"></div>/**
  321. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  322. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  323. * @return {Ext.Element} this
  324. */
  325. hide : function(animate){
  326. // hideMode override
  327. if (typeof animate == 'string'){
  328. this.setVisible(false, animate);
  329. return this;
  330. }
  331. this.setVisible(false, this.preanim(arguments, 0));
  332. return this;
  333. },
  334. <div id="method-Ext.Element-show"></div>/**
  335. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  336. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  337. * @return {Ext.Element} this
  338. */
  339. show : function(animate){
  340. // hideMode override
  341. if (typeof animate == 'string'){
  342. this.setVisible(true, animate);
  343. return this;
  344. }
  345. this.setVisible(true, this.preanim(arguments, 0));
  346. return this;
  347. }
  348. };
  349. }());
  350. </pre>
  351. </body>
  352. </html>