blob: ab7bebf731cd6dfcea8d4a10bcd28653607255e2 (
plain)
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
|
SVG.Clip = function Clip() {
this.constructor.call(this, SVG.create('clipPath'));
// set unique id
this.id = 'svgjs_' + (SVG.did++);
this.attr('id', this.id);
};
// inherit from SVG.Element
SVG.Clip.prototype = new SVG.Element();
// include the container object
SVG.extend(SVG.Clip, SVG.Container);
// add clipping functionality to element
SVG.extend(SVG.Element, {
// clip element using another element
clip: function(b) {
var p = this.parent.defs().clip();
b(p);
return this.clipTo(p);
},
// distribute clipping path to svg element
clipTo: function(p) {
return this.attr('clip-path', 'url(#' + p.id + ')');
}
});
// add def-specific functions
SVG.extend(SVG.Defs, {
// create clippath
clip: function() {
return this.put(new SVG.Clip());
}
});
|