--- a/svghmi/gen_index_xhtml.xslt Tue May 26 09:58:20 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Tue May 26 10:53:02 2020 +0200
@@ -1152,40 +1152,72 @@
- <xsl:template mode="widget_class" match="widget[@type='Button']">
- <xsl:text>class ButtonWidget extends Widget{
- <xsl:text> frequency = 5;
- <xsl:text> // TODO : use attributes to allow interaction through svg:use
- <xsl:text> // TODO : deal with dragging
- <xsl:text> this.element.addEventListener(
- <xsl:text> "mousedown",
- <xsl:text> change_hmi_value(this.indexes[0], "=1");
- <xsl:text> this.element.addEventListener(
- <xsl:text> change_hmi_value(this.indexes[0], "=0");
+ <xsl:template mode="widget_defs" match="widget[@type='Button']"> + <xsl:param name="hmi_element"/> + <xsl:call-template name="defs_by_labels"> + <xsl:with-param name="hmi_element" select="$hmi_element"/> + <xsl:with-param name="labels"> + <xsl:text>active inactive</xsl:text> + <xsl:with-param name="mandatory" select="'no'"/> + <xsl:text>frequency: 5, + <xsl:text>on_mouse_down: function(evt) { + <xsl:text> if (this.active_style && this.inactive_style) { + <xsl:text> this.active_elt.setAttribute("style", this.active_style); + <xsl:text> this.inactive_elt.setAttribute("style", "display:none");
+ <xsl:text> change_hmi_value(this.indexes[0], "=1"); + <xsl:text>on_mouse_up: function(evt) { + <xsl:text> if (this.active_style && this.inactive_style) { + <xsl:text> this.active_elt.setAttribute("style", "display:none"); + <xsl:text> this.inactive_elt.setAttribute("style", this.inactive_style); + <xsl:text> change_hmi_value(this.indexes[0], "=0"); + <xsl:text>active_style: undefined, + <xsl:text>inactive_style: undefined, + <xsl:text>init: function() { + <xsl:text> this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; + <xsl:text> this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; + <xsl:text> if (this.active_style && this.inactive_style) { + <xsl:text> this.active_elt.setAttribute("style", "display:none"); + <xsl:text> this.inactive_elt.setAttribute("style", this.inactive_style); + <xsl:text> this.element.setAttribute("onmousedown", "hmi_widgets['</xsl:text> + <xsl:value-of select="$hmi_element/@id"/> + <xsl:text>'].on_mouse_down(evt)"); + <xsl:text> this.element.setAttribute("onmouseup", "hmi_widgets['</xsl:text> + <xsl:value-of select="$hmi_element/@id"/> + <xsl:text>'].on_mouse_up(evt)"); <xsl:template mode="widget_defs" match="widget[@type='CircularBar']">
@@ -3271,8 +3303,6 @@
- <xsl:text> console.log(opstr, given_val);
<xsl:text> let old_val = cache[index];
--- a/svghmi/widget_button.ysl2 Tue May 26 09:58:20 2020 +0200
+++ b/svghmi/widget_button.ysl2 Tue May 26 10:53:02 2020 +0200
@@ -1,20 +1,33 @@
-template "widget[@type='Button']", mode="widget_class"
- class ButtonWidget extends Widget{
- this.element.addEventListener(
- change_hmi_value(this.indexes[0], "=1");
- this.element.addEventListener(
- change_hmi_value(this.indexes[0], "=0");
+template "widget[@type='Button']", mode="widget_defs" { + optional_labels("active inactive"); + | on_mouse_down: function(evt) { + | if (this.active_style && this.inactive_style) { + | this.active_elt.setAttribute("style", this.active_style); + | this.inactive_elt.setAttribute("style", "display:none"); + | change_hmi_value(this.indexes[0], "=1"); + | on_mouse_up: function(evt) { + | if (this.active_style && this.inactive_style) { + | this.active_elt.setAttribute("style", "display:none"); + | this.inactive_elt.setAttribute("style", this.inactive_style); + | change_hmi_value(this.indexes[0], "=0"); + | active_style: undefined, + | inactive_style: undefined, + | this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; + | this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; + | if (this.active_style && this.inactive_style) { + | this.active_elt.setAttribute("style", "display:none"); + | this.inactive_elt.setAttribute("style", this.inactive_style); + | this.element.setAttribute("onmousedown", "hmi_widgets['«$hmi_element/@id»'].on_mouse_down(evt)"); + | this.element.setAttribute("onmouseup", "hmi_widgets['«$hmi_element/@id»'].on_mouse_up(evt)"); \ No newline at end of file