-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy pathsvg-image-element.js
46 lines (40 loc) · 1.35 KB
/
svg-image-element.js
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
jvm.SVGImageElement = function(config, style){
jvm.SVGImageElement.parentClass.call(this, 'image', config, style);
};
jvm.inherits(jvm.SVGImageElement, jvm.SVGShapeElement);
jvm.SVGImageElement.prototype.applyAttr = function(attr, value){
var that = this,
imageOffset,
imageUrl;
if (attr == 'image') {
if (typeof value == 'object') {
imageUrl = value.url;
this.offset = value.offset;
} else {
imageUrl = value;
this.offset = [0, 0];
}
jvm.whenImageLoaded(imageUrl).then(function(img){
that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageUrl);
that.width = img[0].width;
that.height = img[0].height;
that.applyAttr('width', that.width);
that.applyAttr('height', that.height);
that.applyAttr('x', that.cx - that.width / 2 + that.offset[0]);
that.applyAttr('y', that.cy - that.height / 2 + that.offset[1]);
jvm.$(that.node).trigger('imageloaded', [img]);
});
} else if(attr == 'cx') {
this.cx = value;
if (this.width) {
this.applyAttr('x', value - this.width / 2 + this.offset[0]);
}
} else if(attr == 'cy') {
this.cy = value;
if (this.height) {
this.applyAttr('y', value - this.height / 2 + this.offset[1]);
}
} else {
jvm.SVGImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
}
};