Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Added some .destory() upgrades to prevent memory leaks and add better…
Browse files Browse the repository at this point in the history
… multi-tooltip support
  • Loading branch information
Craga89 committed Sep 13, 2011
1 parent 694390b commit 437b5af
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 35 deletions.
29 changes: 18 additions & 11 deletions dist/jquery.qtip.basic.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 01:18:55 2011 +0100
* Date: Tue Sep 13 17:05:46 2011 +0100
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down Expand Up @@ -1473,7 +1473,8 @@ function QTip(target, options, id, attr)
destroy: function()
{
var t = target[0],
title = $.attr(t, oldtitle);
title = $.attr(t, oldtitle),
elemAPI = target.data('qtip');

// Destroy tooltip and any associated plugins if rendered
if(self.rendered) {
Expand All @@ -1489,17 +1490,23 @@ function QTip(target, options, id, attr)
clearTimeout(self.timers.hide);
unassignEvents();

// Remove api object
$.removeData(t, 'qtip');
// If the API if actually this qTip API...
if(!elemAPI || self === elemAPI) {
// Remove api object
$.removeData(t, 'qtip');

// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
}

// Remove ARIA attributes
target.removeAttr('aria-describedby');
}

// Remove ARIA attributes and bound qtip events
target.removeAttr('aria-describedby').unbind('.qtip');
// Remove qTip events associated with this API
target.unbind('.qtip-'+id);

// Remove ID from sued id object
delete usedIDs[self.id];
Expand Down Expand Up @@ -1589,7 +1596,7 @@ function init(id, opts)
$.data(this, 'qtip', obj);

// Catch remove events on target element to destroy redundant tooltip
elem.bind('remove.qtip', function(){ obj.destroy(); });
elem.bind('remove.qtip-'+id, function(){ obj.destroy(); });

return obj;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.qtip.css
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 01:18:55 2011 +0100
* Date: Tue Sep 13 17:05:46 2011 +0100
*/

/* Core qTip styles */
Expand Down
29 changes: 18 additions & 11 deletions dist/jquery.qtip.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 01:18:55 2011 +0100
* Date: Tue Sep 13 17:05:46 2011 +0100
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down Expand Up @@ -1473,7 +1473,8 @@ function QTip(target, options, id, attr)
destroy: function()
{
var t = target[0],
title = $.attr(t, oldtitle);
title = $.attr(t, oldtitle),
elemAPI = target.data('qtip');

// Destroy tooltip and any associated plugins if rendered
if(self.rendered) {
Expand All @@ -1489,17 +1490,23 @@ function QTip(target, options, id, attr)
clearTimeout(self.timers.hide);
unassignEvents();

// Remove api object
$.removeData(t, 'qtip');
// If the API if actually this qTip API...
if(!elemAPI || self === elemAPI) {
// Remove api object
$.removeData(t, 'qtip');

// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
}

// Remove ARIA attributes
target.removeAttr('aria-describedby');
}

// Remove ARIA attributes and bound qtip events
target.removeAttr('aria-describedby').unbind('.qtip');
// Remove qTip events associated with this API
target.unbind('.qtip-'+id);

// Remove ID from sued id object
delete usedIDs[self.id];
Expand Down Expand Up @@ -1589,7 +1596,7 @@ function init(id, opts)
$.data(this, 'qtip', obj);

// Catch remove events on target element to destroy redundant tooltip
elem.bind('remove.qtip', function(){ obj.destroy(); });
elem.bind('remove.qtip-'+id, function(){ obj.destroy(); });

return obj;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.qtip.min.js

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions src/core.js
Expand Up @@ -1410,7 +1410,8 @@ function QTip(target, options, id, attr)
destroy: function()
{
var t = target[0],
title = $.attr(t, oldtitle);
title = $.attr(t, oldtitle),
elemAPI = target.data('qtip');

// Destroy tooltip and any associated plugins if rendered
if(self.rendered) {
Expand All @@ -1426,17 +1427,23 @@ function QTip(target, options, id, attr)
clearTimeout(self.timers.hide);
unassignEvents();

// Remove api object
$.removeData(t, 'qtip');
// If the API if actually this qTip API...
if(!elemAPI || self === elemAPI) {
// Remove api object
$.removeData(t, 'qtip');

// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
// Reset old title attribute if removed
if(options.suppress && title) {
$.attr(t, 'title', title);
target.removeAttr(oldtitle);
}

// Remove ARIA attributes
target.removeAttr('aria-describedby');
}

// Remove ARIA attributes and bound qtip events
target.removeAttr('aria-describedby').unbind('.qtip');
// Remove qTip events associated with this API
target.unbind('.qtip-'+id);

// Remove ID from sued id object
delete usedIDs[self.id];
Expand Down Expand Up @@ -1526,7 +1533,7 @@ function init(id, opts)
$.data(this, 'qtip', obj);

// Catch remove events on target element to destroy redundant tooltip
elem.bind('remove.qtip', function(){ obj.destroy(); });
elem.bind('remove.qtip-'+id, function(){ obj.destroy(); });

return obj;
}
Expand Down

0 comments on commit 437b5af

Please sign in to comment.