base-test.js added
[xynt.git] / xynt-link.js
1 function tasks_link(anc, a, b, type) {
2     var cur;
3     this.anc = anc;
4     this.o   = document.createElement("div");
5     this.o.style.top  = "0px";
6     this.o.style.left = "0px";
7     this.o.style.position = "absolute";
8     this.o.style.visibility = "hidden";
9     this.beg = document.createElement("div");
10     this.end = document.createElement("div");
11     this.arr = document.createElement("img");
12     this.arr.style.position = "absolute";
13     this.o.appendChild(this.arr);
14     this.anc.appendChild(this.o);
15     for (var i = 0 ; i < 2 ; i++) {
16         cur = i == 0 ? this.beg : this.end;
17         cur.style.width = '5px';
18         cur.style.height = '5px';
19         cur.style.backgroundColor = 'gray';
20         cur.style.visibility = 'inherit';
21         cur.style.zIndex = 20;
22         cur.style.position = 'absolute';
23         this.o.appendChild(cur);
24         // alert("gugu");
25     }
26     
27     this.a = a;
28     this.b = b;
29     this.type = type;
30
31     if (typeof(a.connected) != 'object')
32         return null;
33
34     if (typeof(b.connected) != 'object')
35         return null;
36
37     for (var i = 0 ; i < 2 ; i++) {
38         cur = (i == 0 ? a : b);
39         cur.connected[cur.connected.length++] = this;
40         for( ; cur.parentNode != null && cur.parentNode != anc ; cur = cur.parentNode) {
41             cur.connect(this);
42         }
43     }
44     this.update()
45 }
46
47 tasks_link.prototype = {
48     a: null,
49     b: null,
50     type: null,
51
52     update: function(method, obj)
53     {
54         /*
55         if (method == 'end') {
56             if (this.o.style.visibility == 'visible')
57                 this.o.style.visibility = 'hidden';
58             else
59                 this.o.style.visibility = 'visible';
60         }
61         */
62         
63         // FIXME you need to user the width of the border instead of +2
64         this.beg.style.left = (parseInt(this.a.style.left) + parseInt(this.a.style.width) + 2 + parseInt(this.a.parentNode.style.left))+"px";
65         this.beg.style.top  = (parseInt(this.a.style.top)  + parseInt(((parseInt(this.a.style.height) + 2) / 2)) + parseInt(this.a.parentNode.style.top))+"px";
66         this.beg.style.width = (parseInt(this.b.style.left) - (parseInt(this.a.style.left) + 2 + parseInt(this.b.style.width) + 2)+ parseInt(this.b.parentNode.style.left) + 5)+"px";
67         this.beg.style.height = "1px";
68
69         this.end.style.left = (parseInt(this.beg.style.left) + parseInt(this.beg.style.width))+"px";
70         this.arr.style.left = (parseInt(this.end.style.left) - 3)+"px";
71         /* this.end.style.left = (parseInt(this.b.style.left) + parseInt(this.b.parentNode.style.left))+"px";
72            this.end.style.top  = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top))+"px"; */
73         endpty = parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top)+10;
74         this.end.style.width  = "1px";
75         
76         if (parseInt(this.beg.style.top) < endpty) {
77             this.end.style.top  = this.beg.style.top;
78             this.end.style.height = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top) - ((parseInt(this.a.style.top)  + parseInt(this.a.parentNode.style.top))) ) - 11 +"px";
79             this.arr.style.top = (parseInt(this.end.style.top) + parseInt(this.end.style.height) - 5)+"px";
80             this.arr.src = "img/arrow_do.png";
81         }
82         else {
83             this.end.style.top  = (parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top) + 23)+"px";
84             this.end.style.height = (parseInt(this.a.style.top)  + parseInt(this.a.parentNode.style.top) - ((parseInt(this.b.style.top)  + parseInt(this.b.parentNode.style.top))) ) - 11 +"px";
85
86             this.arr.style.top = this.end.style.top;
87             this.arr.src = "img/arrow_up.png";
88         }
89
90
91         this.o.style.visibility = "visible";
92         
93         console.log("met: " + method + " obj: " + (obj == this.a ? "Obj A" : (obj == this.b ? "Obj B" : "Other")) );
94     }
95 }