Mockup patterns - trigger callback after loaded (Plone6/ClassicUI)

Apologies for the noob question: I want to manipulate the DOM after patterns have loaded. Can I register something to happen after registry.scan() or should I just use a MutationObserver to check for the "patterns-loaded" class on the body? Would there be any efficiency difference?

You could add an event listener to any initialized pattern with:

$(".pat-<patternname>").on("init.<pattername>.patterns", () => {
    // callback 
});

unfortunately there is no event when all patterns are initialized (@thet please correct me if I'm wrong), so you have to check the body class patterns-loaded as you've already mentioned.

2 Likes

@petschki @Esoth that's right - there is yet no event which is thrown after all pattterns have loaded.

I wonder why. I will add one for the next Patternslib release.

However - the Patterns are loaded by registry.scan asynchronously. So the patterns-loaded body class can be set before each pattern has finished initialization.

The safest thing is really to wait for an individual pattern to be loaded, like @petschki mentioned.

1 Like