Destroy / hide tooltips for tooltips when using pjax

I'm having trouble twart bootstrap hints not to be removed from the DOM element when using pjax in a Rails application. For example, when I hang up an item using a tooltip, then click on a link to another page, the tooltip will freeze. My current solution for removing tooltips is as follows:

App.Utils.Tooltip = { triggerAll: function(element) { if (element.data('tooltip-loaded') == true) { return; } element.data('tooltip-loaded', true).tooltip().trigger('mouseover'); }, destroyAll: function() { var tooltips = ($('[rel=tooltip]').get()); $.each(tooltips, function() { $(this).tooltip('destroy'); }); } }; $(document).on('mouseover', '[rel=tooltip]', function() { App.Utils.Tooltip.triggerAll($(this)); }); $(document).on('pjax:beforeSend', function() { App.Utils.Tooltip.destroyAll(); }); 

Is there a more efficient / efficient way to do this?

+4
source share
1 answer

The tooltip plugin stops you from instantiating it twice, so no verification is needed, you can simplify your code to the next.

 App.Utils.Tooltip = { triggerAll: function(element) { element.tooltip('show'); }, destroyAll: function() { $('[rel=tooltip]').tooltip('destroy'); } }; 
+1
source

All Articles