svghmi/widget_tooglebutton.ysl2
changeset 3519 43b2bff95289
parent 3495 f422d3d71f89
child 3520 b27e50143083
equal deleted inserted replaced
3518:c663d1f9f03b 3519:43b2bff95289
    35 
    35 
    36             //redraw toggle button
    36             //redraw toggle button
    37             this.request_animate();
    37             this.request_animate();
    38         }
    38         }
    39 
    39 
    40         activate(val) {
    40         set_state(active) {
    41             let [active, inactive] = val ? ["","none"] : ["none", ""];
    41             if (this.active_elt){
    42             if (this.active_elt)
    42                 if(active==undefined || !active){
    43                 this.active_elt.style.display = active;
    43                     if(this.active_elt_parent == undefined){
    44             if (this.inactive_elt)
    44                         this.active_elt_parent = this.active_elt.parentElement;
    45                 this.inactive_elt.style.display = inactive;
    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             }
    46         }
    67         }
    47 
    68 
    48         animate(){
    69         animate(){
    49             // redraw toggle button on screen refresh
    70             // redraw toggle button on screen refresh
    50             this.activate(this.state);
    71             this.set_state(this.state);
    51         }
    72         }
    52 
    73 
    53         init() {
    74         init() {
    54             this.activate(false);
       
    55             this.element.onclick = (evt) => this.on_click(evt);
    75             this.element.onclick = (evt) => this.on_click(evt);
       
    76             this.active_elt_parent = 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);
    56         }
    85         }
    57     ||
    86     ||
    58 }
    87 }
    59 
    88 
    60 widget_defs("ToggleButton") {
    89 widget_defs("ToggleButton") {
    61     optional_labels("active inactive");
    90     optional_labels("active inactive");
    62 }
    91 }
       
    92