aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorjzaefferer <joern.zaefferer@gmail.com>2010-12-22 18:58:57 +0100
committerjzaefferer <joern.zaefferer@gmail.com>2010-12-22 18:58:57 +0100
commit0479ab6af6414c7a8e779c3cab3e7e8406f9eb62 (patch)
treecab8e0ea33ef3db131877d307a2b7c7099b7709e /ui
parent3552947c19b8ea1b779dc9809783c6ac6a218d68 (diff)
parent1fd34199efa9ddc35276b415cad8e7e37a6cc856 (diff)
downloadjquery-ui-0479ab6af6414c7a8e779c3cab3e7e8406f9eb62.tar.gz
jquery-ui-0479ab6af6414c7a8e779c3cab3e7e8406f9eb62.zip
Merge remote branch 'origin/tooltip'
Conflicts: demos/autocomplete/combobox.html demos/index.html tests/unit/index.html
Diffstat (limited to 'ui')
-rw-r--r--ui/jquery.ui.tooltip.js137
1 files changed, 137 insertions, 0 deletions
diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js
new file mode 100644
index 000000000..ea3cde339
--- /dev/null
+++ b/ui/jquery.ui.tooltip.js
@@ -0,0 +1,137 @@
+/*
+ * jQuery UI Tooltip @VERSION
+ *
+ * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * http://docs.jquery.com/UI/Tooltip
+ *
+ * Depends:
+ * jquery.ui.core.js
+ * jquery.ui.widget.js
+ * jquery.ui.position.js
+ */
+(function($) {
+
+var increments = 0;
+
+$.widget("ui.tooltip", {
+ options: {
+ items: "[title]",
+ content: function() {
+ return $(this).attr("title");
+ },
+ position: {
+ my: "left center",
+ at: "right center",
+ offset: "15 0"
+ }
+ },
+ _create: function() {
+ var self = this;
+ this.tooltip = $("<div></div>")
+ .attr("id", "ui-tooltip-" + increments++)
+ .attr("role", "tooltip")
+ .attr("aria-hidden", "true")
+ .addClass("ui-tooltip ui-widget ui-corner-all ui-widget-content")
+ .appendTo(document.body)
+ .hide();
+ this.tooltipContent = $("<div></div>")
+ .addClass("ui-tooltip-content")
+ .appendTo(this.tooltip);
+ this.opacity = this.tooltip.css("opacity");
+ this.element
+ .bind("focus.tooltip mouseover.tooltip", function(event) {
+ self.open( event );
+ })
+ .bind("blur.tooltip mouseout.tooltip", function(event) {
+ self.close( event );
+ });
+ },
+
+ enable: function() {
+ this.options.disabled = false;
+ },
+
+ disable: function() {
+ this.options.disabled = true;
+ },
+
+ destroy: function() {
+ this.tooltip.remove();
+ $.Widget.prototype.destroy.apply(this, arguments);
+ },
+
+ widget: function() {
+ return this.element.pushStack(this.tooltip.get());
+ },
+
+ open: function(event) {
+ var target = $(event && event.target || this.element).closest(this.options.items);
+ // 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) {
+ // 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);
+ }
+ },
+
+ _show: function(event, target, content) {
+ if (!content)
+ return;
+
+ target.attr("title", "");
+
+ if (this.options.disabled)
+ return;
+
+ this.tooltipContent.html(content);
+ this.tooltip.css({
+ top: 0,
+ left: 0
+ }).show().position( $.extend({
+ of: target
+ }, this.options.position )).hide();
+
+ this.tooltip.attr("aria-hidden", "false");
+ target.attr("aria-describedby", this.tooltip.attr("id"));
+
+ this.tooltip.stop(false, true).fadeIn();
+
+ this._trigger( "open", event );
+ },
+
+ close: function(event) {
+ if (!this.current)
+ return;
+
+ var current = this.current;
+ this.current = null;
+ current.attr("title", this.currentTitle);
+
+ if (this.options.disabled)
+ return;
+
+ current.removeAttr("aria-describedby");
+ this.tooltip.attr("aria-hidden", "true");
+
+ this.tooltip.stop(false, true).fadeOut();
+
+ this._trigger( "close", event );
+ }
+
+});
+
+})(jQuery); \ No newline at end of file