-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSVGSprite.js
37 lines (34 loc) · 1.14 KB
/
SVGSprite.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
function SVGSprite(sprite) {
SVGSprite.registry.push(this);
this.tag = 'g';
this.sprite = sprite;
this.el = this.createEl();
this.$el = $(this.el);
this.update();
this.sprite.on('change', function() {
this.update();
}.bind(this));
this.sprite.getShapes().forEach(function(shp) {
this.$el.append(new SVGShape(shp).el);
}.bind(this));
this.sprite.on('shape:add', function(shp) {
this.$el.append(new SVGShape(shp).el);
}.bind(this));
this.sprite.on('ellipse:add', function(ellipse) {
this.$el.append(new SVGEllipse(ellipse).el);
}.bind(this));
this.sprite.sprites.forEach(function(sprite) {
this.$el.append(new SVGSprite(sprite).el);
}.bind(this));
this.sprite.on('sprite:add', function(sprite) {
this.$el.append(new SVGSprite(sprite).el);
}.bind(this));
}
// pull into shared SVGElement base class
SVGSprite.prototype.createEl = function createEl() {
return document.createElementNS('http://www.w3.org/2000/svg', this.tag);
};
SVGSprite.prototype.update = function update() {
this.$el.attr('transform', 'translate(' + this.sprite.offset + ')')
}
SVGSprite.registry = [];