diff -r 8f928cee01e5 -r 7349063b19d8 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Wed May 13 14:48:52 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Thu May 14 09:24:09 2020 +0200
@@ -866,20 +866,26 @@
class Widget {
+ offset = 0;
+
+ frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
+
constructor(elt_id,args,indexes,members){
+ this.element_id = elt_id;
+
this.element = id(elt_id);
this.args = args;
this.indexes = indexes;
- this.offset = 0;
-
Object.keys(members).forEach(prop => this[prop]=members[prop]);
}
+
+
unsub(){
/* remove subsribers */
@@ -1078,9 +1084,10 @@
-
-
- on_click: function(evt) {
+
+ class BackWidget extends Widget{
+
+ on_click(evt) {
if(jump_history.length > 1){
@@ -1092,44 +1099,51 @@
}
- },
-
- init: function() {
-
- this.element.setAttribute("onclick", "hmi_widgets['
-
- '].on_click(evt)");
-
- },
-
-
-
-
- frequency: 5,
-
- init: function() {
-
- this.element.addEventListener(
-
- "mousedown",
-
- evt => {
-
- change_hmi_value(this.indexes[0], "=1");
-
- });
-
- this.element.addEventListener(
-
- "mouseup",
-
- evt => {
-
- change_hmi_value(this.indexes[0], "=0");
-
- });
-
- },
+ }
+
+ init() {
+
+ this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
+
+ }
+
+ }
+
+
+
+ class ButtonWidget extends Widget{
+
+ frequency = 5;
+
+ init() {
+
+ // TODO : use attributes to allow interaction through svg:use
+
+ // TODO : deal with dragging
+
+ this.element.addEventListener(
+
+ "mousedown",
+
+ evt => {
+
+ change_hmi_value(this.indexes[0], "=1");
+
+ });
+
+ this.element.addEventListener(
+
+ "mouseup",
+
+ evt => {
+
+ change_hmi_value(this.indexes[0], "=0");
+
+ });
+
+ }
+
+ }
@@ -1767,7 +1781,6 @@
-
@@ -2585,34 +2598,34 @@
},
+
+ class SwitchWidget extends Widget{
+
+ frequency = 5;
+
+ dispatch(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: [
@@ -3104,11 +3117,15 @@
let maxfreq = 0;
- for(let widget of widgets)
-
- if(maxfreq < widget.frequency)
-
- maxfreq = widget.frequency;
+ for(let widget of widgets){
+
+ let wf = widget.frequency;
+
+ if(wf != undefined && maxfreq < wf)
+
+ maxfreq = wf;
+
+ }