svg-image-element.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. jvm.SVGImageElement = function(config, style){
  2. jvm.SVGImageElement.parentClass.call(this, 'image', config, style);
  3. };
  4. jvm.inherits(jvm.SVGImageElement, jvm.SVGShapeElement);
  5. jvm.SVGImageElement.prototype.applyAttr = function(attr, value){
  6. var that = this;
  7. if (attr == 'image') {
  8. jvm.whenImageLoaded(value).then(function(img){
  9. that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value);
  10. that.width = img[0].width;
  11. that.height = img[0].height;
  12. that.applyAttr('width', that.width);
  13. that.applyAttr('height', that.height);
  14. that.applyAttr('x', that.cx - that.width / 2);
  15. that.applyAttr('y', that.cy - that.height / 2);
  16. jvm.$(that.node).trigger('imageloaded', [img]);
  17. });
  18. } else if(attr == 'cx') {
  19. this.cx = value;
  20. if (this.width) {
  21. this.applyAttr('x', value - this.width / 2);
  22. }
  23. } else if(attr == 'cy') {
  24. this.cy = value;
  25. if (this.height) {
  26. this.applyAttr('y', value - this.height / 2);
  27. }
  28. } else {
  29. jvm.SVGImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
  30. }
  31. };