# HG changeset patch # User Edouard Tisserant # Date 1583229480 -3600 # Node ID 8d15c6238e627acab867730f4d0747286c1508f3 # Parent e38654ec628155a4b38155ff11ccffc0fa903dc7 SVGHMI: re-indent generated JS diff -r e38654ec6281 -r 8d15c6238e62 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Mar 02 16:30:29 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Tue Mar 03 10:58:00 2020 +0100 @@ -1265,45 +1265,45 @@ - frequency: 5, + frequency: 5, - dispatch: function(value) { + dispatch: function(value) { - this.value_elt.textContent = String(value); + this.value_elt.textContent = String(value); - }, + }, - init: function() { + init: function() { - id(" + id(" ").addEventListener( - "click", - - evt => alert('XXX TODO : Edit value')); + "click", + + evt => alert('XXX TODO : Edit value')); - id(" + id(" ").addEventListener( - "click", - - evt => {let new_val = change_hmi_value(this.indexes[0], " + "click", + + evt => {let new_val = change_hmi_value(this.indexes[0], " "); - this.value_elt.textContent = String(new_val);}); + this.value_elt.textContent = String(new_val);}); - }, + }, @@ -1313,78 +1313,78 @@ - frequency: 5, - - dispatch: function(value) { - - for(let choice of this.choices){ - - if(value != choice.value){ - - choice.elt.setAttribute("style", "display:none"); - - } else { - - choice.elt.setAttribute("style", choice.style); + frequency: 5, + + dispatch: function(value) { + + for(let choice of this.choices){ + + if(value != choice.value){ + + choice.elt.setAttribute("style", "display:none"); + + } else { + + choice.elt.setAttribute("style", choice.style); + + } } - } - - }, - - init: function() { - - // Hello Switch - - }, - - choices: [ + }, + + init: function() { + + // Hello Switch + + }, + + choices: [ - { - - elt:id(" + { + + elt:id(" "), - style:" + style:" ", - value: + value: - } + } , - ], + ], - on_click: function(evt) { - - console.log(evt); - - switch_page(this.args[0]); - - }, - - init: function() { - - this.element.setAttribute("onclick", "hmi_widgets[' + on_click: function(evt) { + + console.log(evt); + + switch_page(this.args[0]); + + }, + + init: function() { + + this.element.setAttribute("onclick", "hmi_widgets[' '].on_click(evt)"); - }, + }, diff -r e38654ec6281 -r 8d15c6238e62 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Mon Mar 02 16:30:29 2020 +0100 +++ b/svghmi/gen_index_xhtml.ysl2 Tue Mar 03 10:58:00 2020 +0100 @@ -694,26 +694,29 @@ } value "$value_elt"; if "$value_elt" - | frequency: 5, - | dispatch: function(value) { + | frequency: 5, + + | dispatch: function(value) { + if "$value_elt" - | this.value_elt.textContent = String(value); - | }, + | this.value_elt.textContent = String(value); + + | }, const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id"; - | init: function() { + | init: function() { if "$edit_elt_id" { - | id("«$edit_elt_id»").addEventListener( - | "click", - | evt => alert('XXX TODO : Edit value')); + | id("«$edit_elt_id»").addEventListener( + | "click", + | evt => alert('XXX TODO : Edit value')); } foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { - | id("«@id»").addEventListener( - | "click", - | evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»"); - | this.value_elt.textContent = String(new_val);}); - /* could gray out value until refreshed */ - } - | }, + | id("«@id»").addEventListener( + | "click", + | evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»"); + | this.value_elt.textContent = String(new_val);}); + /* TODO gray out value until refreshed */ + } + | }, } template "widget[@type='Button']", mode="widget_defs" { } @@ -722,44 +725,44 @@ } template "widget[@type='Switch']", mode="widget_defs" { param "hmi_element"; - | frequency: 5, - | dispatch: function(value) { - | for(let choice of this.choices){ - | if(value != choice.value){ - | choice.elt.setAttribute("style", "display:none"); - | } else { - | choice.elt.setAttribute("style", choice.style); + | frequency: 5, + | dispatch: function(value) { + | for(let choice of this.choices){ + | if(value != choice.value){ + | choice.elt.setAttribute("style", "display:none"); + | } else { + | choice.elt.setAttribute("style", choice.style); + | } | } - | } - | }, - | init: function() { - | // Hello Switch - | }, - | choices: [ + | }, + | init: function() { + | // Hello Switch + | }, + | choices: [ const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+)(#.*)?$'"!; foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" { const "literal", "regexp:match(@inkscape:label,$regex)[2]"; - | { - | elt:id("«@id»"), - | style:"«@style»", - | value:«$literal» - | }`if "position()!=last()" > ,` - } - | ], + | { + | elt:id("«@id»"), + | style:"«@style»", + | value:«$literal» + | }`if "position()!=last()" > ,` + } + | ], } template "widget[@type='Jump']", mode="widget_defs" { param "hmi_element"; - | on_click: function(evt) { - | console.log(evt); - | switch_page(this.args[0]); - | }, - | init: function() { + | on_click: function(evt) { + | console.log(evt); + | switch_page(this.args[0]); + | }, + | init: function() { /* registering event this way doies not "click" through svg:use | this.element.onclick = evt => switch_page(this.args[0]); event must be registered by adding attribute to element instead TODO : generalize mouse event handling by global event capture + getElementsAtPoint() */ - | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); - | }, + | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); + | }, } }