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

Commit

Permalink
Better destroy improvements to re-allocate memory properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Feb 11, 2013
1 parent 73551a9 commit 772eb68
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 82 deletions.
4 changes: 2 additions & 2 deletions dist/jquery.qtip.css
@@ -1,12 +1,12 @@
/*!
* qTip2 - Pretty powerful tooltips - v2.0.1-10-
* qTip2 - Pretty powerful tooltips - v2.0.1-11-
* http://qtip2.com
*
* Copyright (c) 2013 Craig Michael Thompson
* Released under the MIT, GPL licenses
* http://jquery.org/license
*
* Date: Sat Feb 9 2013 07:53 GMT+0000
* Date: Mon Feb 11 2013 11:13 GMT+0000
* Plugins: svg ajax tips modal viewport imagemap ie6
* Styles: basic css3
*/
Expand Down
98 changes: 58 additions & 40 deletions dist/jquery.qtip.js
@@ -1,12 +1,12 @@
/*!
* qTip2 - Pretty powerful tooltips - v2.0.1-10-
* qTip2 - Pretty powerful tooltips - v2.0.1-11-
* http://qtip2.com
*
* Copyright (c) 2013 Craig Michael Thompson
* Released under the MIT, GPL licenses
* http://jquery.org/license
*
* Date: Sat Feb 9 2013 07:53 GMT+0000
* Date: Mon Feb 11 2013 11:13 GMT+0000
* Plugins: svg ajax tips modal viewport imagemap ie6
* Styles: basic css3
*/
Expand Down Expand Up @@ -52,6 +52,7 @@
// Shortcut vars
QTIP, PLUGINS, MOUSE,
NAMESPACE = 'qtip',
HASATTR = 'data-hasqtip',
usedIDs = {},
widget = ['ui-widget', 'ui-tooltip'],
selector = 'div.qtip.'+NAMESPACE,
Expand Down Expand Up @@ -651,15 +652,15 @@ function QTip(target, options, id, attr)
function unassignEvents()
{
var targets = [
options.show.target[0],
options.hide.target[0],
self.rendered && elements.tooltip[0],
options.position.container[0],
options.position.viewport[0],
options.position.container.closest('html')[0], // unfocus
window,
document
];
options.show.target[0],
options.hide.target[0],
self.rendered && elements.tooltip[0],
options.position.container[0],
options.position.viewport[0],
options.position.container.closest('html')[0], // unfocus
window,
document
];

