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

Commit

Permalink
Add triggering flag to fix destroy on hide bug. Also ensure we hide i…
Browse files Browse the repository at this point in the history
…f calling destroy() when rendered
  • Loading branch information
Craga89 committed Apr 16, 2013
1 parent 37c6c1b commit 581224d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/core/class.js
Expand Up @@ -26,7 +26,7 @@ function QTip(target, options, id, attr) {

// Set the initial flags
this.rendered = this.destroyed = this.disabled = this.waiting =
this.hiddenDuringWait = this.positioning = FALSE;
this.hiddenDuringWait = this.positioning = this.triggering = FALSE;
}
PROTOTYPE = QTip.prototype;

Expand Down Expand Up @@ -156,7 +156,8 @@ PROTOTYPE.toggle = function(state, event) {
this.waiting && !state && (this.hiddenDuringWait = TRUE);

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

var type = state ? 'show' : 'hide',
opts = this.options[type],
Expand Down Expand Up @@ -534,12 +535,13 @@ PROTOTYPE.destroy = function(immediate) {
// Set flag the signify destroy is taking place to plugins
// and ensure it only gets destroyed once!
if(this.destroyed) { return this.target; }
this.destroyed = TRUE;

function process() {
var target = this.target,
title = target.attr(oldtitle),
elemAPI = target.data(NAMESPACE);
title = target.attr(oldtitle);

// Set flag
this.destroyed = TRUE;

// Destroy tooltip if rendered
if(this.rendered) {
Expand All @@ -556,16 +558,13 @@ PROTOTYPE.destroy = function(immediate) {
clearTimeout(this.timers.hide);
this._unassignEvents();

// If the API if actually this qTip API...
if(!elemAPI || this === elemAPI) {
// Remove api object and ARIA attributes
target.removeData(NAMESPACE).removeAttr(HASATTR)
.removeAttr('aria-describedby');
// Remove api object and ARIA attributes
target.removeData(NAMESPACE).removeAttr(HASATTR)
.removeAttr('aria-describedby');

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

// Remove qTip events associated with this API
Expand All @@ -578,8 +577,9 @@ PROTOTYPE.destroy = function(immediate) {
}

// If an immediate destory is needed
if(immediate !== TRUE) {
if(immediate !== TRUE && this.rendered) {
tooltip.one('tooltiphidden', $.proxy(process, this));
!this.triggering && this.hide();
}

// If we're not in the process of hiding... process
Expand Down
3 changes: 3 additions & 0 deletions src/core/events.js
Expand Up @@ -87,7 +87,10 @@ PROTOTYPE._bind = function(target, events, method, suffix) {
PROTOTYPE._trigger = function(type, args, event) {
var callback = $.Event('tooltip'+type);
callback.originalEvent = (event && $.extend({}, event)) || this.cache.event || NULL;

this.triggering = TRUE;
this.tooltip.trigger(callback, [this].concat(args || []));
this.triggering = FALSE;

return !callback.isDefaultPrevented();
};
Expand Down

0 comments on commit 581224d

Please sign in to comment.