edouard@2883: // widget_jump.ysl2 Edouard@2779: Edouard@2903: function "jump_widget_activity" { Edouard@2903: param "hmi_element"; Edouard@2903: optional_labels("active inactive"); Edouard@2903: } Edouard@2903: edouard@2883: template "widget[@type='Jump']", mode="widget_defs" { edouard@2883: param "hmi_element"; Edouard@2903: const "opts" call "jump_widget_activity" with "hmi_element", "$hmi_element"; Edouard@2903: const "have_opt","string-length($opts)>0"; Edouard@2903: value "$opts"; edouard@2883: | on_click: function(evt) { Edouard@2898: | const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2902: | const name = this.args[0]; Edouard@2902: | switch_page(name, index); edouard@2883: | }, Edouard@2903: if "$have_opt" { Edouard@2903: | notify_page_change: function(page_name, index){ Edouard@2903: | const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2903: | const ref_name = this.args[0]; Edouard@2903: | if((ref_name == undefined || ref_name == page_name) && index == ref_index) { Edouard@2903: | console.log("active", ref_name, ref_index, page_name, index); Edouard@2903: | /* show active */ Edouard@2903: | this.active_elt.setAttribute("style", this.active_elt_style); Edouard@2903: | /* hide inactive */ Edouard@2903: | this.inactive_elt.setAttribute("style", "display:none"); Edouard@2903: | } else { Edouard@2903: | console.log("inactive",ref_name, ref_index, page_name, index); Edouard@2903: | /* show inactive */ Edouard@2903: | this.inactive_elt.setAttribute("style", this.inactive_elt_style); Edouard@2903: | /* hide active */ Edouard@2903: | this.active_elt.setAttribute("style", "display:none"); Edouard@2903: | } Edouard@2903: | }, Edouard@2903: } edouard@2883: | init: function() { Edouard@2901: /* registering event this way does not "click" through svg:use edouard@2883: | this.element.onclick = evt => switch_page(this.args[0]); edouard@2883: event must be registered by adding attribute to element instead edouard@2883: TODO : generalize mouse event handling by global event capture + getElementsAtPoint() edouard@2883: */ edouard@2883: | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)"); Edouard@2903: if "$have_opt" { Edouard@2903: | this.active_elt_style = this.active_elt.getAttribute("style"); Edouard@2903: | this.inactive_elt_style = this.inactive_elt.getAttribute("style"); Edouard@2903: } edouard@2883: | }, Edouard@2753: } Edouard@2901: Edouard@2901: template "widget[@type='Jump']", mode="per_page_widget_template"{ Edouard@2901: param "page_desc"; Edouard@2901: /* check that given path is compatible with page's reference path */ Edouard@2901: if "path" { Edouard@2901: /* when no page name provided, check for same page */ Edouard@2901: const "target_page_name" choose { Edouard@2901: when "arg" value "arg[1]/@value"; Edouard@2901: otherwise value "$page_desc/arg[1]/@value"; Edouard@2901: } Edouard@2901: const "target_page_path" choose { Edouard@2901: when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"; Edouard@2901: otherwise value "$page_desc/path[1]/@value"; Edouard@2901: } Edouard@2901: Edouard@2901: if "not(func:same_class_paths($target_page_path, path[1]/@value))" Edouard@2901: error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»") Edouard@2901: } Edouard@2901: }