Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltipster close all before opening a new one, click/hover combination

I'm using tooltipster to build some call-outs. I've some on click, some on hover.

JS:

var instances = $.tooltipster.instances();

$('.mgu-click').tooltipster({
  functionBefore: function(instance, helper) {
    $.each(instances, function(i, instance) {
      instance.close();
    });
  },
  contentCloning: true,
  trigger: 'click',
  'maxWidth': 280,
  'minHeight': 280,
  animation: 'grow',
  interactive: true,
  arrow: false,
  distance: -10,
  contentAsHTML: true,
  theme: 'tooltipster-shadow'
});
$('.mgu-hover').tooltipster({
  functionBefore: function(instance, helper) {
    $.each(instances, function(i, instance) {
      instance.close();
    });
  },
  contentCloning: true,
  trigger: (browser.hasTouchEvents()) ? 'click' : 'hover',
  'maxWidth': 280,
  'minHeight': 280,
  animation: 'grow',
  interactive: true,
  arrow: false,
  distance: -10,
  contentAsHTML: true,
  theme: 'tooltipster-shadow'
});

If you click or move to a tooltipster-btn all other should close before the selected open. The functionBefore work fine with the trigger: click. But if i call the one with trigger hover, all other dont close.

thanks for help

like image 488
Stiller Eugen Avatar asked Dec 05 '25 06:12

Stiller Eugen


1 Answers

It looks like you need to call the $.tooltipster.instances() method within the functionBefore function for a reference to the latest instances:

functionBefore: function(instance, helper){
  $.each($.tooltipster.instances(), function(i, instance){
    instance.close();
  });
}
like image 186
Josh Crozier Avatar answered Dec 07 '25 19:12

Josh Crozier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!