aboutsummaryrefslogtreecommitdiffstats
path: root/src/arrange.js
blob: 63ac659c6c40ea6ef0fc161f6ec519b382af21a9 (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
// ### This module adds backward / forward functionality to elements.

//
SVG.extend(SVG.Element, {
  // Get all siblings, including myself
  siblings: function() {
    return this.parent.children();
  },
  // Get the curent position siblings
  position: function() {
    return this.siblings().indexOf(this);
  },
  // Get the next element (will return null if there is none)
  next: function() {
    return this.siblings()[this.position() + 1];
  },
  // Get the next element (will return null if there is none)
  previous: function() {
    return this.siblings()[this.position() - 1];
  },
  // Send given element one step forward
  forward: function() {
    return this.parent.remove(this).put(this, this.position() + 1);
  },
  // Send given element one step backward
  backward: function() {
    var i, parent = this.parent.level();
    
    i = this.position();
    
    if (i > 1)
      parent.remove(this).add(this, i - 1);
    
    return this;
  },
  // Send given element all the way to the front
  front: function() {
    return this.parent.remove(this).put(this);
  },
  // Send given element all the way to the back
  back: function() {
    var parent = this.parent.level();
    
    if (this.position() > 1)
      parent.remove(this).add(this, 0);
    
    return this;
  }
  
});