How to use Tooltips (bootstrap-tooltip.js) and Popovers (bootstrap-popover.js)?

Tooltips

<a rel="tooltip" href="#" data-original-title="Tooltip text">lorem ipsum</a>

Popovers

<a data-content="Popover text" rel="popover" class="btn btn-danger" href="#" data-original-title="A Title">hover for popover</a>

I have no results, where is an error?

bootstrap-tooltip.js and bootstrap-popover.js are enabled in theme

Comments

marcheidemann’s picture

what did you wrote into your script?

<script>

marcheidemann’s picture

first of all: you copied the code from inspect, it should be title

Stan.Ezersky’s picture

Thanks for question!

For Tooltips

  <script>
!function( $ ){
	$(function () {	
			$('a[rel=tooltip]').tooltip();
		});
}( window.jQuery ) 
  </script>
<a href="#" rel="tooltip" title="This is the tooltip">lorem ipsum</a>

For Popovers

!function( $ ){
	$(function () {	
			$('a[rel=popover]').popover();
		});
}( window.jQuery )
<a data-content="And here's some amazing content. It's very engaging. right?" rel="popover" class="btn btn-danger" href="#" data-original-title="A Title">hover for popover</a>
Docc’s picture

Stan this is not the place to ask about help on implanting and usage of twitter bootstrap.

But if you would like people to help you then please give more info.
Drupal version, project version, JQuery version, any JS errors(important), etc.

It works fine over here so you probably got something wrong somewhere.

frankbaele’s picture

Status: Active » Closed (works as designed)
andregriffin’s picture

Project: Twitter's Bootstrap » Bootstrap
zdean’s picture

Status: Closed (works as designed) » Active

In reference to #4 above, my setup:

Drupal 7.22
Bootstrap 7.x-2.0-beta3
JQuery 1.7

I've set up a sub-theme. In my .info file, I've added:

scripts[] = bootstrapcustom.js

In my bootstrapcustom.js file, I've added:

(function($) {
 $('a').tooltip();
})(jQuery);

In my html, I've added:

<a href="#" title="hello"><i class="icon-pencil"></i></a>

The result is a normal tooltip with the text (small yellow box with "hello"), not the Bootstrap style tooltip.

I'd be happy to turn this into a help doc if anyone can point me in the right direction for making it work.

Thanks!

markhalliwell’s picture

Status: Active » Closed (works as designed)

This is because you aren't wrapping your code in a $(document).ready() function. Also given the way Drupal works, it's loading the script at the top before the rest of the page has been rendered. So technically, there are no <a/> tags present yet when the script executes.

MarcoPBazz’s picture

#zdean

maybe I find out a solution:

  1. Add scripts[] = bootstrap-tooltip.js (https://gist.github.com/pseidemann/4458612)
  2. add (function($) {
    $('a').tooltip();
    })(jQuery);

    at the bottom of html.tpl

Works for me, hope 'll be helpfull

dariogcode’s picture

According to B3, the markup should include data-toggle, the my code looks like

(function($) {
	$(document).ready(function() {
		$('[data-toggle=tooltip]').tooltip();
	});
})(jQuery);
henryhu’s picture

Issue summary: View changes

The following code is working for me in B3:

(function($) {
  $(document).ready(function() {
    $('[data-toggle=popover]').popover();
  });
})(jQuery);
markhalliwell’s picture

You wouldn't have to implement it manually if you didn't exclude the base theme's ./js/bootstrap.js.

Binu Varghese’s picture

The page @ http://getbootstrap.com/javascript/#tooltips says:

"For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself."

One way is to add the below script at the bottom of your theme's html.tpl.php (before the closing body tag)

(function($) { $(document).ready(function() { $('[data-toggle=tooltip]').tooltip(); }); })(jQuery);
coreteamvn’s picture

For me the example didnt work (using bootstrap 3) and the tooltip didnt show up in panels.

This worked:
<a class="btn btn-danger" href="#" data-toggle="tooltip" data-original-title="A Title">hover for tooltip</a>

sano’s picture

re: #12 - one must also not forget to turn on popovers and/or tooltips in the /admin/appearance/settings/ like your's truly forgot to do. Then no custom javascript insertion is necessary (if not removed as Marc mentions).