Element.anim.html 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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-dom-Element'>/**
  19. </span> * @class Ext.dom.Element
  20. */
  21. /* ================================
  22. * A Note About Wrapped Animations
  23. * ================================
  24. * A few of the effects below implement two different animations per effect, one wrapping
  25. * animation that performs the visual effect and a &quot;no-op&quot; animation on this Element where
  26. * no attributes of the element itself actually change. The purpose for this is that the
  27. * wrapper is required for the effect to work and so it does the actual animation work, but
  28. * we always animate `this` so that the element's events and callbacks work as expected to
  29. * the callers of this API.
  30. *
  31. * Because of this, we always want each wrap animation to complete first (we don't want to
  32. * cut off the visual effect early). To ensure that, we arbitrarily increase the duration of
  33. * the element's no-op animation, also ensuring that it has a decent minimum value -- on slow
  34. * systems, too-low durations can cause race conditions between the wrap animation and the
  35. * element animation being removed out of order. Note that in each wrap's `afteranimate`
  36. * callback it will explicitly terminate the element animation as soon as the wrap is complete,
  37. * so there's no real danger in making the duration too long.
  38. *
  39. * This applies to all effects that get wrapped, including slideIn, slideOut, switchOff and frame.
  40. */
  41. Ext.dom.Element.override({
  42. <span id='Ext-dom-Element-method-animate'> /**
  43. </span> * Performs custom animation on this Element.
  44. *
  45. * The following properties may be specified in `from`, `to`, and `keyframe` objects:
  46. *
  47. * - `x` - The page X position in pixels.
  48. *
  49. * - `y` - The page Y position in pixels
  50. *
  51. * - `left` - The element's CSS `left` value. Units must be supplied.
  52. *
  53. * - `top` - The element's CSS `top` value. Units must be supplied.
  54. *
  55. * - `width` - The element's CSS `width` value. Units must be supplied.
  56. *
  57. * - `height` - The element's CSS `height` value. Units must be supplied.
  58. *
  59. * - `scrollLeft` - The element's `scrollLeft` value.
  60. *
  61. * - `scrollTop` - The element's `scrollTop` value.
  62. *
  63. * - `opacity` - The element's `opacity` value. This must be a value between `0` and `1`.
  64. *
  65. * **Be aware** that animating an Element which is being used by an Ext Component without in some way informing the
  66. * Component about the changed element state will result in incorrect Component behaviour. This is because the
  67. * Component will be using the old state of the element. To avoid this problem, it is now possible to directly
  68. * animate certain properties of Components.
  69. *
  70. * @param {Object} config Configuration for {@link Ext.fx.Anim}.
  71. * Note that the {@link Ext.fx.Anim#to to} config is required.
  72. * @return {Ext.dom.Element} this
  73. */
  74. animate: function(config) {
  75. var me = this,
  76. listeners,
  77. anim,
  78. animId = me.dom.id || Ext.id(me.dom);
  79. if (!Ext.fx.Manager.hasFxBlock(animId)) {
  80. // Bit of gymnastics here to ensure our internal listeners get bound first
  81. if (config.listeners) {
  82. listeners = config.listeners;
  83. delete config.listeners;
  84. }
  85. if (config.internalListeners) {
  86. config.listeners = config.internalListeners;
  87. delete config.internalListeners;
  88. }
  89. anim = new Ext.fx.Anim(me.anim(config));
  90. if (listeners) {
  91. anim.on(listeners);
  92. }
  93. Ext.fx.Manager.queueFx(anim);
  94. }
  95. return me;
  96. },
  97. // @private - process the passed fx configuration.
  98. anim: function(config) {
  99. if (!Ext.isObject(config)) {
  100. return (config) ? {} : false;
  101. }
  102. var me = this,
  103. duration = config.duration || Ext.fx.Anim.prototype.duration,
  104. easing = config.easing || 'ease',
  105. animConfig;
  106. if (config.stopAnimation) {
  107. me.stopAnimation();
  108. }
  109. Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id));
  110. // Clear any 'paused' defaults.
  111. Ext.fx.Manager.setFxDefaults(me.id, {
  112. delay: 0
  113. });
  114. animConfig = {
  115. // Pass the DOM reference. That's tested first so will be converted to an Ext.fx.Target fastest.
  116. target: me.dom,
  117. remove: config.remove,
  118. alternate: config.alternate || false,
  119. duration: duration,
  120. easing: easing,
  121. callback: config.callback,
  122. listeners: config.listeners,
  123. iterations: config.iterations || 1,
  124. scope: config.scope,
  125. block: config.block,
  126. concurrent: config.concurrent,
  127. delay: config.delay || 0,
  128. paused: true,
  129. keyframes: config.keyframes,
  130. from: config.from || {},
  131. to: Ext.apply({}, config)
  132. };
  133. Ext.apply(animConfig.to, config.to);
  134. // Anim API properties - backward compat
  135. delete animConfig.to.to;
  136. delete animConfig.to.from;
  137. delete animConfig.to.remove;
  138. delete animConfig.to.alternate;
  139. delete animConfig.to.keyframes;
  140. delete animConfig.to.iterations;
  141. delete animConfig.to.listeners;
  142. delete animConfig.to.target;
  143. delete animConfig.to.paused;
  144. delete animConfig.to.callback;
  145. delete animConfig.to.scope;
  146. delete animConfig.to.duration;
  147. delete animConfig.to.easing;
  148. delete animConfig.to.concurrent;
  149. delete animConfig.to.block;
  150. delete animConfig.to.stopAnimation;
  151. delete animConfig.to.delay;
  152. return animConfig;
  153. },
  154. <span id='Ext-dom-Element-method-slideIn'> /**
  155. </span> * Slides the element into view. An anchor point can be optionally passed to set the point of origin for the slide
  156. * effect. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  157. * Fx class overview for valid anchor point options. Usage:
  158. *
  159. * // default: slide the element in from the top
  160. * el.slideIn();
  161. *
  162. * // custom: slide the element in from the right with a 2-second duration
  163. * el.slideIn('r', { duration: 2000 });
  164. *
  165. * // common config options shown with default values
  166. * el.slideIn('t', {
  167. * easing: 'easeOut',
  168. * duration: 500
  169. * });
  170. *
  171. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  172. * @param {Object} options (optional) Object literal with any of the Fx config options
  173. * @param {Boolean} options.preserveScroll Set to true if preservation of any descendant elements'
  174. * `scrollTop` values is required. By default the DOM wrapping operation performed by `slideIn` and
  175. * `slideOut` causes the browser to lose all scroll positions.
  176. * @return {Ext.dom.Element} The Element
  177. */
  178. slideIn: function(anchor, obj, slideOut) {
  179. var me = this,
  180. elStyle = me.dom.style,
  181. beforeAnim,
  182. wrapAnim,
  183. restoreScroll,
  184. wrapDomParentNode;
  185. anchor = anchor || &quot;t&quot;;
  186. obj = obj || {};
  187. beforeAnim = function() {
  188. var animScope = this,
  189. listeners = obj.listeners,
  190. box, originalStyles, anim, wrap;
  191. if (!slideOut) {
  192. me.fixDisplay();
  193. }
  194. box = me.getBox();
  195. if ((anchor == 't' || anchor == 'b') &amp;&amp; box.height === 0) {
  196. box.height = me.dom.scrollHeight;
  197. }
  198. else if ((anchor == 'l' || anchor == 'r') &amp;&amp; box.width === 0) {
  199. box.width = me.dom.scrollWidth;
  200. }
  201. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', true);
  202. me.setSize(box.width, box.height);
  203. // Cache all descendants' scrollTop &amp; scrollLeft values if configured to preserve scroll.
  204. if (obj.preserveScroll) {
  205. restoreScroll = me.cacheScrollValues();
  206. }
  207. wrap = me.wrap({
  208. id: Ext.id() + '-anim-wrap-for-' + me.id,
  209. style: {
  210. visibility: slideOut ? 'visible' : 'hidden'
  211. }
  212. });
  213. wrapDomParentNode = wrap.dom.parentNode;
  214. wrap.setPositioning(me.getPositioning());
  215. if (wrap.isStyle('position', 'static')) {
  216. wrap.position('relative');
  217. }
  218. me.clearPositioning('auto');
  219. wrap.clip();
  220. // The wrap will have reset all descendant scrollTops. Restore them if we cached them.
  221. if (restoreScroll) {
  222. restoreScroll();
  223. }
  224. // This element is temporarily positioned absolute within its wrapper.
  225. // Restore to its default, CSS-inherited visibility setting.
  226. // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap.
  227. me.setStyle({
  228. visibility: '',
  229. position: 'absolute'
  230. });
  231. if (slideOut) {
  232. wrap.setSize(box.width, box.height);
  233. }
  234. switch (anchor) {
  235. case 't':
  236. anim = {
  237. from: {
  238. width: box.width + 'px',
  239. height: '0px'
  240. },
  241. to: {
  242. width: box.width + 'px',
  243. height: box.height + 'px'
  244. }
  245. };
  246. elStyle.bottom = '0px';
  247. break;
  248. case 'l':
  249. anim = {
  250. from: {
  251. width: '0px',
  252. height: box.height + 'px'
  253. },
  254. to: {
  255. width: box.width + 'px',
  256. height: box.height + 'px'
  257. }
  258. };
  259. elStyle.right = '0px';
  260. break;
  261. case 'r':
  262. anim = {
  263. from: {
  264. x: box.x + box.width,
  265. width: '0px',
  266. height: box.height + 'px'
  267. },
  268. to: {
  269. x: box.x,
  270. width: box.width + 'px',
  271. height: box.height + 'px'
  272. }
  273. };
  274. break;
  275. case 'b':
  276. anim = {
  277. from: {
  278. y: box.y + box.height,
  279. width: box.width + 'px',
  280. height: '0px'
  281. },
  282. to: {
  283. y: box.y,
  284. width: box.width + 'px',
  285. height: box.height + 'px'
  286. }
  287. };
  288. break;
  289. case 'tl':
  290. anim = {
  291. from: {
  292. x: box.x,
  293. y: box.y,
  294. width: '0px',
  295. height: '0px'
  296. },
  297. to: {
  298. width: box.width + 'px',
  299. height: box.height + 'px'
  300. }
  301. };
  302. elStyle.bottom = '0px';
  303. elStyle.right = '0px';
  304. break;
  305. case 'bl':
  306. anim = {
  307. from: {
  308. y: box.y + box.height,
  309. width: '0px',
  310. height: '0px'
  311. },
  312. to: {
  313. y: box.y,
  314. width: box.width + 'px',
  315. height: box.height + 'px'
  316. }
  317. };
  318. elStyle.bottom = '0px';
  319. break;
  320. case 'br':
  321. anim = {
  322. from: {
  323. x: box.x + box.width,
  324. y: box.y + box.height,
  325. width: '0px',
  326. height: '0px'
  327. },
  328. to: {
  329. x: box.x,
  330. y: box.y,
  331. width: box.width + 'px',
  332. height: box.height + 'px'
  333. }
  334. };
  335. break;
  336. case 'tr':
  337. anim = {
  338. from: {
  339. x: box.x + box.width,
  340. width: '0px',
  341. height: '0px'
  342. },
  343. to: {
  344. x: box.x,
  345. width: box.width + 'px',
  346. height: box.height + 'px'
  347. }
  348. };
  349. elStyle.right = '0px';
  350. break;
  351. }
  352. wrap.show();
  353. wrapAnim = Ext.apply({}, obj);
  354. delete wrapAnim.listeners;
  355. wrapAnim = new Ext.fx.Anim(Ext.applyIf(wrapAnim, {
  356. target: wrap,
  357. duration: 500,
  358. easing: 'ease-out',
  359. from: slideOut ? anim.to : anim.from,
  360. to: slideOut ? anim.from : anim.to
  361. }));
  362. // In the absence of a callback, this listener MUST be added first
  363. wrapAnim.on('afteranimate', function() {
  364. me.setStyle(originalStyles);
  365. if (slideOut) {
  366. if (obj.useDisplay) {
  367. me.setDisplayed(false);
  368. } else {
  369. me.hide();
  370. }
  371. }
  372. if (wrap.dom) {
  373. if (wrap.dom.parentNode) {
  374. wrap.dom.parentNode.insertBefore(me.dom, wrap.dom);
  375. } else {
  376. wrapDomParentNode.appendChild(me.dom);
  377. }
  378. wrap.remove();
  379. }
  380. // The unwrap will have reset all descendant scrollTops. Restore them if we cached them.
  381. if (restoreScroll) {
  382. restoreScroll();
  383. }
  384. // kill the no-op element animation created below
  385. animScope.end();
  386. });
  387. // Add configured listeners after
  388. if (listeners) {
  389. wrapAnim.on(listeners);
  390. }
  391. };
  392. me.animate({
  393. // See &quot;A Note About Wrapped Animations&quot; at the top of this class:
  394. duration: obj.duration ? Math.max(obj.duration, 500) * 2 : 1000,
  395. listeners: {
  396. beforeanimate: beforeAnim // kick off the wrap animation
  397. }
  398. });
  399. return me;
  400. },
  401. <span id='Ext-dom-Element-method-slideOut'> /**
  402. </span> * Slides the element out of view. An anchor point can be optionally passed to set the end point for the slide
  403. * effect. When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will
  404. * still take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  405. * desired. This function automatically handles wrapping the element with a fixed-size container if needed. See the
  406. * Fx class overview for valid anchor point options. Usage:
  407. *
  408. * // default: slide the element out to the top
  409. * el.slideOut();
  410. *
  411. * // custom: slide the element out to the right with a 2-second duration
  412. * el.slideOut('r', { duration: 2000 });
  413. *
  414. * // common config options shown with default values
  415. * el.slideOut('t', {
  416. * easing: 'easeOut',
  417. * duration: 500,
  418. * remove: false,
  419. * useDisplay: false
  420. * });
  421. *
  422. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  423. * @param {Object} options (optional) Object literal with any of the Fx config options
  424. * @return {Ext.dom.Element} The Element
  425. */
  426. slideOut: function(anchor, o) {
  427. return this.slideIn(anchor, o, true);
  428. },
  429. <span id='Ext-dom-Element-method-puff'> /**
  430. </span> * Fades the element out while slowly expanding it in all directions. When the effect is completed, the element will
  431. * be hidden (visibility = 'hidden') but block elements will still take up space in the document. Usage:
  432. *
  433. * // default
  434. * el.puff();
  435. *
  436. * // common config options shown with default values
  437. * el.puff({
  438. * easing: 'easeOut',
  439. * duration: 500,
  440. * useDisplay: false
  441. * });
  442. *
  443. * @param {Object} options (optional) Object literal with any of the Fx config options
  444. * @return {Ext.dom.Element} The Element
  445. */
  446. puff: function(obj) {
  447. var me = this,
  448. beforeAnim,
  449. box = me.getBox(),
  450. originalStyles = me.getStyles('width', 'height', 'left', 'right', 'top', 'bottom', 'position', 'z-index', 'font-size', 'opacity', true);
  451. obj = Ext.applyIf(obj || {}, {
  452. easing: 'ease-out',
  453. duration: 500,
  454. useDisplay: false
  455. });
  456. beforeAnim = function() {
  457. me.clearOpacity();
  458. me.show();
  459. this.to = {
  460. width: box.width * 2,
  461. height: box.height * 2,
  462. x: box.x - (box.width / 2),
  463. y: box.y - (box.height /2),
  464. opacity: 0,
  465. fontSize: '200%'
  466. };
  467. this.on('afteranimate',function() {
  468. if (me.dom) {
  469. if (obj.useDisplay) {
  470. me.setDisplayed(false);
  471. } else {
  472. me.hide();
  473. }
  474. me.setStyle(originalStyles);
  475. obj.callback.call(obj.scope);
  476. }
  477. });
  478. };
  479. me.animate({
  480. duration: obj.duration,
  481. easing: obj.easing,
  482. listeners: {
  483. beforeanimate: {
  484. fn: beforeAnim
  485. }
  486. }
  487. });
  488. return me;
  489. },
  490. <span id='Ext-dom-Element-method-switchOff'> /**
  491. </span> * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
  492. * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
  493. * take up space in the document. The element must be removed from the DOM using the 'remove' config option if
  494. * desired. Usage:
  495. *
  496. * // default
  497. * el.switchOff();
  498. *
  499. * // all config options shown with default values
  500. * el.switchOff({
  501. * easing: 'easeIn',
  502. * duration: .3,
  503. * remove: false,
  504. * useDisplay: false
  505. * });
  506. *
  507. * @param {Object} options (optional) Object literal with any of the Fx config options
  508. * @return {Ext.dom.Element} The Element
  509. */
  510. switchOff: function(obj) {
  511. var me = this,
  512. beforeAnim;
  513. obj = Ext.applyIf(obj || {}, {
  514. easing: 'ease-in',
  515. duration: 500,
  516. remove: false,
  517. useDisplay: false
  518. });
  519. beforeAnim = function() {
  520. var animScope = this,
  521. size = me.getSize(),
  522. xy = me.getXY(),
  523. keyframe, position;
  524. me.clearOpacity();
  525. me.clip();
  526. position = me.getPositioning();
  527. keyframe = new Ext.fx.Animator({
  528. target: me,
  529. duration: obj.duration,
  530. easing: obj.easing,
  531. keyframes: {
  532. 33: {
  533. opacity: 0.3
  534. },
  535. 66: {
  536. height: 1,
  537. y: xy[1] + size.height / 2
  538. },
  539. 100: {
  540. width: 1,
  541. x: xy[0] + size.width / 2
  542. }
  543. }
  544. });
  545. keyframe.on('afteranimate', function() {
  546. if (obj.useDisplay) {
  547. me.setDisplayed(false);
  548. } else {
  549. me.hide();
  550. }
  551. me.clearOpacity();
  552. me.setPositioning(position);
  553. me.setSize(size);
  554. // kill the no-op element animation created below
  555. animScope.end();
  556. });
  557. };
  558. me.animate({
  559. // See &quot;A Note About Wrapped Animations&quot; at the top of this class:
  560. duration: (Math.max(obj.duration, 500) * 2),
  561. listeners: {
  562. beforeanimate: {
  563. fn: beforeAnim
  564. }
  565. }
  566. });
  567. return me;
  568. },
  569. <span id='Ext-dom-Element-method-frame'> /**
  570. </span> * Shows a ripple of exploding, attenuating borders to draw attention to an Element. Usage:
  571. *
  572. * // default: a single light blue ripple
  573. * el.frame();
  574. *
  575. * // custom: 3 red ripples lasting 3 seconds total
  576. * el.frame(&quot;#ff0000&quot;, 3, { duration: 3000 });
  577. *
  578. * // common config options shown with default values
  579. * el.frame(&quot;#C3DAF9&quot;, 1, {
  580. * duration: 1000 // duration of each individual ripple.
  581. * // Note: Easing is not configurable and will be ignored if included
  582. * });
  583. *
  584. * @param {String} [color='#C3DAF9'] The hex color value for the border.
  585. * @param {Number} [count=1] The number of ripples to display.
  586. * @param {Object} [options] Object literal with any of the Fx config options
  587. * @return {Ext.dom.Element} The Element
  588. */
  589. frame : function(color, count, obj){
  590. var me = this,
  591. beforeAnim;
  592. color = color || '#C3DAF9';
  593. count = count || 1;
  594. obj = obj || {};
  595. beforeAnim = function() {
  596. me.show();
  597. var animScope = this,
  598. box = me.getBox(),
  599. proxy = Ext.getBody().createChild({
  600. id: me.id + '-anim-proxy',
  601. style: {
  602. position : 'absolute',
  603. 'pointer-events': 'none',
  604. 'z-index': 35000,
  605. border : '0px solid ' + color
  606. }
  607. }),
  608. proxyAnim;
  609. proxyAnim = new Ext.fx.Anim({
  610. target: proxy,
  611. duration: obj.duration || 1000,
  612. iterations: count,
  613. from: {
  614. top: box.y,
  615. left: box.x,
  616. borderWidth: 0,
  617. opacity: 1,
  618. height: box.height,
  619. width: box.width
  620. },
  621. to: {
  622. top: box.y - 20,
  623. left: box.x - 20,
  624. borderWidth: 10,
  625. opacity: 0,
  626. height: box.height + 40,
  627. width: box.width + 40
  628. }
  629. });
  630. proxyAnim.on('afteranimate', function() {
  631. proxy.remove();
  632. // kill the no-op element animation created below
  633. animScope.end();
  634. });
  635. };
  636. me.animate({
  637. // See &quot;A Note About Wrapped Animations&quot; at the top of this class:
  638. duration: (Math.max(obj.duration, 500) * 2) || 2000,
  639. listeners: {
  640. beforeanimate: {
  641. fn: beforeAnim
  642. }
  643. }
  644. });
  645. return me;
  646. },
  647. <span id='Ext-dom-Element-method-ghost'> /**
  648. </span> * Slides the element while fading it out of view. An anchor point can be optionally passed to set the ending point
  649. * of the effect. Usage:
  650. *
  651. * // default: slide the element downward while fading out
  652. * el.ghost();
  653. *
  654. * // custom: slide the element out to the right with a 2-second duration
  655. * el.ghost('r', { duration: 2000 });
  656. *
  657. * // common config options shown with default values
  658. * el.ghost('b', {
  659. * easing: 'easeOut',
  660. * duration: 500
  661. * });
  662. *
  663. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
  664. * @param {Object} options (optional) Object literal with any of the Fx config options
  665. * @return {Ext.dom.Element} The Element
  666. */
  667. ghost: function(anchor, obj) {
  668. var me = this,
  669. beforeAnim;
  670. anchor = anchor || &quot;b&quot;;
  671. beforeAnim = function() {
  672. var width = me.getWidth(),
  673. height = me.getHeight(),
  674. xy = me.getXY(),
  675. position = me.getPositioning(),
  676. to = {
  677. opacity: 0
  678. };
  679. switch (anchor) {
  680. case 't':
  681. to.y = xy[1] - height;
  682. break;
  683. case 'l':
  684. to.x = xy[0] - width;
  685. break;
  686. case 'r':
  687. to.x = xy[0] + width;
  688. break;
  689. case 'b':
  690. to.y = xy[1] + height;
  691. break;
  692. case 'tl':
  693. to.x = xy[0] - width;
  694. to.y = xy[1] - height;
  695. break;
  696. case 'bl':
  697. to.x = xy[0] - width;
  698. to.y = xy[1] + height;
  699. break;
  700. case 'br':
  701. to.x = xy[0] + width;
  702. to.y = xy[1] + height;
  703. break;
  704. case 'tr':
  705. to.x = xy[0] + width;
  706. to.y = xy[1] - height;
  707. break;
  708. }
  709. this.to = to;
  710. this.on('afteranimate', function () {
  711. if (me.dom) {
  712. me.hide();
  713. me.clearOpacity();
  714. me.setPositioning(position);
  715. }
  716. });
  717. };
  718. me.animate(Ext.applyIf(obj || {}, {
  719. duration: 500,
  720. easing: 'ease-out',
  721. listeners: {
  722. beforeanimate: {
  723. fn: beforeAnim
  724. }
  725. }
  726. }));
  727. return me;
  728. },
  729. <span id='Ext-dom-Element-method-highlight'> /**
  730. </span> * Highlights the Element by setting a color (applies to the background-color by default, but can be changed using
  731. * the &quot;attr&quot; config option) and then fading back to the original color. If no original color is available, you
  732. * should provide the &quot;endColor&quot; config option which will be cleared after the animation. Usage:
  733. *
  734. * // default: highlight background to yellow
  735. * el.highlight();
  736. *
  737. * // custom: highlight foreground text to blue for 2 seconds
  738. * el.highlight(&quot;0000ff&quot;, { attr: 'color', duration: 2000 });
  739. *
  740. * // common config options shown with default values
  741. * el.highlight(&quot;ffff9c&quot;, {
  742. * attr: &quot;backgroundColor&quot;, //can be any valid CSS property (attribute) that supports a color value
  743. * endColor: (current color) or &quot;ffffff&quot;,
  744. * easing: 'easeIn',
  745. * duration: 1000
  746. * });
  747. *
  748. * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading #
  749. * (defaults to yellow: 'ffff9c')
  750. * @param {Object} options (optional) Object literal with any of the Fx config options
  751. * @return {Ext.dom.Element} The Element
  752. */
  753. highlight: function(color, o) {
  754. var me = this,
  755. dom = me.dom,
  756. from = {},
  757. restore, to, attr, lns, event, fn;
  758. o = o || {};
  759. lns = o.listeners || {};
  760. attr = o.attr || 'backgroundColor';
  761. from[attr] = color || 'ffff9c';
  762. if (!o.to) {
  763. to = {};
  764. to[attr] = o.endColor || me.getColor(attr, 'ffffff', '');
  765. }
  766. else {
  767. to = o.to;
  768. }
  769. // Don't apply directly on lns, since we reference it in our own callbacks below
  770. o.listeners = Ext.apply(Ext.apply({}, lns), {
  771. beforeanimate: function() {
  772. restore = dom.style[attr];
  773. me.clearOpacity();
  774. me.show();
  775. event = lns.beforeanimate;
  776. if (event) {
  777. fn = event.fn || event;
  778. return fn.apply(event.scope || lns.scope || window, arguments);
  779. }
  780. },
  781. afteranimate: function() {
  782. if (dom) {
  783. dom.style[attr] = restore;
  784. }
  785. event = lns.afteranimate;
  786. if (event) {
  787. fn = event.fn || event;
  788. fn.apply(event.scope || lns.scope || window, arguments);
  789. }
  790. }
  791. });
  792. me.animate(Ext.apply({}, o, {
  793. duration: 1000,
  794. easing: 'ease-in',
  795. from: from,
  796. to: to
  797. }));
  798. return me;
  799. },
  800. <span id='Ext-dom-Element-method-pause'> /**
  801. </span> * Creates a pause before any subsequent queued effects begin. If there are no effects queued after the pause it will
  802. * have no effect. Usage:
  803. *
  804. * el.pause(1);
  805. *
  806. * @deprecated 4.0 Use the `delay` config to {@link #animate} instead.
  807. * @param {Number} seconds The length of time to pause (in seconds)
  808. * @return {Ext.Element} The Element
  809. */
  810. pause: function(ms) {
  811. var me = this;
  812. Ext.fx.Manager.setFxDefaults(me.id, {
  813. delay: ms
  814. });
  815. return me;
  816. },
  817. <span id='Ext-dom-Element-method-fadeIn'> /**
  818. </span> * Fade an element in (from transparent to opaque). The ending opacity can be specified using the `opacity`
  819. * config option. Usage:
  820. *
  821. * // default: fade in from opacity 0 to 100%
  822. * el.fadeIn();
  823. *
  824. * // custom: fade in from opacity 0 to 75% over 2 seconds
  825. * el.fadeIn({ opacity: .75, duration: 2000});
  826. *
  827. * // common config options shown with default values
  828. * el.fadeIn({
  829. * opacity: 1, //can be any value between 0 and 1 (e.g. .5)
  830. * easing: 'easeOut',
  831. * duration: 500
  832. * });
  833. *
  834. * @param {Object} options (optional) Object literal with any of the Fx config options
  835. * @return {Ext.Element} The Element
  836. */
  837. fadeIn: function(o) {
  838. var me = this;
  839. me.animate(Ext.apply({}, o, {
  840. opacity: 1,
  841. internalListeners: {
  842. beforeanimate: function(anim){
  843. // restore any visibility/display that may have
  844. // been applied by a fadeout animation
  845. if (me.isStyle('display', 'none')) {
  846. me.setDisplayed('');
  847. } else {
  848. me.show();
  849. }
  850. }
  851. }
  852. }));
  853. return this;
  854. },
  855. <span id='Ext-dom-Element-method-fadeOut'> /**
  856. </span> * Fade an element out (from opaque to transparent). The ending opacity can be specified using the `opacity`
  857. * config option. Note that IE may require `useDisplay:true` in order to redisplay correctly.
  858. * Usage:
  859. *
  860. * // default: fade out from the element's current opacity to 0
  861. * el.fadeOut();
  862. *
  863. * // custom: fade out from the element's current opacity to 25% over 2 seconds
  864. * el.fadeOut({ opacity: .25, duration: 2000});
  865. *
  866. * // common config options shown with default values
  867. * el.fadeOut({
  868. * opacity: 0, //can be any value between 0 and 1 (e.g. .5)
  869. * easing: 'easeOut',
  870. * duration: 500,
  871. * remove: false,
  872. * useDisplay: false
  873. * });
  874. *
  875. * @param {Object} options (optional) Object literal with any of the Fx config options
  876. * @return {Ext.Element} The Element
  877. */
  878. fadeOut: function(o) {
  879. var me = this;
  880. o = Ext.apply({
  881. opacity: 0,
  882. internalListeners: {
  883. afteranimate: function(anim){
  884. var dom = me.dom;
  885. if (dom &amp;&amp; anim.to.opacity === 0) {
  886. if (o.useDisplay) {
  887. me.setDisplayed(false);
  888. } else {
  889. me.hide();
  890. }
  891. }
  892. }
  893. }
  894. }, o);
  895. me.animate(o);
  896. return me;
  897. },
  898. <span id='Ext-dom-Element-method-scale'> /**
  899. </span> * Animates the transition of an element's dimensions from a starting height/width to an ending height/width. This
  900. * method is a convenience implementation of {@link #shift}. Usage:
  901. *
  902. * // change height and width to 100x100 pixels
  903. * el.scale(100, 100);
  904. *
  905. * // common config options shown with default values. The height and width will default to
  906. * // the element's existing values if passed as null.
  907. * el.scale(
  908. * [element's width],
  909. * [element's height], {
  910. * easing: 'easeOut',
  911. * duration: 350
  912. * }
  913. * );
  914. *
  915. * @deprecated 4.0 Just use {@link #animate} instead.
  916. * @param {Number} width The new width (pass undefined to keep the original width)
  917. * @param {Number} height The new height (pass undefined to keep the original height)
  918. * @param {Object} options (optional) Object literal with any of the Fx config options
  919. * @return {Ext.Element} The Element
  920. */
  921. scale: function(w, h, o) {
  922. this.animate(Ext.apply({}, o, {
  923. width: w,
  924. height: h
  925. }));
  926. return this;
  927. },
  928. <span id='Ext-dom-Element-method-shift'> /**
  929. </span> * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. Any of these
  930. * properties not specified in the config object will not be changed. This effect requires that at least one new
  931. * dimension, position or opacity setting must be passed in on the config object in order for the function to have
  932. * any effect. Usage:
  933. *
  934. * // slide the element horizontally to x position 200 while changing the height and opacity
  935. * el.shift({ x: 200, height: 50, opacity: .8 });
  936. *
  937. * // common config options shown with default values.
  938. * el.shift({
  939. * width: [element's width],
  940. * height: [element's height],
  941. * x: [element's x position],
  942. * y: [element's y position],
  943. * opacity: [element's opacity],
  944. * easing: 'easeOut',
  945. * duration: 350
  946. * });
  947. *
  948. * @deprecated 4.0 Just use {@link #animate} instead.
  949. * @param {Object} options Object literal with any of the Fx config options
  950. * @return {Ext.Element} The Element
  951. */
  952. shift: function(config) {
  953. this.animate(config);
  954. return this;
  955. }
  956. });
  957. </pre>
  958. </body>
  959. </html>