mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
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.
This commit is contained in:
parent
96977edecc
commit
732a485676
@ -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>
|
||||
|
21
ui/jquery.ui.tooltip.js
vendored
21
ui/jquery.ui.tooltip.js
vendored
@ -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 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user