// Check if tooltip is rendered
if(self.rendered) {
Expand Down Expand Up @@ -1314,20 +1315,24 @@ function QTip(target, options, id, attr)

destroy: function()
{
// Set flag the signify destroy is taking place to plugins
// and ensure it only gets destroyed once!b
if(!(self.destroyed = !self.detroyed)) { return; }

var t = target[0],
title = $.attr(t, oldtitle),
elemAPI = target.data('qtip');

// Set flag the signify destroy is taking place to plugins
self.destroyed = TRUE;

// Destroy tooltip and any associated plugins if rendered
if(self.rendered) {
tooltip.stop(1,0).remove();

$.each(self.plugins, function() {
// Destroy all plugins
$.each(self.plugins, function(name) {
if(this.destroy) { this.destroy(); }
delete self.plugins[name];
});

// Remove all descendants and tooltip element
tooltip.stop(1,0).find('*').remove().end().remove();
}

// Clear timers and remove bound events
Expand All @@ -1338,11 +1343,11 @@ function QTip(target, options, id, attr)
// If the API if actually this qTip API...
if(!elemAPI || self === elemAPI) {
// Remove api object
$.removeData(t, 'qtip');
target.removeData('qtip').removeAttr(HASATTR);

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

Expand All @@ -1353,25 +1358,28 @@ function QTip(target, options, id, attr)
// Remove qTip events associated with this API
target.unbind('.qtip-'+id);

// Remove ID from sued id object
// Remove ID from used id objects, and delete object references
// for better garbage collection and leak protection
delete usedIDs[self.id];
delete self.options; delete self.elements;
delete self.cache; delete self.timers;
delete self.checks;

return target;
}
});
}

// Initialization method
function init(id, opts)
function init(elem, id, opts)
{
var obj, posOptions, attr, config, title,

// Setup element references
elem = $(this),
docBody = $(document.body),

// Use document body instead of document element if needed
newTarget = this === document ? docBody : elem,
newTarget = elem[0] === document ? docBody : elem,

// Grab metadata from element if plugin is present
metadata = (elem.metadata) ? elem.metadata(opts.metadata) : NULL,
Expand Down Expand Up @@ -1421,7 +1429,7 @@ function init(id, opts)
posOptions.my = new PLUGINS.Corner(posOptions.my);

// Destroy previous tooltip if overwrite is enabled, or skip element if not
if($.data(this, 'qtip')) {
if(elem.data('qtip')) {
if(config.overwrite) {
elem.qtip('destroy');
}
Expand All @@ -1430,18 +1438,23 @@ function init(id, opts)
}
}

// Add has-qtip attribute
elem.attr(HASATTR, true);

// Remove title attribute and store it if present
if(config.suppress && (title = $.attr(this, 'title'))) {
if(config.suppress && (title = elem.attr('title'))) {
// Final attr call fixes event delegatiom and IE default tooltip showing problem
$(this).removeAttr('title').attr(oldtitle, title).attr('title', '');
elem.removeAttr('title').attr(oldtitle, title).attr('title', '');
}

// Initialize the tooltip and add API reference
obj = new QTip(elem, config, id, !!attr);
$.data(this, 'qtip', obj);
elem.data('qtip', obj);

// Catch remove/removeqtip events on target element to destroy redundant tooltip
elem.one('remove.qtip-'+id+' removeqtip.qtip-'+id, function(){ obj.destroy(); });
elem.one('remove.qtip-'+id+' removeqtip.qtip-'+id, function() {
var api; if((api = $(this).data('qtip'))) { api.destroy(); }
});

return obj;
}
Expand Down Expand Up @@ -1515,7 +1528,7 @@ QTIP.bind = function(opts, event)
namespace = '.qtip-'+id+'-create';

// Initialize the qTip and re-grab newly sanitized options
api = init.call(this, id, opts);
api = init($(this), id, opts);
if(api === FALSE) { return TRUE; }
options = api.options;

Expand Down Expand Up @@ -1583,8 +1596,7 @@ QTIP.bind = function(opts, event)

// Prerendering is enabled, create tooltip now
if(options.show.ready || options.prerender) { hoverIntent(event); }
})
.attr('data-hasqtip', TRUE);
});
};

// Setup base plugins
Expand Down Expand Up @@ -1741,16 +1753,16 @@ $.each(PLUGINS.fn, function(name, func) {
if(!$.ui) {
$['cleanData'+replaceSuffix] = $.cleanData;
$.cleanData = function( elems ) {
for(var i = 0, elem; (elem = elems[i]) !== undefined; i++) {
try { $( elem ).triggerHandler('removeqtip'); }
for(var i = 0, elem; (elem = elems[i]) !== undefined && elem.getAttribute(HASATTR); i++) {
try { $( elem ).triggerHandler('removeqtip');}
catch( e ) {}
}
$['cleanData'+replaceSuffix]( elems );
};
}

// Set global qTip properties
QTIP.version = '2.0.1-10-';
QTIP.version = '2.0.1-11-';
QTIP.nextid = 0;
QTIP.inactiveEvents = 'click dblclick mousedown mouseup mousemove mouseleave mouseenter'.split(' ');
QTIP.zindex = 15000;
Expand Down Expand Up @@ -2401,7 +2413,7 @@ function Tip(qTip, command)
elems.tip.html(vml + vml);

// Prevent mousing down on the tip since it causes problems with .live() handling in IE due to VML
$('*', elems.tip).bind('click mousedown', function(event) { event.stopPropagation(); });
$('*', elems.tip).bind('click'+namespace+' mousedown'+namespace, function(event) { event.stopPropagation(); });
}
},

Expand Down Expand Up @@ -2619,12 +2631,19 @@ function Tip(qTip, command)

destroy: function()
{
// Remove the tip element
if(elems.tip) { elems.tip.remove(); }
elems.tip = false;

// Unbind events
tooltip.unbind(namespace);

// Remove the tip element(s)
if(elems.tip) {
elems.tip.find('*').remove()
.end().remove();
}

// Delete references
delete self.corner;
delete self.mimic;
delete self.size;
}
});

Expand Down Expand Up @@ -2996,7 +3015,6 @@ $.extend(TRUE, QTIP.defaults, {
}
});


PLUGINS.viewport = function(api, position, posOptions, targetWidth, targetHeight, elemWidth, elemHeight)
{
var target = posOptions.target,
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.qtip.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery.qtip.min.js

Large diffs are not rendered by default.

0 comments on commit 772eb68

Please sign in to comment.