aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/bower_components/jvectormap/src/vml-image-element.js
blob: 8fb7ca9960deef4b21119c202345ab9266af39ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
jvm.VMLImageElement = function(config, style){
  jvm.VMLImageElement.parentClass.call(this, 'image', config, style);
};

jvm.inherits(jvm.VMLImageElement, jvm.VMLShapeElement);

jvm.VMLImageElement.prototype.applyAttr = function(attr, value){
  var patternEl,
      imageEl,
      that = this;

  if (attr == 'image') {
    jvm.whenImageLoaded(value).then(function(img){
      that.node.setAttribute('src', value);
      that.width = img[0].width;
      that.height = img[0].height;
      that.applyAttr('width', that.width);
      that.applyAttr('height', that.height);

      jvm.VMLImageElement.images[value] = jvm.VMLImageElement.imageCounter++;

      that.applyAttr('x', that.cx - that.width / 2);
      that.applyAttr('y', that.cy - that.height / 2);

      jvm.$(that.node).trigger('imageloaded', [img]);
    });
  } else if(attr == 'cx') {
    this.cx = value;
    if (this.width) {
      this.applyAttr('x', value - this.width / 2);
    }
  } else if(attr == 'cy') {
    this.cy = value;
    if (this.height) {
      this.applyAttr('y', value - this.height / 2);
    }
  } else if(attr == 'width' || attr == 'height') {
    this.node.style[attr] = value + 'px';
  } else if (attr == 'x' || attr == 'y') {
    this.node.style[attr == 'x' ? 'left' : 'top'] = value + 'px';
  } else {
    jvm.VMLImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
  }
};

jvm.VMLImageElement.imageCounter = 1;
jvm.VMLImageElement.images = {}