image.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. define(function(require, exports, module) {
  2. return require('../core/class').createClass('Image', {
  3. base: require('./shape'),
  4. constructor: function(url, width, height, x, y) {
  5. this.callBase('image');
  6. this.url = url;
  7. this.width = width || 0;
  8. this.height = height || 0;
  9. this.x = x || 0;
  10. this.y = y || 0;
  11. this.update();
  12. },
  13. update: function() {
  14. this.node.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', this.url);
  15. this.node.setAttribute('x', this.x);
  16. this.node.setAttribute('y', this.y);
  17. this.node.setAttribute('width', this.width);
  18. this.node.setAttribute('height', this.height);
  19. return this;
  20. },
  21. setUrl: function(url) {
  22. this.url = url === '' ? null : url;
  23. return this.update();
  24. },
  25. getUrl: function() {
  26. return this.url;
  27. },
  28. setWidth: function(width) {
  29. this.width = width;
  30. return this.update();
  31. },
  32. getWidth: function() {
  33. return this.width;
  34. },
  35. setHeight: function(height) {
  36. this.height = height;
  37. return this.update();
  38. },
  39. getHeight: function() {
  40. return this.height;
  41. },
  42. setX: function(x) {
  43. this.x = x;
  44. return this.update();
  45. },
  46. getX: function() {
  47. return this.x;
  48. },
  49. setY: function(y) {
  50. this.y = y;
  51. return this.update();
  52. },
  53. getY: function() {
  54. return this.y;
  55. }
  56. });
  57. });