I slightly modified PopOver to do what I want, not sure if it's the best
way or not, but my very simple tests worked fine. The real difference is
adding the popover content to the document in the constructor (maybe should
be init?) and then just showing/hiding the tip instead of adding and
removing it. Code shown below. Any thoughts?
!function ($) {
"use strict"; // jshint ;_;
/* POPOVEREX PUBLIC CLASS DEFINITION
* =============================== */
var PopoverEx = function (element, options) {
this.init('popoverex', element, options)
var $tip,
placement,
inside
$tip = this.tip()
this.setContent()
placement = typeof this.options.placement == 'function' ?
this.options.placement.call(this, $tip[0], this.$element[0]) :
this.options.placement
inside = /in/.test(placement)
$tip
.remove()
.css({ top: 0, left: 0, display: 'block' })
.appendTo(inside ? this.$element : document.body).hide()
}
/* NOTE: POPOVEREX EXTENDS BOOTSTRAP-POPOVER.js
========================================== */
PopoverEx.prototype = $.extend({}, $.fn.popover.Constructor.prototype, {
constructor: PopoverEx
, show: function () {
var $tip
, inside
, pos
, actualWidth
, actualHeight
, placement
, tp
if (this.hasContent() && this.enabled) {
$tip = this.tip()
if (this.options.animation) {
$tip.addClass('fade')
}
placement = typeof this.options.placement == 'function' ?
this.options.placement.call(this, $tip[0], this.$element[0]) :
this.options.placement
inside = /in/.test(placement)
$tip.show()
pos = this.getPosition(inside)
actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
switch (inside ? placement.split(' ')[1] : placement) {
case 'bottom':
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 -
actualWidth / 2}
break
case 'top':
tp = {top: pos.top - actualHeight, left: pos.left + pos.width /
2 - actualWidth / 2}
break
case 'left':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left:
pos.left - actualWidth}
break
case 'right':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left:
pos.left + pos.width}
break
}
$tip
.css(tp)
.addClass(placement)
.addClass('in')
}
}
, hide: function () {
var that = this
, $tip = this.tip()
$tip.removeClass('in')
function removeWithAnimation() {
var timeout = setTimeout(function () {
$tip.off($.support.transition.end).hide()
}, 500)
$tip.one($.support.transition.end, function () {
clearTimeout(timeout)
$tip.hide()
})
}
$.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() :
$tip.hide()
return this
}
})
/* POPOVEREX PLUGIN DEFINITION
* ======================= */
$.fn.popoverex = 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 PopoverEx(this,
options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.popoverex.Constructor = PopoverEx
$.fn.popoverex.defaults = $.extend({} , $.fn.popover.defaults, {
placement: 'right'
, trigger: 'click'
, content: ''
, template: '<div class="popover"><div class="arrow"></div><div
class="popover-inner"><h3 class="popover-title"></h3><div
class="popover-content"><p></p></div></div></div>'
})
}(window.jQuery);
On Tuesday, November 13, 2012 12:38:52 PM UTC-5, Jamie Johnson wrote:
> I am wondering if it's possible to not remove a tooltip on hide and
> instead just set it's visibility to none. I'm currently manually
> hiding/showing the popover element which works, but I am wondering if there
> is something built in that can be used to do this.