35 |
35 |
36 //redraw toggle button |
36 //redraw toggle button |
37 this.request_animate(); |
37 this.request_animate(); |
38 } |
38 } |
39 |
39 |
40 set_state(active) { |
|
41 if (this.active_elt){ |
|
42 if(active==undefined || !active){ |
|
43 if(this.active_elt_parent == undefined){ |
|
44 this.active_elt_parent = this.active_elt.parentElement; |
|
45 this.active_elt_parent.removeChild(this.active_elt); |
|
46 } |
|
47 }else{ |
|
48 if(this.active_elt_parent != undefined){ |
|
49 this.active_elt_parent.insertBefore(this.active_elt, this.active_elt_sibling); |
|
50 this.active_elt_parent = undefined; |
|
51 } |
|
52 } |
|
53 } |
|
54 if (this.inactive_elt){ |
|
55 if(active==undefined || active){ |
|
56 if(this.inactive_elt_parent == undefined){ |
|
57 this.inactive_elt_parent = this.inactive_elt.parentElement; |
|
58 this.inactive_elt_parent.removeChild(this.inactive_elt); |
|
59 } |
|
60 }else{ |
|
61 if(this.inactive_elt_parent != undefined){ |
|
62 this.inactive_elt_parent.insertBefore(this.inactive_elt, this.inactive_elt_sibling); |
|
63 this.inactive_elt_parent = undefined; |
|
64 } |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 animate(){ |
40 animate(){ |
70 // redraw toggle button on screen refresh |
41 // redraw toggle button on screen refresh |
71 this.set_state(this.state); |
42 this.set_activation_state(this.state); |
72 } |
43 } |
73 |
44 |
74 init() { |
45 init() { |
75 this.element.onclick = (evt) => this.on_click(evt); |
46 this.element.onclick = (evt) => this.on_click(evt); |
76 this.active_elt_parent = undefined; |
47 this.set_activation_state(undefined); |
77 this.active_elt_sibling = this.active_elt.nextSibling; |
|
78 this.inactive_elt_parent = undefined; |
|
79 this.inactive_elt_sibling = this.inactive_elt.nextSibling; |
|
80 if(this.inactive_elt_sibling == this.active_elt) |
|
81 this.inactive_elt_sibling = this.inactive_elt_sibling.nextSibling; |
|
82 if(this.active_elt_sibling == this.inactive_elt) |
|
83 this.active_elt_sibling = this.active_elt_sibling.nextSibling; |
|
84 this.set_state(undefined); |
|
85 } |
48 } |
86 || |
49 || |
87 } |
50 } |
88 |
51 |
89 widget_defs("ToggleButton") { |
52 widget_defs("ToggleButton") { |
90 optional_labels("active inactive"); |
53 activable(); |
91 } |
54 } |
92 |
55 |