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

Commit

Permalink
Few small fixes to hideMethod that prevent hiding issues when reposit…
Browse files Browse the repository at this point in the history
…ioning and event propagation
  • Loading branch information
Craga89 committed Aug 1, 2011
1 parent b772f04 commit 94ceb31
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 35 deletions.
12 changes: 5 additions & 7 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: Mon Jul 25 12:30:35 2011 +0100
* Date: Wed Jul 27 20:23:08 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 @@ -448,7 +448,7 @@ function QTip(target, options, id, attr)
// Define hide method
function hideMethod(event)
{
if(tooltip.hasClass(disabled)) { return FALSE; }
if(tooltip.hasClass(disabled) || isPositioning || isDrawing) { return FALSE; }

// Check if new target was actually the tooltip element
var relatedTarget = $(event.relatedTarget || event.target),
Expand All @@ -461,7 +461,7 @@ function QTip(target, options, id, attr)

// Prevent hiding if tooltip is fixed and event target is the tooltip. Or if mouse positioning is enabled and cursor momentarily overlaps
if((posOptions.target === 'mouse' && ontoTooltip) || (options.hide.fixed && ((/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget)))) {
event.preventDefault(); return;
event.preventDefault(); event.stopImmediatePropagation(); return;
}

// If tooltip has displayed, start hide timer
Expand Down Expand Up @@ -1411,14 +1411,12 @@ function QTip(target, options, id, attr)

disable: function(state)
{
var c = disabled;

if('boolean' !== typeof state) {
state = !(tooltip.hasClass(c) || cache.disabled);
state = !(tooltip.hasClass(disabled) || cache.disabled);
}

if(self.rendered) {
tooltip.toggleClass(c, state);
tooltip.toggleClass(disabled, state);
$.attr(tooltip[0], 'aria-disabled', state);
}
else {
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: Mon Jul 25 12:30:35 2011 +0100
* Date: Wed Jul 27 20:23:08 2011 +0100
*/

/* Core qTip styles */
Expand Down
23 changes: 11 additions & 12 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: Mon Jul 25 12:30:35 2011 +0100
* Date: Wed Jul 27 20:23:08 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 @@ -448,7 +448,7 @@ function QTip(target, options, id, attr)
// Define hide method
function hideMethod(event)
{
if(tooltip.hasClass(disabled)) { return FALSE; }
if(tooltip.hasClass(disabled) || isPositioning || isDrawing) { return FALSE; }

// Check if new target was actually the tooltip element
var relatedTarget = $(event.relatedTarget || event.target),
Expand All @@ -461,7 +461,7 @@ function QTip(target, options, id, attr)

// Prevent hiding if tooltip is fixed and event target is the tooltip. Or if mouse positioning is enabled and cursor momentarily overlaps
if((posOptions.target === 'mouse' && ontoTooltip) || (options.hide.fixed && ((/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget)))) {
event.preventDefault(); return;
event.preventDefault(); event.stopImmediatePropagation(); return;
}

// If tooltip has displayed, start hide timer
Expand Down Expand Up @@ -1411,14 +1411,12 @@ function QTip(target, options, id, attr)

disable: function(state)
{
var c = disabled;

if('boolean' !== typeof state) {
state = !(tooltip.hasClass(c) || cache.disabled);
state = !(tooltip.hasClass(disabled) || cache.disabled);
}

if(self.rendered) {
tooltip.toggleClass(c, state);
tooltip.toggleClass(disabled, state);
$.attr(tooltip[0], 'aria-disabled', state);
}
else {
Expand Down Expand Up @@ -1937,7 +1935,7 @@ function Ajax(api)
// Make sure default event hasn't been prevented
if(event && event.isDefaultPrevented()) { return self; }

var hasSelector = opts.url.indexOf(' '),
var hasSelector = opts.url.indexOf(' '),
url = opts.url,
selector,
hideFirst = opts.once && !opts.loading && first;
Expand All @@ -1955,6 +1953,9 @@ function Ajax(api)
function after() {
// Re-display tip if loading and first time, and reset first flag
if(hideFirst) { tooltip.css('visibility', ''); first = FALSE; }

// Call users complete if it was defined
if($.isFunction(opts.complete)) { opts.complete.apply(this, arguments); }
}

// Define success handler
Expand All @@ -1972,15 +1973,13 @@ function Ajax(api)

// Set the content
api.set('content.text', content);

after(); // Call common callback
}

// Error handler
function errorHandler(xh, status, error){ api.set('content.text', status + ': ' + error); after(); }
function errorHandler(xh, status, error){ api.set('content.text', status + ': ' + error); }

// Setup $.ajax option object and process the request
$.ajax( $.extend({ success: successHandler, error: errorHandler, context: api }, opts, { url: url }) );
$.ajax( $.extend({ success: successHandler, error: errorHandler, context: api }, opts, { url: url, complete: after }) );

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/ajax.js
Expand Up @@ -40,7 +40,7 @@ function Ajax(api)
// Make sure default event hasn't been prevented
if(event && event.isDefaultPrevented()) { return self; }

var hasSelector = opts.url.indexOf(' '),
var hasSelector = opts.url.indexOf(' '),
url = opts.url,
selector,
hideFirst = opts.once && !opts.loading && first;
Expand All @@ -58,6 +58,9 @@ function Ajax(api)
function after() {
// Re-display tip if loading and first time, and reset first flag
if(hideFirst) { tooltip.css('visibility', ''); first = FALSE; }

// Call users complete if it was defined
if($.isFunction(opts.complete)) { opts.complete.apply(this, arguments); }
}

// Define success handler
Expand All @@ -75,15 +78,13 @@ function Ajax(api)

// Set the content
api.set('content.text', content);

after(); // Call common callback
}

// Error handler
function errorHandler(xh, status, error){ api.set('content.text', status + ': ' + error); after(); }
function errorHandler(xh, status, error){ api.set('content.text', status + ': ' + error); }

// Setup $.ajax option object and process the request
$.ajax( $.extend({ success: successHandler, error: errorHandler, context: api }, opts, { url: url }) );
$.ajax( $.extend({ success: successHandler, error: errorHandler, context: api }, opts, { url: url, complete: after }) );

return self;
}
Expand Down
10 changes: 4 additions & 6 deletions src/core.js
Expand Up @@ -385,7 +385,7 @@ function QTip(target, options, id, attr)
// Define hide method
function hideMethod(event)
{
if(tooltip.hasClass(disabled)) { return FALSE; }
if(tooltip.hasClass(disabled) || isPositioning || isDrawing) { return FALSE; }

// Check if new target was actually the tooltip element
var relatedTarget = $(event.relatedTarget || event.target),
Expand All @@ -398,7 +398,7 @@ function QTip(target, options, id, attr)

// Prevent hiding if tooltip is fixed and event target is the tooltip. Or if mouse positioning is enabled and cursor momentarily overlaps
if((posOptions.target === 'mouse' && ontoTooltip) || (options.hide.fixed && ((/mouse(out|leave|move)/).test(event.type) && (ontoTooltip || ontoTarget)))) {
event.preventDefault(); return;
event.preventDefault(); event.stopImmediatePropagation(); return;
}

// If tooltip has displayed, start hide timer
Expand Down Expand Up @@ -1348,14 +1348,12 @@ function QTip(target, options, id, attr)

disable: function(state)
{
var c = disabled;

if('boolean' !== typeof state) {
state = !(tooltip.hasClass(c) || cache.disabled);
state = !(tooltip.hasClass(disabled) || cache.disabled);
}

if(self.rendered) {
tooltip.toggleClass(c, state);
tooltip.toggleClass(disabled, state);
$.attr(tooltip[0], 'aria-disabled', state);
}
else {
Expand Down

0 comments on commit 94ceb31

Please sign in to comment.