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

Commit

Permalink
Add checks durinf imagesLoaded wait to ensure tooltip doesn't 'stick'…
Browse files Browse the repository at this point in the history
… when mousing over the target element quickly
  • Loading branch information
Craga89 committed Apr 3, 2013
1 parent 5c88d38 commit 196ded1
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/core.js
Expand Up @@ -5,13 +5,14 @@ function QTip(target, options, id, attr)
{
// Declare this reference
var self = this,
docBody = document.body,
tooltipID = NAMESPACE + '-' + id,
isPositioning = 0,
isDrawing = 0,
tooltip = $(),
namespace = '.qtip-' + id,
disabledClass = 'qtip-disabled',
isPositioning = 0,
isDrawing = 0,
isWaiting = 0,
hiddenDuringWait = 0,
elements, cache;

// Setup class attributes
Expand Down Expand Up @@ -204,7 +205,10 @@ function QTip(target, options, id, attr)
}

// Ensure images have loaded...
return elem.imagesLoaded().promise();
isWaiting = TRUE;
return elem.imagesLoaded()
.done(function() { isWaiting = FALSE; })
.promise();
}

function updateContent(content, reposition)
Expand All @@ -221,7 +225,9 @@ function QTip(target, options, id, attr)

// Handle deferred content
if($.isFunction(content.then)) {
isWaiting = TRUE;
return content.then(function(c) {
isWaiting = FALSE;
return updateContent(c, reposition);
}, null, function(c) {
return updateContent(c, reposition);
Expand All @@ -237,7 +243,10 @@ function QTip(target, options, id, attr)
else { elem.html(content); }

// Ensure images have loaded...
return elem.imagesLoaded().promise();
isWaiting = TRUE;
return elem.imagesLoaded()
.done(function() { isWaiting = FALSE; })
.promise();
}

function assignEvents()
Expand Down Expand Up @@ -277,7 +286,7 @@ function QTip(target, options, id, attr)
// Define hide method
function hideMethod(event)
{
if(tooltip.hasClass(disabledClass) || isPositioning || isDrawing) { return FALSE; }
if(tooltip.hasClass(disabledClass) || isDrawing) { return FALSE; }

// Check if new target was actually the tooltip element
var relatedTarget = $(event.relatedTarget),
Expand Down Expand Up @@ -673,10 +682,11 @@ function QTip(target, options, id, attr)
// Reset flags
isPositioning = 0;

// Show tooltip if needed
if(options.show.ready || show) {
// Show tooltip if not hidden during wait period
if(!hiddenDuringWait && (options.show.ready || show)) {
self.toggle(TRUE, cache.event, FALSE);
}
hiddenDuringWait = FALSE;
});

return self;
Expand Down Expand Up @@ -774,6 +784,9 @@ function QTip(target, options, id, attr)

toggle: function(state, event)
{
// If we're currently waiting and we've just hidden... stop it
isWaiting && !state && (hiddenDuringWait = TRUE);

// Try to prevent flickering when tooltip overlaps show element
if(event) {
if((/over|enter/).test(event.type) && (/out|leave/).test(cache.event.type) &&
Expand All @@ -785,7 +798,7 @@ function QTip(target, options, id, attr)
// Cache event
cache.event = $.extend({}, event);
}

// Render the tooltip if showing and it isn't already
if(!self.rendered || self.destroyed) { return state ? self.render(1) : self; }

Expand All @@ -799,7 +812,7 @@ function QTip(target, options, id, attr)
animate = state || opts.target.length === 1,
sameTarget = !event || opts.target.length < 2 || cache.target[0] === event.target,
identicalState, allow, showEvent, delay;

// Detect state if valid one isn't provided
if((typeof state).search('boolean|number')) { state = !visible; }

Expand Down

0 comments on commit 196ded1

Please sign in to comment.