Skip to content
Permalink
Browse files

Tooltip: Adding another ajax example to visual testcase. Fixing async…

… response handling (taking IE cached response quirk into account) and simplifying fade animations a ton.
  • Loading branch information...
jzaefferer committed Oct 21, 2010
1 parent 96977ed commit 732a485676a1dcbefc16fdb9d26774b622410138
Showing with 29 additions and 13 deletions.
  1. +21 −0 tests/visual/tooltip/tooltip.html
  2. +8 −13 ui/jquery.ui.tooltip.js
@@ -44,6 +44,24 @@
return "Loading...";
}
});
// asynchronous content with caching
var content;
$("#ajax2").tooltip({
content: function(response) {
if (content) {
return content;
}
$.ajax({
url: "ajaxcontent.php",
cache: false,
success: function(result) {
content = result;
response(result);
}
});
return "Loading...";
}
});
// custom position
$("#right2").tooltip({
@@ -117,6 +135,9 @@
<div id="ajax" style="width: 100px;" class="ui-widget-content" title="never be seen">
gets its content via ajax
</div>
<div id="ajax2" style="width: 100px;" class="ui-widget-content" title="never be seen">
gets its content via ajax, caches the response
</div>

<div id="context2" class="ui-widget ui-widget-content">
<span title="something" style="border:1px solid blue">span</span>
@@ -82,9 +82,12 @@ $.widget("ui.tooltip", {
this.current = target;
this.currentTitle = target.attr("title");
var content = this.options.content.call(target[0], function(response) {
// ignore async responses that come in after the tooltip is already hidden
if (self.current == target)
self._show(event, target, response);
// IE may instantly serve a cached response, need to give it a chance to finish with _show before that
setTimeout(function() {
// ignore async responses that come in after the tooltip is already hidden
if (self.current == target)
self._show(event, target, response);
}, 13);
});
if (content) {
self._show(event, target, content);
@@ -111,10 +114,7 @@ $.widget("ui.tooltip", {
this.tooltip.attr("aria-hidden", "false");
target.attr("aria-describedby", this.tooltip.attr("id"));

if (this.tooltip.is(":animated"))
this.tooltip.stop().show().fadeTo("normal", this.opacity);
else
this.tooltip.is(':visible') ? this.tooltip.fadeTo("normal", this.opacity) : this.tooltip.fadeIn();
this.tooltip.stop(false, true).fadeIn();

this._trigger( "open", event );
},
@@ -132,12 +132,7 @@ $.widget("ui.tooltip", {
current.removeAttr("aria-describedby");
this.tooltip.attr("aria-hidden", "true");

if (this.tooltip.is(':animated'))
this.tooltip.stop().fadeTo("normal", 0, function() {
$(this).hide().css("opacity", "");
});
else
this.tooltip.stop().fadeOut();
this.tooltip.stop(false, true).fadeOut();

this._trigger( "close", event );
}

0 comments on commit 732a485

Please sign in to comment.
You can’t perform that action at this time.