summaryrefslogtreecommitdiffstats
path: root/src/flatten.js
blob: db9b9dfa04d2801227c62b2ab4e6adfbd947a19f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SVG.extend(SVG.Parent, {
  flatten: function(parent) {
    if(this instanceof SVG.Defs) return this

    parent = parent || (this instanceof SVG.Doc ? this : this.parent(SVG.Parent))

    this.each(function(){
      if(this instanceof SVG.Defs) return this
      if(this instanceof SVG.Parent) return this.flatten(parent)
      return this.toParent(parent)
    })
    
    // we need this so that SVG.Doc does not get removed
    this.node.firstChild || this.remove()

    return this
  }
})