/ext-4.0.7/src/fx/target/Element.js

https://bitbucket.org/srogerf/javascript · JavaScript · 99 lines · 67 code · 8 blank · 24 comment · 26 complexity · 61453dc5e47721f8ec45893453f1a4cf MD5 · raw file

  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.fx.target.Element
  11. * @extends Ext.fx.target.Target
  12. *
  13. * This class represents a animation target for an {@link Ext.Element}. In general this class will not be
  14. * created directly, the {@link Ext.Element} will be passed to the animation and
  15. * and the appropriate target will be created.
  16. */
  17. Ext.define('Ext.fx.target.Element', {
  18. /* Begin Definitions */
  19. extend: 'Ext.fx.target.Target',
  20. /* End Definitions */
  21. type: 'element',
  22. getElVal: function(el, attr, val) {
  23. if (val == undefined) {
  24. if (attr === 'x') {
  25. val = el.getX();
  26. }
  27. else if (attr === 'y') {
  28. val = el.getY();
  29. }
  30. else if (attr === 'scrollTop') {
  31. val = el.getScroll().top;
  32. }
  33. else if (attr === 'scrollLeft') {
  34. val = el.getScroll().left;
  35. }
  36. else if (attr === 'height') {
  37. val = el.getHeight();
  38. }
  39. else if (attr === 'width') {
  40. val = el.getWidth();
  41. }
  42. else {
  43. val = el.getStyle(attr);
  44. }
  45. }
  46. return val;
  47. },
  48. getAttr: function(attr, val) {
  49. var el = this.target;
  50. return [[ el, this.getElVal(el, attr, val)]];
  51. },
  52. setAttr: function(targetData) {
  53. var target = this.target,
  54. ln = targetData.length,
  55. attrs, attr, o, i, j, ln2, element, value;
  56. for (i = 0; i < ln; i++) {
  57. attrs = targetData[i].attrs;
  58. for (attr in attrs) {
  59. if (attrs.hasOwnProperty(attr)) {
  60. ln2 = attrs[attr].length;
  61. for (j = 0; j < ln2; j++) {
  62. o = attrs[attr][j];
  63. element = o[0];
  64. value = o[1];
  65. if (attr === 'x') {
  66. element.setX(value);
  67. }
  68. else if (attr === 'y') {
  69. element.setY(value);
  70. }
  71. else if (attr === 'scrollTop') {
  72. element.scrollTo('top', value);
  73. }
  74. else if (attr === 'scrollLeft') {
  75. element.scrollTo('left',value);
  76. }
  77. else {
  78. element.setStyle(attr, value);
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. });