Perspective Style Class Breathing Synchronization

Hi All,

I have a perspective style class called breathing. it fades in and out between two colours and works well. I use mapping to change the border style of a UDT instance when a certain number of alarms have been reached for the instance.

The problem is that they aren't synchronized between the UDT instances as they would become active at different times. is there a way to lock the timing of the style class that they use the same start-stop timing?

Thanks in advance

1 Like

Other similar posts have discussed the topic, and the general consensus is that you can't do it with CSS only and it is quite involved to implement well with JavaScript.

However, with some VERY janky JavaScript and @victordcq's Markdown injection method:

Create a new markdown component and disable escapeHtml

Then create an expression binding on the source prop containing the style class to target and a script transform with the code below:

def transform(self, value, quality, timestamp):
	code =  """<img style='display:none' src='/favicon.ico' onload=\"	
		var targetNode = document.documentElement;
		var observerConfig = { subtree: true, attributes: true, attributeFilter: ['class'] };
		
		var mutationCallback = function(mutationsList, observer) {
		    mutationsList.forEach(function(mutation) {
		        if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
		            var targetElement = mutation.target;
		            if (targetElement.classList.contains('psc-igStyleClass')) {
		                var elements = document.querySelectorAll('.psc-igStyleClass');
					    elements.forEach(function(element) {
					    	var animation = element.style.animation;
					    	element.style.animation = 'none';
					        void element.offsetWidth;
					        element.style.animation = animation;
					    });		              
		            }
		        }
		    });
		};
		
		var observer = new MutationObserver(mutationCallback);
		observer.observe(targetNode, observerConfig);
	\"></img>""".replace("\n", "").replace("\t", "").replace("igStyleClass",value)
	return code

The code basically setups a mutation observer, that monitors for the animated class being added to an element, then loops through all elements with that class and reset their animations. All animation will be reset to the start, which is not ideal...

this is not really a save replace, because "className" is something that exists as an attribute in Js, you should use someting with a special character infront or something so its definitly not gonna be mistaken

1 Like