initial checkin
[org.ibex.widgets.git] / src / ibex / lib / cardpane.t
1 <!-- Copyleft 2004 - see COPYING for details [LGPL] -->
2
3 <ibex>
4     <meta:doc>
5         See ibex.widget.cardpane for details
6
7         <todo>
8             Make cardpane aware of 'enabled' cards
9         </todo>
10     </meta:doc>
11  
12     <ui:box>
13
14         // public interface
15
16         thisbox.nextcard;
17         thisbox.nextstep;
18         thisbox.prevcard;
19         thisbox.prevstep;
20         thisbox.show;
21
22         // private variables
23
24         var steps = [];
25         var stepmarker = 0;
26         var stepping = false;
27
28         // childadded write trap
29         childadded ++= function(v) {
30             // show v if it is the first card
31             if (numchildren > 1) v.visible = false;
32             else { cascade = v; show = v; }
33         }
34
35         // childremoved write trap
36         childremoved ++= function(v) {
37             // if v is the shown card, attempt to show another
38             if (show == v) {
39                 if (next) next = true;
40                 else if (prev) prev = true;
41             }
42         }
43
44         // write trap to show the next card in the cardpane
45         nextcard ++= function(v) {
46             if (nextcard) nextcard.show = true;
47         }
48
49         // read trap to fetch the next card in the cardpane
50         nextcard ++= function() {
51             if (show and numchildren - 1 > show) return thisbox[show + 1];
52             else return null;
53         }
54
55         // write trap to step forward to the next in the show-chain
56         nextstep ++= function(v) {
57             stepping = true;
58             if (nextstep) nextstep.show = true;
59             stepping = false;
60         }
61
62         // read trap to fetch the next step in the show-chain
63         nextstep ++= function() {
64             if (steps.length - 1 > stepmarker) return steps[stepmarker + 1];
65             else return false;
66         }
67
68         // write trap to show the previous card in the cardpane
69         prevcard ++= function(v) {
70             if (prevcard) prevcard.show = true;
71         }
72
73         // read trap to fetch the previous card in the cardpane
74         prevcard ++= function() {
75             if (show and show > 0) return thisbox[show - 1];
76             else return false;
77         }
78
79         // write trap to step back to the previous in the show-chain
80         prevstep ++= function(v) {
81             stepping = true;
82             if (prevstep) prevstep.show = true;
83             stepping = false;
84         }
85
86         // read trap to fetch the previous step in the show-chain
87         prevstep ++= function() {
88             if (stepmarker > 0) return steps[stepmarker - 1];
89             else return false;
90         }
91
92         // write trap to show a card by box or index
93         show ++= function(v) {
94             var card;
95             
96             if (typeof(v) == "number" and numchildren > v) card = thisbox[v];
97             else if (typeof(v) == "object" and (thisbox.indexof(v) or thisbox.indexof(v) == 0)) card = v;
98
99             if (card) {
100                 // hide the previously shown card and show the new one
101                 //if (cascade) cascade.visible = false;
102                 for (var i=0; numchildren > i; i++) { thisbox[i].visible = false; }
103                 card.visible = true;
104
105                 // remember where we are
106                 if (!stepping) {
107                     stepmarker ++;
108                     if (stepmarker != steps.length) steps.splice(stepmarker, steps.length - stepsmarker);
109                     if (stepmarker > 100) steps.splice(0);
110                     steps[stepmarker] = card;
111                 }
112
113                 cascade = card;
114             }
115             else return;
116         }
117
118     </ui:box>
119 </ibex>