summaryrefslogtreecommitdiffstats
path: root/src/arrange.js
blob: d7fcb5f2afe7516369264a04cb63d7375e0388d0 (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
43
44
45
46
47
48
49
50
51
52
53
// add backward / forward functionality to elements
SVG.extend(SVG.Element, {
  
  // get all siblings, including me
  siblings: function() {
    return this.mother().children();
  },
  
  // send given element one step forwards
  forward: function() {
    var i = this.siblings().indexOf(this);
    this.mother().remove(this).add(this, i + 1);
    
    return this;
  },
  
  // send given element one step backwards
  backward: function() {
    var i, p = this.mother();
    
    p.levelDefs();
    
    i = this.siblings().indexOf(this);
    
    if (i > 1)
      p.remove(this).add(this, i - 1);
    
    return this;
  },
  
  // send given element all the way to the front
  front: function() {
    this.mother().remove(this).add(this);
    
    return this;
  },
  
  // send given element all the way to the back
  back: function() {
    var i, p = this.mother();
    
    p.levelDefs();
    
    i = this.siblings().indexOf(this);
    
    if (i > 1)
      p.remove(this).add(this, 0);
    
    return this;
  }
  
});