如何在bootstrap核心文件之外添加以下热修复程序?
这个问题之前已经发布过,而且热修复确实像魅力一样。但它需要编辑核心文件。 here!
在Tooltip.prototype.show函数中:
$tip
.detach()
.css({ top: 0, left: 0, display: 'block' })
.addClass(placement)
在下面添加add-class就像魅力一样:
.addClass(this.$element.attr("data-class"))
现在,每当您向弹出式调用添加data-class
时,它都会将该属性添加到<div class="popover">
div。
缺点是您必须编辑核心文件才能实现此目的。我只是略微精通它jQuery,这已经让我的大脑震惊,但我认为必须有一种方法可以将.addClass()作为Tooltip Prototype的扩展。也许使用.extend()?
答案 0 :(得分:0)
!function($){
$.extend($.fn.tooltip.Constructor.DEFAULTS,{
dataClass: false
});
var Tooltip = $.fn.tooltip.Constructor;
_show = Tooltip.prototype.show;
Tooltip.prototype.show = function (){
_show.apply(this,Array.prototype.slice.apply(arguments));
if (this.options.dataClass!=="undefined" && this.options.dataClass){
var that = this;
var $tip = this.tip();
if (this.$element.attr("data-class") !== undefined)
$tip.addClass(this.$element.attr("data-class"));
}
};
}(jQuery);