1 // widget_jump.ysl2 |
1 // widget_jump.ysl2 |
|
2 |
|
3 function "jump_widget_activity" { |
|
4 param "hmi_element"; |
|
5 optional_labels("active inactive"); |
|
6 } |
2 |
7 |
3 template "widget[@type='Jump']", mode="widget_defs" { |
8 template "widget[@type='Jump']", mode="widget_defs" { |
4 param "hmi_element"; |
9 param "hmi_element"; |
5 |
10 const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_element"; |
|
11 const "have_opt","string-length($opts)>0"; |
|
12 value "$opts"; |
6 | on_click: function(evt) { |
13 | on_click: function(evt) { |
7 | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
14 | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
8 | const name = this.args[0]; |
15 | const name = this.args[0]; |
9 | switch_page(name, index); |
16 | switch_page(name, index); |
10 | }, |
17 | }, |
|
18 if "$have_opt" { |
|
19 | notify_page_change: function(page_name, index){ |
|
20 | const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; |
|
21 | const ref_name = this.args[0]; |
|
22 | if((ref_name == undefined || ref_name == page_name) && index == ref_index) { |
|
23 | console.log("active", ref_name, ref_index, page_name, index); |
|
24 | /* show active */ |
|
25 | this.active_elt.setAttribute("style", this.active_elt_style); |
|
26 | /* hide inactive */ |
|
27 | this.inactive_elt.setAttribute("style", "display:none"); |
|
28 | } else { |
|
29 | console.log("inactive",ref_name, ref_index, page_name, index); |
|
30 | /* show inactive */ |
|
31 | this.inactive_elt.setAttribute("style", this.inactive_elt_style); |
|
32 | /* hide active */ |
|
33 | this.active_elt.setAttribute("style", "display:none"); |
|
34 | } |
|
35 | }, |
|
36 } |
11 | init: function() { |
37 | init: function() { |
12 /* registering event this way does not "click" through svg:use |
38 /* registering event this way does not "click" through svg:use |
13 | this.element.onclick = evt => switch_page(this.args[0]); |
39 | this.element.onclick = evt => switch_page(this.args[0]); |
14 event must be registered by adding attribute to element instead |
40 event must be registered by adding attribute to element instead |
15 TODO : generalize mouse event handling by global event capture + getElementsAtPoint() |
41 TODO : generalize mouse event handling by global event capture + getElementsAtPoint() |
16 */ |
42 */ |
17 | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
43 | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); |
|
44 if "$have_opt" { |
|
45 | this.active_elt_style = this.active_elt.getAttribute("style"); |
|
46 | this.inactive_elt_style = this.inactive_elt.getAttribute("style"); |
|
47 } |
18 | }, |
48 | }, |
19 } |
49 } |
20 |
50 |
21 template "widget[@type='Jump']", mode="per_page_widget_template"{ |
51 template "widget[@type='Jump']", mode="per_page_widget_template"{ |
22 param "page_desc"; |
52 param "page_desc"; |