Permalink
Browse files

Added $.fn.tipsy.revalidate() to remove dangling tooltips from the DOM.

1 parent 9fe119e commit 8cd3dbc6e4814507a444afe847fec13c832c47bf @jaz303 committed Jun 24, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 src/javascripts/jquery.tipsy.js
View
17 src/javascripts/jquery.tipsy.js
@@ -9,6 +9,13 @@
return (typeof thing == 'function') ? (thing.call(ctx)) : thing;
};
+ function isElementInDOM(ele) {
+ while (ele = ele.parentNode) {
+ if (ele == document) return true;
+ }
+ return false;
+ };
+
function Tipsy(element, options) {
this.$element = $(element);
this.options = options;
@@ -104,6 +111,7 @@
tip: function() {
if (!this.$tip) {
this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
+ this.$tip.data('tipsy-pointee', this.$element[0]);
@adriengibrat
adriengibrat Jun 26, 2012

data 'tipsy-pointee' is never really set to the tooltip as it's not already in the DOM...

@kmiyashiro
kmiyashiro Jul 3, 2012

Calling revalidate just hides all tipsys.. I don't think this is working as intended.

}
return this.$tip;
},
@@ -191,6 +199,15 @@
trigger: 'hover'
};
+ $.fn.tipsy.revalidate = function() {
+ $('.tipsy').each(function() {
+ var pointee = $.data(this, 'tipsy-pointee');
+ if (!pointee || !isElementInDOM(pointee)) {
+ $(this).remove();
+ }
+ });
+ };
+
// Overwrite this method to provide options on a per-element basis.
// For example, you could store the gravity in a 'tipsy-gravity' attribute:
// return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });

1 comment on commit 8cd3dbc

@adriengibrat

Yes, since tipsy-pointee is always null... This commit fix this bug: #108

Please sign in to comment.