57 } |
57 } |
58 |
58 |
59 // Called on requestAnimationFrame, modifies DOM |
59 // Called on requestAnimationFrame, modifies DOM |
60 var requestAnimationFrameID = null; |
60 var requestAnimationFrameID = null; |
61 function animate() { |
61 function animate() { |
62 // Do the page swith if any one pending |
62 let rearm = true; |
63 if(page_switch_in_progress){ |
63 do{ |
64 if(current_subscribed_page != current_visible_page){ |
64 if(page_fading == "pending" || page_fading == "forced"){ |
65 switch_visible_page(current_subscribed_page); |
65 if(page_fading == "pending") |
66 } |
66 svg_root.classList.add("fade-out-page"); |
67 |
67 page_fading = "in_progress"; |
68 page_switch_in_progress = false; |
68 if(page_fading_args.length) |
69 |
69 setTimeout(function(){ |
70 if(page_fading_in_progress){ |
70 switch_page(...page_fading_args); |
71 svg_root.classList.remove("fade-out-page"); |
71 },1); |
72 page_fading_in_progress = false; |
72 break; |
73 } |
73 } |
74 } |
74 |
75 |
75 // Do the page swith if pending |
76 while(widget = need_cache_apply.pop()){ |
76 if(page_switch_in_progress){ |
77 widget.apply_cache(); |
77 if(current_subscribed_page != current_visible_page){ |
78 } |
78 switch_visible_page(current_subscribed_page); |
79 |
79 } |
80 if(jumps_need_update) update_jumps(); |
80 |
81 |
81 page_switch_in_progress = false; |
82 apply_updates(); |
82 |
83 |
83 if(page_fading == "in_progress"){ |
84 pending_widget_animates.forEach(widget => widget._animate()); |
84 svg_root.classList.remove("fade-out-page"); |
85 pending_widget_animates = []; |
85 page_fading = "off"; |
|
86 } |
|
87 } |
|
88 |
|
89 while(widget = need_cache_apply.pop()){ |
|
90 widget.apply_cache(); |
|
91 } |
|
92 |
|
93 if(jumps_need_update) update_jumps(); |
|
94 |
|
95 apply_updates(); |
|
96 |
|
97 pending_widget_animates.forEach(widget => widget._animate()); |
|
98 pending_widget_animates = []; |
|
99 rearm = false; |
|
100 } while(0); |
86 |
101 |
87 requestAnimationFrameID = null; |
102 requestAnimationFrameID = null; |
|
103 |
|
104 if(rearm) requestHMIAnimation(); |
88 } |
105 } |
89 |
106 |
90 function requestHMIAnimation() { |
107 function requestHMIAnimation() { |
91 if(requestAnimationFrameID == null){ |
108 if(requestAnimationFrameID == null){ |
92 requestAnimationFrameID = window.requestAnimationFrame(animate); |
109 requestAnimationFrameID = window.requestAnimationFrame(animate); |
210 } |
227 } |
211 }); |
228 }); |
212 } |
229 } |
213 |
230 |
214 |
231 |
215 var page_fading_in_progress = false; |
232 var page_fading = "off"; |
|
233 var page_fading_args = "off"; |
216 function fading_page_switch(...args){ |
234 function fading_page_switch(...args){ |
217 svg_root.classList.add("fade-out-page"); |
235 if(page_fading == "in_progress") |
218 page_fading_in_progress = true; |
236 page_fading = "forced"; |
219 |
237 else |
220 setTimeout(function(){ |
238 page_fading = "pending"; |
221 switch_page(...args); |
239 page_fading_args = args; |
222 },1); |
240 |
|
241 requestHMIAnimation(); |
|
242 |
223 } |
243 } |
224 document.body.style.backgroundColor = "black"; |
244 document.body.style.backgroundColor = "black"; |
225 |
245 |
226 // subscribe to per instance current page hmi variable |
246 // subscribe to per instance current page hmi variable |
227 // PLC must prefix page name with "!" for page switch to happen |
247 // PLC must prefix page name with "!" for page switch to happen |