bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Since 2.3 tooltips and popovers are broken when Prototype.js is included.

Open paales opened this issue 13 years ago • 17 comments

The problem is that the parent is hidden when the tooltip is hidden.

bootstrap-tooltip.js:

  , hide: function () {
      var that = this
        , $tip = this.tip()
        , e = $.Event('hide')

      this.$element.trigger(e)
      if (e.isDefaultPrevented()) return
....

The line this.$element.trigger(e) causes problems, causes the parent element (the button, link or text) to be hidden. When I remove prototype.js everything works as expected. When I remove the this.$element.trigger(e) code, everything works as expected.

jQuery 1.9 (with noConflict of course) and prototype 1.7, any suggestions how to fix this?

paales avatar Feb 13 '13 16:02 paales

I have the same problem on a Magento installation (which uses Prototype) with a Bootstrap theme. Also with noConflict mode. The only fix I could find was to comment the line out.

leeuwd avatar Feb 16 '13 10:02 leeuwd

Third-party libraries are technically not officially supported. Would still be nice to know the cause of such weirdness of course.

cvrebert avatar Feb 17 '13 12:02 cvrebert

PrototypeJS adds methods to the Element prototype so when jQuery tries to trigger the hide() method on an element it is actually firing the PrototypeJS hide() method, which is equivalent to the jQuery hide() method and sets the style of the element to display:none;

solutions to this

  1. remove the line of code like you did
  2. use a different event name for that event
  3. use the Prototype version of Bootstrap that I've created, linked below

I've not completed all of the Javascript Modules but I've done what I think are the most popular, Tooltips and Popovers are done.

http://github.com/jwestbrook/bootstrap-prototype

jwestbrook avatar Feb 17 '13 20:02 jwestbrook

I have found that popovers are broken in 2.3 and I do not include prototype. Reverting to 2.2.2 with no other change makes them work again.

rivets avatar Feb 22 '13 13:02 rivets

I got used to the fact that popovers get more and more broken on every release. But this time regular 2 hours of debugging do not help. "data-popover-data" gets cleaned up in random manner, or popovers disappear or get trimmed within "collapse". Have to revert to 2.2.2 as well.

DenysVuika avatar Feb 26 '13 20:02 DenysVuika

@rivets: how, specifically, are they broken for you?

cvrebert avatar Feb 26 '13 20:02 cvrebert

Please stop polluting this issue, this issue is about the tooltips/popovers + prototype not working, not about some misconfiguration or running an old jQuery version.

paales avatar Feb 27 '13 10:02 paales

I have a same issue with bootstrap and Magento, but my ticket was closed, with help of paales I was able to fix it by renaming hide() method to hideTooltip().

Nazariy avatar Mar 01 '13 14:03 Nazariy

@captainpete I'm willing to bet this pull request will be closed given the outcome of #5318. The way we addressed was in addition to calling the plugin on an element(s) to also drop the hide() definition, e.g. element.hide = undefined. jQuery.noop() is another option.

dgsmith2 avatar Mar 08 '13 03:03 dgsmith2

Thanks @dgsmith2. That fills in the gaps somewhat. As mentioned on #7130, there's a few open pull-requests overloading the same events from different modules, seems namespacing the events is close-at-hand.

captainpete avatar Mar 08 '13 05:03 captainpete

Experiencing the same problem with Wordpress.

digitalclutch avatar Mar 23 '13 15:03 digitalclutch

in 3.0 we've changed the event name (by namespacing events) – this should solve your guy's problem - cheers

fat avatar May 25 '13 06:05 fat

3.0 uses namespace

var e = $.Event('hide.bs.' + this.type)

That won't solve this issue with Prototype since jQuery will call the canonical event name 'hide' which will still conflict with the Prototype hide() method on the element.

The event name itself needs to change, eg, 'bs:hide.' + this.type (to use Backbone-inspired namespacing).

moos avatar Jun 06 '13 22:06 moos

@fat why you don't use namespace like moos suggested (Backbone Namespacing)?

christian-schwan avatar Jul 03 '13 20:07 christian-schwan

event namespacing did not fix this issue using bootstrap 3.0.0 and prototype 1.7

gschueler avatar Sep 05 '13 20:09 gschueler

There's supposedly still some .trigger() vs .triggerHandler() problem, and nobody has submitted a patch against v3 for it.

cvrebert avatar Sep 05 '13 21:09 cvrebert

I found that after you call your bootstrap .tooltip() function on your element, you can simply add an action (when the tooltip is hidden) that removes the "display:hidden" style on your element (that has been imposed by Prototype).

By doing this, you are not removing anything from either the bootstrap or prototype libraries. You should be forward compatible with future libraries (if you update either one in the future).

Example:

<span class='tooltipped' title='This is my tooltip text'>Hover to see my tooltip</span>
jQuery(document).ready(function() {
  jQuery(".tooltipped").tooltip();          
  jQuery(".tooltipped").on("hidden.bs.tooltip", 
                                         function() { 
                                           jQuery(this).css("display", "");
                                         });
});

bdevnich avatar Jun 04 '14 17:06 bdevnich