1 /********************************************************************************
2 * javascript/spool_toggle : script for folding/unfolding threads in spool
3 * ------------------------
5 * This file is part of the banana distribution
6 * Copyright: See COPYING files that comes with this distribution
7 ********************************************************************************/
9 /** prevent IE from launching two opposite toggle actions at the same time
10 * Usual parameters are:
11 * - 0 : no action is running
15 var banana_toggle
= 0;
17 /** Release banana_toggle a little time after action is done
18 * called with : setTimeout(banana_release_toggle, 10);
20 function banna_release_toggle() {
24 /** Unfold a thread by showing all its sons
25 * called on the img element of the thread
27 function banana_unfold_thread() {
28 // don't unfold if already folding somewhere
29 if (banana_toggle
== 1) {
33 var myid
= $(this).parent().parent().parent().attr("id").replace(/[0-9]+_/,"");
35 $("tr[@id^="+myid
+"_]").each(banana_subunfold_thread
);
36 // change tree icon and prepare for folding
38 attr("src",this.src
.replace(/k3/,"k2")).
40 unbind("click",banana_unfold_thread
).
41 click(banana_fold_thread
);
42 setTimeout(banna_release_toggle
, 10);
45 /** Fold a thread by hiding all its sons
46 * called on the img element of the thread
48 function banana_fold_thread() {
49 // don't fold if already unfolding somewhere
50 if (banana_toggle
== 2) {
54 var myid
= $(this).parent().parent().parent().attr("id").replace(/[0-9]+_/,"");
56 $("tr[@id^="+myid
+"_]").each(banana_subfold_thread
);
57 // change tree icon and prepare for unfolding
59 attr("src",this.src
.replace(/k2/,"k3")).
61 unbind("click",banana_fold_thread
).
62 click(banana_unfold_thread
);
63 setTimeout(banna_release_toggle
, 10);
66 /** Show a son of a thread when unfolding
67 * called on the tr element of the son
69 function banana_subunfold_thread() {
70 // show the element before working on sons
71 // otherwise they could be hidden and not managed
73 // if this son has subsons and is unfold
74 if ($("img[@alt='*']", this).size()) {
76 var myid
= $(this).attr("id").replace(/[0-9]+_/,"");
77 $("tr[@id^="+myid
+"_]").each(banana_subunfold_thread
);
81 /** Hide a son of a thread when folding
82 * called on the tr element of the son
84 function banana_subfold_thread() {
85 // if this son has subsons and is unfold
86 if ($("img[@alt='*']", this).size()) {
88 var myid
= $(this).attr("id").replace(/[0-9]+_/,"");
89 $("tr[@id^="+myid
+"_]").each(banana_subfold_thread
);
91 // hide element only after working on sons
92 // otherwise they could be hidden and not managed
96 /** Fold all threads in page
98 function banana_fold_all() {
99 $("tr img[alt='*'][@src*=k2]").each(banana_fold_thread
);
102 /** Unfold all threads in page
104 function banana_unfold_all() {
105 $("tr img[alt='+'][@src*=k3]").each(banana_unfold_thread
);
108 // prepare for folding
109 $(document
).ready( function() {
110 $("tr img[@alt='*'][@src*='k2']").
111 css("cursor","pointer").
112 click(banana_fold_thread
);