svghmi/widget_button.ysl2
branchsvghmi
changeset 2976 99c4521bb844
parent 2961 00825316ed00
child 3000 a9a45977bac0
equal deleted inserted replaced
2971:f0a822ef9fa0 2976:99c4521bb844
     1 // widget_button.ysl2
     1 // widget_button.ysl2
     2 
     2 
     3 template "widget[@type='Button']", mode="widget_class"
     3 template "widget[@type='Button']", mode="widget_defs" {
     4     ||
     4     param "hmi_element";
     5     class ButtonWidget extends Widget{
     5     optional_labels("active inactive");
     6         frequency = 5;
     6     | frequency: 5,
     7         init() {
     7     | on_mouse_down: function(evt) {
     8             this.element.addEventListener(
     8     |     if (this.active_style && this.inactive_style) {
     9               "mousedown",
     9     |         this.active_elt.setAttribute("style", this.active_style);
    10               evt => {
    10     |         this.inactive_elt.setAttribute("style", "display:none");
    11                   change_hmi_value(this.indexes[0], "=1");
    11     |     }
    12               });
    12     |     change_hmi_value(this.indexes[0], "=1");
    13             this.element.addEventListener(
    13     | },
    14               "mouseup",
    14     | on_mouse_up: function(evt) {
    15               evt => {
    15     |     if (this.active_style && this.inactive_style) {
    16                   change_hmi_value(this.indexes[0], "=0");
    16     |         this.active_elt.setAttribute("style", "display:none");
    17               });
    17     |         this.inactive_elt.setAttribute("style", this.inactive_style);
    18         }
    18     |     }
    19     }
    19     |     change_hmi_value(this.indexes[0], "=0");
    20     ||
    20     | },
       
    21     | active_style: undefined,
       
    22     | inactive_style: undefined,
       
    23     | init: function() {
       
    24     |   this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
       
    25     |   this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
    26     |   if (this.active_style && this.inactive_style) {
       
    27     |       this.active_elt.setAttribute("style", "display:none");
       
    28     |       this.inactive_elt.setAttribute("style", this.inactive_style);
       
    29     |   }
       
    30     |   this.element.setAttribute("onmousedown", "hmi_widgets['«$hmi_element/@id»'].on_mouse_down(evt)");
       
    31     |   this.element.setAttribute("onmouseup", "hmi_widgets['«$hmi_element/@id»'].on_mouse_up(evt)");
       
    32     | },
       
    33 }