How to customize Twitter Bootstrap popover hide animation

javascript, jquery, twitter-bootstrap

Solution

Nice question-brain-teaser! You can definitely do it. Take a look how you can extend plugin without messing with original source code:

$.fn.popover = function (orig) {
  return function(options) {
    return this.each(function() {
      orig.call($(this), options);
      if (typeof options.hide == 'function') {
        $(this).data('bs.popover').hide = function() {
          options.hide.call(this.$tip, this);
          orig.Constructor.prototype.hide.call(this);
        };
      }
    });
  }
}($.fn.popover);

Here we go! We extended default popover functionality with our own. Now lets use it:

$('.three').popover({
  placement: 'bottom',
  hide: function() {
    $(this).animate({marginTop: -100}, function() {
      $(this).css({marginTop: ''});
    });
  }
});

Above popover will have custom animation effect while hiding.

Of course if you don't provide `hide` option you will have default behavior.

Demo: http://jsfiddle.net/VHDwa/71/

Problem

I would like to implement my own popover hide animation. Currently, I am modifying bootstrap.js directly. ``` $.fn.popover = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('popover') , options = typeof option == 'object' && option if (!data) $this.data('popover', (data = new Popover(this, options))) //original code // if (typeof option == 'string') data[option]() //custom code if (typeof option == 'string') { if (option === 'hide') { //my customize animation here } else { data[option](); } } }) } ``` I would like to know if there are anyway so I can achieve a dynamic animation when I init the popover ``` $('#target').popover({ hide: function () { //my own animation } }); ```

Original source