equal
deleted
inserted
replaced
28 content; |
28 content; |
29 } |
29 } |
30 value "$activity"; |
30 value "$activity"; |
31 const "has_activity","string-length($activity)>0"; |
31 const "has_activity","string-length($activity)>0"; |
32 | }, |
32 | }, |
|
33 | has_activity: «$has_activity», |
33 }; |
34 }; |
34 |
35 |
35 decl activable() alias - { |
36 decl activable() alias - { |
36 _activable("warn") |
37 _activable("warn") |
37 }; |
38 }; |
231 } |
232 } |
232 function _show(elt, placeholder){ |
233 function _show(elt, placeholder){ |
233 placeholder.parentNode.insertBefore(elt, placeholder); |
234 placeholder.parentNode.insertBefore(elt, placeholder); |
234 } |
235 } |
235 |
236 |
236 function set_activation_state(eltsub, state){ |
237 function set_activity_state(eltsub, state){ |
237 if(eltsub.active_elt != undefined){ |
238 if(eltsub.active_elt != undefined){ |
238 if(eltsub.active_elt_placeholder == undefined){ |
239 if(eltsub.active_elt_placeholder == undefined){ |
239 eltsub.active_elt_placeholder = document.createComment(""); |
240 eltsub.active_elt_placeholder = document.createComment(""); |
240 eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt); |
241 eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt); |
241 } |
242 } |
246 eltsub.inactive_elt_placeholder = document.createComment(""); |
247 eltsub.inactive_elt_placeholder = document.createComment(""); |
247 eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt); |
248 eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt); |
248 } |
249 } |
249 ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder); |
250 ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder); |
250 } |
251 } |
251 } |
|
252 |
|
253 function activate_activable(eltsub) { |
|
254 set_activation_state(eltsub, true); |
|
255 } |
|
256 |
|
257 function inactivate_activable(eltsub) { |
|
258 set_activation_state(eltsub, false); |
|
259 } |
252 } |
260 |
253 |
261 class Widget { |
254 class Widget { |
262 offset = 0; |
255 offset = 0; |
263 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
256 frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ |
266 |
259 |
267 constructor(elt_id, freq, args, variables, enable_expr, members){ |
260 constructor(elt_id, freq, args, variables, enable_expr, members){ |
268 this.element_id = elt_id; |
261 this.element_id = elt_id; |
269 this.element = id(elt_id); |
262 this.element = id(elt_id); |
270 this.args = args; |
263 this.args = args; |
|
264 |
271 [this.indexes, this.variables_options] = (variables.length>0) ? zip(...variables) : [[],[]]; |
265 [this.indexes, this.variables_options] = (variables.length>0) ? zip(...variables) : [[],[]]; |
272 this.indexes_length = this.indexes.length; |
266 this.indexes_length = this.indexes.length; |
|
267 |
273 this.enable_expr = enable_expr; |
268 this.enable_expr = enable_expr; |
274 this.enable_state = true; |
269 this.enable_state = true; |
275 this.enable_displayed_state = true; |
270 this.enable_displayed_state = true; |
276 this.enabled_elts = []; |
271 this.enabled_elts = []; |
277 |
272 |
476 |
471 |
477 undeafen(index){ |
472 undeafen(index){ |
478 this.deafen[index] = undefined; |
473 this.deafen[index] = undefined; |
479 let [new_val, old_val] = this.incoming[index]; |
474 let [new_val, old_val] = this.incoming[index]; |
480 this.incoming[index] = undefined; |
475 this.incoming[index] = undefined; |
481 this.dispatch(new_val, old_val, index); |
476 if(this.dispatch) |
|
477 this.dispatch(new_val, old_val, index); |
482 } |
478 } |
483 |
479 |
484 enable(enabled){ |
480 enable(enabled){ |
485 if(this.enable_state != enabled){ |
481 if(this.enable_state != enabled){ |
486 this.enable_state = enabled; |
482 this.enable_state = enabled; |
512 //show disabled content |
508 //show disabled content |
513 if(this.disabled_elt) |
509 if(this.disabled_elt) |
514 this.element.appendChild(this.disabled_elt); |
510 this.element.appendChild(this.disabled_elt); |
515 |
511 |
516 this.enable_displayed_state = false; |
512 this.enable_displayed_state = false; |
|
513 |
|
514 // once disabled activity display is lost |
|
515 this.activity_displayed_state = undefined; |
517 } |
516 } |
518 } |
517 } |
519 |
518 |
520 _dispatch(value, oldval, varnum) { |
519 _dispatch(value, oldval, varnum) { |
521 let dispatch = this.dispatch; |
520 let dispatch = this.dispatch; |
551 } |
550 } |
552 |
551 |
553 _animate(){ |
552 _animate(){ |
554 if(this.enable_expr) |
553 if(this.enable_expr) |
555 this.animate_enable(); |
554 this.animate_enable(); |
556 if(this.animate != undefined && (!this.enable_expr || this.enable_state)) |
555 // inhibit widget animation when disabled |
557 this.animate(); |
556 if(!this.enable_expr || this.enable_state){ |
|
557 if(this.has_activity) |
|
558 this.animate_activity(); |
|
559 if(this.animate != undefined) |
|
560 this.animate(); |
|
561 } |
558 this.pending_animate = false; |
562 this.pending_animate = false; |
559 } |
563 } |
560 |
564 |
561 request_animate(){ |
565 request_animate(){ |
562 if(!this.pending_animate){ |
566 if(!this.pending_animate){ |
564 this.pending_animate = true; |
568 this.pending_animate = true; |
565 requestHMIAnimation(); |
569 requestHMIAnimation(); |
566 } |
570 } |
567 } |
571 } |
568 |
572 |
569 set_activation_state(state){ |
573 animate_activity(){ |
570 set_activation_state(this.activable_sub, state); |
574 if(this.activity_displayed_state != this.activity_state){ |
|
575 set_activity_state(this.activable_sub, this.activity_state); |
|
576 this.activity_displayed_state = this.activity_state; |
|
577 } |
571 } |
578 } |
572 } |
579 } |
573 || |
580 || |
574 } |
581 } |
575 |
582 |