2010-04-08 21:21:47 +00:00
|
|
|
/*
|
|
|
|
* jQuery UI Tooltip @VERSION
|
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:36:06 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2010-04-08 21:21:47 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Tooltip
|
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* jquery.ui.core.js
|
|
|
|
* jquery.ui.widget.js
|
2010-07-09 13:36:06 +00:00
|
|
|
* jquery.ui.position.js
|
2010-04-08 21:21:47 +00:00
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
var increments = 0;
|
|
|
|
|
|
|
|
$.widget("ui.tooltip", {
|
|
|
|
options: {
|
2010-10-26 15:07:22 +00:00
|
|
|
items: "[title]",
|
2010-04-08 21:21:47 +00:00
|
|
|
content: function() {
|
|
|
|
return $(this).attr("title");
|
|
|
|
},
|
|
|
|
position: {
|
|
|
|
my: "left center",
|
|
|
|
at: "right center",
|
|
|
|
offset: "15 0"
|
|
|
|
}
|
|
|
|
},
|
2010-10-26 12:41:14 +00:00
|
|
|
_create: function() {
|
2010-04-08 21:21:47 +00:00
|
|
|
var self = this;
|
|
|
|
this.tooltip = $("<div></div>")
|
|
|
|
.attr("id", "ui-tooltip-" + increments++)
|
|
|
|
.attr("role", "tooltip")
|
|
|
|
.attr("aria-hidden", "true")
|
2010-10-26 12:32:03 +00:00
|
|
|
.addClass("ui-tooltip ui-widget ui-corner-all ui-widget-content")
|
2010-04-08 21:21:47 +00:00
|
|
|
.appendTo(document.body)
|
|
|
|
.hide();
|
|
|
|
this.tooltipContent = $("<div></div>")
|
|
|
|
.addClass("ui-tooltip-content")
|
|
|
|
.appendTo(this.tooltip);
|
|
|
|
this.opacity = this.tooltip.css("opacity");
|
|
|
|
this.element
|
2010-10-26 15:07:22 +00:00
|
|
|
.bind("focus.tooltip mouseover.tooltip", function(event) {
|
2010-04-15 07:45:35 +00:00
|
|
|
self.open( event );
|
2010-04-08 21:21:47 +00:00
|
|
|
})
|
2010-10-26 15:07:22 +00:00
|
|
|
.bind("blur.tooltip mouseout.tooltip", function(event) {
|
2010-04-15 07:45:35 +00:00
|
|
|
self.close( event );
|
2010-04-08 21:21:47 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
enable: function() {
|
|
|
|
this.options.disabled = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
disable: function() {
|
|
|
|
this.options.disabled = true;
|
|
|
|
},
|
|
|
|
|
2011-01-14 22:11:22 +00:00
|
|
|
_destroy: function() {
|
2010-04-08 21:21:47 +00:00
|
|
|
this.tooltip.remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
widget: function() {
|
2010-07-30 12:30:43 +00:00
|
|
|
return this.element.pushStack(this.tooltip.get());
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
open: function(event) {
|
2010-10-26 15:07:22 +00:00
|
|
|
var target = $(event && event.target || this.element).closest(this.options.items);
|
2011-02-26 14:06:06 +00:00
|
|
|
if ( !target.length ) {
|
|
|
|
return;
|
|
|
|
}
|
2010-04-08 21:21:47 +00:00
|
|
|
// already visible? possible when both focus and mouseover events occur
|
|
|
|
if (this.current && this.current[0] == target[0])
|
|
|
|
return;
|
|
|
|
var self = this;
|
|
|
|
this.current = target;
|
|
|
|
this.currentTitle = target.attr("title");
|
|
|
|
var content = this.options.content.call(target[0], function(response) {
|
2011-02-26 14:04:33 +00:00
|
|
|
// IE may instantly serve a cached response, need to give it a chance to finish with _open before that
|
2010-10-21 19:03:48 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
// ignore async responses that come in after the tooltip is already hidden
|
|
|
|
if (self.current == target)
|
2011-02-26 14:04:33 +00:00
|
|
|
self._open(event, target, response);
|
2010-10-21 19:03:48 +00:00
|
|
|
}, 13);
|
2010-04-08 21:21:47 +00:00
|
|
|
});
|
|
|
|
if (content) {
|
2011-02-26 14:04:33 +00:00
|
|
|
self._open(event, target, content);
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-02-26 14:04:33 +00:00
|
|
|
_open: function(event, target, content) {
|
2010-04-08 21:21:47 +00:00
|
|
|
if (!content)
|
|
|
|
return;
|
|
|
|
|
|
|
|
target.attr("title", "");
|
|
|
|
|
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.tooltipContent.html(content);
|
|
|
|
this.tooltip.css({
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
2010-07-20 12:00:43 +00:00
|
|
|
}).show().position( $.extend({
|
2010-04-08 21:21:47 +00:00
|
|
|
of: target
|
2010-07-20 12:00:43 +00:00
|
|
|
}, this.options.position )).hide();
|
2010-04-08 21:21:47 +00:00
|
|
|
|
|
|
|
this.tooltip.attr("aria-hidden", "false");
|
|
|
|
target.attr("aria-describedby", this.tooltip.attr("id"));
|
|
|
|
|
2010-10-21 19:03:48 +00:00
|
|
|
this.tooltip.stop(false, true).fadeIn();
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
this._trigger( "open", event );
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
close: function(event) {
|
2010-04-08 21:21:47 +00:00
|
|
|
if (!this.current)
|
|
|
|
return;
|
|
|
|
|
2010-12-03 17:14:20 +00:00
|
|
|
var current = this.current;
|
2010-04-08 21:21:47 +00:00
|
|
|
this.current = null;
|
2010-12-03 17:14:20 +00:00
|
|
|
current.attr("title", this.currentTitle);
|
2010-04-08 21:21:47 +00:00
|
|
|
|
|
|
|
if (this.options.disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
current.removeAttr("aria-describedby");
|
|
|
|
this.tooltip.attr("aria-hidden", "true");
|
|
|
|
|
2010-10-21 19:03:48 +00:00
|
|
|
this.tooltip.stop(false, true).fadeOut();
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
this._trigger( "close", event );
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-02-03 17:01:26 +00:00
|
|
|
$.ui.tooltip.version = "@VERSION";
|
|
|
|
|
2010-04-08 21:21:47 +00:00
|
|
|
})(jQuery);
|