XF 2.2 Avoid duplicate tooltips?

Newsman

Member
I'm trying to build custom tooltips and use the tooltip.js as a base. So far, so good!

Everything works, but there is something I noticed that makes me wonder if it's intentional (and if so, why!): for example, you have the same user tagged twice (or more often) on the page.

When you hover over their name, it'll initialize the tooltip, which is normal. But when you do that again with another element that is associated with them (imagine a thread page with the same user appearing multiple times), it'll create a whole new tooltip despite using the exact same member data as the previous one.

Not just that, but if you hit the follow button in one tooltip, it only counts for that tooltip - when you check the other tooltip of the same member, it still shows up as "follow" instead of "unfollow".

What would be the best way to avoid this kind of behavior? Deleting the tooltip every time it goes away?

Cheers for any kind of enlightenment!
 
In the core, tooltips are cached to a container object when created (see XF.MemberTooltipCache) and returned from there if they already exist.
 
In the core, tooltips are cached to a container object when created (see XF.MemberTooltipCache) and returned from there if they already exist.

Right! But for some reason, it still creates another separate tooltip instead of loading (and I guess re-positioning) the already existing one..
 
Oh, I see what you mean. The tooltip objects themselves are scoped to each handler, and the cache is not updated when the contents of the tooltip changes. You might be able to cache the tooltip objects instead of the contents and adjust the trigger to point to those instead, but I haven't tested this. Otherwise you can forego caching, but if the contents are loaded from AJAX they will be re-requested each time.
 
Back
Top Bottom