Use explicit serialization (revert r291).
[banana.git] / javascript / spool_toggle.js
1 /********************************************************************************
2 * javascript/spool_toggle : script for folding/unfolding threads in spool
3 * ------------------------
4 *
5 * This file is part of the banana distribution
6 * Copyright: See COPYING files that comes with this distribution
7 ********************************************************************************/
8
9 /** prevent IE from launching two opposite toggle actions at the same time
10 * Usual parameters are:
11 * - 0 : no action is running
12 * - 1 : folding
13 * - 2 : unfolding
14 */
15 var banana_toggle = 0;
16
17 /** Release banana_toggle a little time after action is done
18 * called with : setTimeout(banana_release_toggle, 10);
19 */
20 function banna_release_toggle() {
21 banana_toggle = 0;
22 }
23
24 /** Unfold a thread by showing all its sons
25 * called on the img element of the thread
26 */
27 function banana_unfold_thread() {
28 // don't unfold if already folding somewhere
29 if (banana_toggle == 1) {
30 return;
31 }
32 banana_toggle = 2;
33 var myid = $(this).parent().parent().parent().attr("id").replace(/[0-9]+_/,"");
34 // show all sons
35 $("tr[@id^="+myid+"_]").each(banana_subunfold_thread);
36 // change tree icon and prepare for folding
37 $(this).
38 attr("src",this.src.replace(/k3/,"k2")).
39 attr("alt","*").
40 unbind("click",banana_unfold_thread).
41 click(banana_fold_thread);
42 setTimeout(banna_release_toggle, 10);
43 }
44
45 /** Fold a thread by hiding all its sons
46 * called on the img element of the thread
47 */
48 function banana_fold_thread() {
49 // don't fold if already unfolding somewhere
50 if (banana_toggle == 2) {
51 return;
52 }
53 banana_toggle = 1;
54 var myid = $(this).parent().parent().parent().attr("id").replace(/[0-9]+_/,"");
55 // hide all sons
56 $("tr[@id^="+myid+"_]").each(banana_subfold_thread);
57 // change tree icon and prepare for unfolding
58 $(this).
59 attr("src",this.src.replace(/k2/,"k3")).
60 attr("alt","+").
61 unbind("click",banana_fold_thread).
62 click(banana_unfold_thread);
63 setTimeout(banna_release_toggle, 10);
64 }
65
66 /** Show a son of a thread when unfolding
67 * called on the tr element of the son
68 */
69 function banana_subunfold_thread() {
70 // show the element before working on sons
71 // otherwise they could be hidden and not managed
72 $(this).show();
73 // if this son has subsons and is unfold
74 if ($("img[@alt='*']", this).size()) {
75 // show subsons
76 var myid = $(this).attr("id").replace(/[0-9]+_/,"");
77 $("tr[@id^="+myid+"_]").each(banana_subunfold_thread);
78 }
79 }
80
81 /** Hide a son of a thread when folding
82 * called on the tr element of the son
83 */
84 function banana_subfold_thread() {
85 // if this son has subsons and is unfold
86 if ($("img[@alt='*']", this).size()) {
87 // hide subsons
88 var myid = $(this).attr("id").replace(/[0-9]+_/,"");
89 $("tr[@id^="+myid+"_]").each(banana_subfold_thread);
90 }
91 // hide element only after working on sons
92 // otherwise they could be hidden and not managed
93 $(this).hide();
94 }
95
96 /** Fold all threads in page
97 */
98 function banana_fold_all() {
99 $("tr img[alt='*'][@src*=k2]").each(banana_fold_thread);
100 }
101
102 /** Unfold all threads in page
103 */
104 function banana_unfold_all() {
105 $("tr img[alt='+'][@src*=k3]").each(banana_unfold_thread);
106 }
107
108 // prepare for folding
109 $(document).ready( function() {
110 $("tr img[@alt='*'][@src*='k2']").
111 css("cursor","pointer").
112 click(banana_fold_thread);
113 });