0

I was using this code to keep popovers stay open on hover:

var originalLeave = $.fn.popover.Constructor.prototype.leave;
$.fn.popover.Constructor.prototype.leave = function(obj){
  var self = obj instanceof this.constructor ?
    obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
  var container, timeout;

  originalLeave.call(this, obj);

  if(obj.currentTarget) {
    container = $(obj.currentTarget).siblings('.popover')
    timeout = self.timeout;
    container.one('mouseenter', function(){
      //We entered the actual popover – call off the dogs
      clearTimeout(timeout);
      //Let's monitor popover content instead
      container.one('mouseleave', function(){
        $.fn.popover.Constructor.prototype.leave.call(self, self);
      });
    })
  }
};


$('body').popover({ selector: '[data-popover]', trigger: 'click hover', placement: 'auto', delay: {show: 50, hide: 400}});

Example here: http://jsfiddle.net/raving/2thfaxeu/

This works great on Bootstrap 3, however I'm now using the Bootstrap 4 alpha and this doesn't work anymore. I can't figure out how to get it to work and I can't find an answer anywhere. Could anyone help me modify this code to work with Bootstrap 4?

1 Answers1

2

Alright I found an answer. I looked through other Bootstrap 3 solutions and found one that I was able to tweak to work with Bootstrap 4. Also I forgot to mention this is using popovers with tether.js.

$(".trigger-link").popover({
  trigger: "manual",
}).on("mouseenter", function() {
  var _this = this;
  $(this).popover("show");
  $(".popover").on("mouseleave", function() {
    $(_this).popover('hide');
  });
}).on("mouseleave", function() {
  var _this = this;
  setTimeout(function() {
    if (!$(".popover:hover").length) {
      $(_this).popover("hide")
    }
  }, 100);
});