21 } |
21 } |
22 |
22 |
23 widget_class("Switch") |
23 widget_class("Switch") |
24 || |
24 || |
25 frequency = 5; |
25 frequency = 5; |
|
26 current_value = undefined; |
|
27 |
|
28 init(){ |
|
29 animate(); |
|
30 } |
|
31 |
26 dispatch(value) { |
32 dispatch(value) { |
|
33 this.current_value = value; |
|
34 this.request_animate(); |
|
35 } |
|
36 |
|
37 animate(){ |
27 for(let choice of this.choices){ |
38 for(let choice of this.choices){ |
28 if(value != choice.value){ |
39 if(this.current_value != choice.value){ |
29 choice.elt.setAttribute("style", "display:none"); |
40 if(choice.parent == undefined){ |
|
41 choice.parent = choice.elt.parentElement; |
|
42 choice.parent.removeChild(choice.elt); |
|
43 } |
30 } else { |
44 } else { |
31 choice.elt.setAttribute("style", choice.style); |
45 if(choice.parent != undefined){ |
|
46 choice.parent.appendChild(choice.elt); |
|
47 choice.parent = undefined; |
|
48 } |
32 } |
49 } |
33 } |
50 } |
34 } |
51 } |
35 || |
52 || |
36 |
53 |
37 widget_defs("Switch") { |
54 widget_defs("Switch") { |
38 | choices: [ |
55 | choices: [ |
39 const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; |
56 const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; |
40 |
57 |
|
58 // this prevents matching element in sub-widgets |
41 const "subelts", "$result_widgets[@id = $hmi_element/@id]//*"; |
59 const "subelts", "$result_widgets[@id = $hmi_element/@id]//*"; |
42 const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]"; |
60 const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]"; |
43 const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]"; |
61 const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]"; |
44 |
62 |
45 foreach "$accepted[regexp:test(@inkscape:label,$regex)]" { |
63 foreach "$accepted[regexp:test(@inkscape:label,$regex)]" { |
46 const "literal", "regexp:match(@inkscape:label,$regex)[2]"; |
64 const "literal", "regexp:match(@inkscape:label,$regex)[2]"; |
47 | { |
65 | { |
48 | elt:id("«@id»"), |
66 | elt:id("«@id»"), |
49 // TODO : use style.display = "none" to hide element |
67 | parent:undefined, |
50 | style:"«@style»", |
|
51 | value:«$literal» |
68 | value:«$literal» |
52 | }`if "position()!=last()" > ,` |
69 | }`if "position()!=last()" > ,` |
53 } |
70 } |
54 | ], |
71 | ], |
55 } |
72 } |