简体   繁体   English

Rails Bootstrap工具提示样式不起作用

[英]Rails bootstrap tooltip style not working

I have a rails 4.0 site using bootstrap 3.0. 我有一个使用Bootstrap 3.0的Rails 4.0站点。 The tooltip is displaying but with no style. 工具提示正在显示,但没有样式。 The bootstrap example shows that the markup will look like this 引导程序示例显示标记将如下所示

<div class="tooltip">
  <div class="tooltip-inner">
  </div>
  <div class="tooltip-arrow"></div>
</div>

However when I inspect it, the markup generated looks like it is jQuery not bootstrap. 但是,当我检查它时,生成的标记看起来像是jQuery而不是自举。

<div id="ui-tooltip-18 role="tooltip" class="ui-tooltip ui-widget ui-corner-all ui-widget-content">
</div>

Here is my application.js 这是我的application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require twitter/bootstrap
//= require_tree .

Here is my JavaScript calling the tooltip 这是我的JavaScript调用工具提示

$(function(){
  $('[data-toggle=tooltip]').tooltip();
});

Here is my markup on the page: 这是我在页面上的标记:

<h3>Verifications</h3>
<table>
  <% @verification_types.each do |type| %>
    <tr>
      <td><%= link_to "#{type.name}", '#', data: { toggle: "tooltip" }, title: "Default title" %></td>
    </tr>
  <% end %>
</table>

I hate this way around it but I got it to work. 我讨厌这种方式,但我能使它正常工作。 I had to add a js file I called it fix_tooltip.js and added this to it $.fn.bstooltip = $.fn.tooltip; 我必须添加一个名为fix_tooltip.js的js文件,并将其添加到其中。 $.fn.bstooltip = $.fn.tooltip; then in my script that is calling tooltip it now does $('[data-toggle]').bstooltip(); 然后在我的调用tooltip脚本中,它现在执行$('[data-toggle]').bstooltip(); It feels really hacky and don't like it. 感觉真的很hack,不喜欢它。 But I couldn't get it to work by changing the jQuery-UI tooltip. 但是我无法通过更改jQuery-UI工具提示来使其工作。

I ended up with the following working solution: 我得到了以下可行的解决方案:

application.js 的application.js

//= require jquery
//= require bootstrap
//= require fix_conflict
//= require jquery.ui.all
//= require jquery_ujs
//= require others
//= require_tree .

fix_conflict.js (thanks for @covard) fix_conflict.js(感谢@covard)

$.fn.bstooltip = $.fn.tooltip;

others.js others.js

$('.form a').bstooltip();
#IMPORTANT: Make sure to target the exact element on which the tooltip is defined

HTML HTML

<form class='form' ...>
  ...
  <a href='#' data-toggle='tooltip' title="some tooltip text>?</a>
  ...
 </form>

IMPORTANT : As mentioned above - targeting the exact element where the tooltip is defined is important. 重要信息 :如上所述,定位定义工具提示的确切元素非常重要。 Otherwise when using a generic targeting $('.form').bstooltip() I ended up with the JQuery styling/tooltip 否则,当使用通用目标$('.form').bstooltip()我最终得到了JQuery样式/工具提示

@tamersalama 's answer helped me figure out a simple solution: @tamersalama的回答帮助我找到了一个简单的解决方案:

Do not include all jquery-ui plugins but rather just those you need (minus the tooltip plugin) 不包括所有jquery-ui插件,而是仅包括您需要的插件(减去工具提示插件)

Here's my application.js: 这是我的application.js:

//= require jquery
//= require jquery-ui/autocomplete
//= require jquery-ui/datepicker
//= require jquery_ujs
//= require bootstrap
//= require_tree .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM