summaryrefslogtreecommitdiffstats
path: root/src/clip.js
blob: 7341c8ff229c7fc027954650af8e1d025d53387e (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
SVG.Clip = function() {
  this.constructor.call(this, SVG.create('clipPath'))
}

// Inherit from SVG.Container
SVG.Clip.prototype = new SVG.Container

//
SVG.extend(SVG.Element, {
  // Distribute clipPath to svg element
  clipWith: function(element) {
    /* use given clip or create a new one */
    this.clip = element instanceof SVG.Clip ? element : this.parent.clip().add(element)
    
    return this.attr('clip-path', 'url(#' + this.clip.attr('id') + ')')
  }
  
})

//
SVG.extend(SVG.Container, {
  // Create clipping element
  clip: function() {
    return this.defs().put(new SVG.Clip)
  }

})