2014-01-06 24 views
1

如何在bootstrap核心文件之外添加以下修復程序?如何使用動態類data-attr擴展Bootstrap 3 popover/tooltip?

此問題已在之前發佈,而且此修補程序確實可以像魅力一樣工作。但它需要編輯核心文件。 here

在Tooltip.prototype.show功能:

$tip 
    .detach() 
    .css({ top: 0, left: 0, display: 'block' }) 
    .addClass(placement) 

添加下面的作品加載類喜歡一個魅力:

.addClass(this.$element.attr("data-class")) 

所以,現在只要添加data-class到酥料餅的調用,它將該屬性添加到<div class="popover"> div。

不利的一面是你必須編輯核心文件來實現這一點。我只是稍微精通了jQuery,這讓我的大腦發抖,但我認爲必須有一種方法來解決.addClass()作爲Tooltip Prototype的擴展。也許使用.extend()?

回答

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); 
+0

- 在部署工具提示功能時添加「dataClass」。 –

+0

- 在元素上創建數據類屬性 –