vml-image-element.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. jvm.VMLImageElement = function(config, style){
  2. jvm.VMLImageElement.parentClass.call(this, 'image', config, style);
  3. };
  4. jvm.inherits(jvm.VMLImageElement, jvm.VMLShapeElement);
  5. jvm.VMLImageElement.prototype.applyAttr = function(attr, value){
  6. var patternEl,
  7. imageEl,
  8. that = this;
  9. if (attr == 'image') {
  10. jvm.whenImageLoaded(value).then(function(img){
  11. that.node.setAttribute('src', value);
  12. that.width = img[0].width;
  13. that.height = img[0].height;
  14. that.applyAttr('width', that.width);
  15. that.applyAttr('height', that.height);
  16. jvm.VMLImageElement.images[value] = jvm.VMLImageElement.imageCounter++;
  17. that.applyAttr('x', that.cx - that.width / 2);
  18. that.applyAttr('y', that.cy - that.height / 2);
  19. jvm.$(that.node).trigger('imageloaded', [img]);
  20. });
  21. } else if(attr == 'cx') {
  22. this.cx = value;
  23. if (this.width) {
  24. this.applyAttr('x', value - this.width / 2);
  25. }
  26. } else if(attr == 'cy') {
  27. this.cy = value;
  28. if (this.height) {
  29. this.applyAttr('y', value - this.height / 2);
  30. }
  31. } else if(attr == 'width' || attr == 'height') {
  32. this.node.style[attr] = value + 'px';
  33. } else if (attr == 'x' || attr == 'y') {
  34. this.node.style[attr == 'x' ? 'left' : 'top'] = value + 'px';
  35. } else {
  36. jvm.VMLImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
  37. }
  38. };
  39. jvm.VMLImageElement.imageCounter = 1;
  40. jvm.VMLImageElement.images = {}