diff --git a/tests/unit/index.html b/tests/unit/index.html
index 4882098d7..ad8c96433 100644
--- a/tests/unit/index.html
+++ b/tests/unit/index.html
@@ -19,27 +19,6 @@
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -69,6 +48,7 @@
Progressbar
Slider
Tabs
+ Tooltip
Utilities
diff --git a/tests/unit/tooltip/tooltip.html b/tests/unit/tooltip/tooltip.html
new file mode 100644
index 000000000..37bfeafce
--- /dev/null
+++ b/tests/unit/tooltip/tooltip.html
@@ -0,0 +1,43 @@
+
+
+
+
+ jQuery UI Tooltip Test Suite
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/unit/tooltip/tooltip_core.js b/tests/unit/tooltip/tooltip_core.js
new file mode 100644
index 000000000..247927df4
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_core.js
@@ -0,0 +1,11 @@
+/*
+ * tooltip_core.js
+ */
+
+
+(function($) {
+
+module("tooltip: core");
+
+
+})(jQuery);
diff --git a/tests/unit/tooltip/tooltip_defaults.js b/tests/unit/tooltip/tooltip_defaults.js
new file mode 100644
index 000000000..bcdcd4307
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_defaults.js
@@ -0,0 +1,16 @@
+/*
+ * tooltip_defaults.js
+ */
+
+var tooltip_defaults = {
+ disabled: false,
+ content: $.ui.tooltip.prototype.options.content,
+ tooltipClass: "ui-widget-content",
+ position: {
+ my: "left center",
+ at: "right center",
+ offset: "15 0"
+ }
+};
+
+commonWidgetTests('tooltip', { defaults: tooltip_defaults });
diff --git a/tests/unit/tooltip/tooltip_events.js b/tests/unit/tooltip/tooltip_events.js
new file mode 100644
index 000000000..51c56b62e
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_events.js
@@ -0,0 +1,54 @@
+/*
+ * tooltip_events.js
+ */
+(function($) {
+
+module("tooltip: events");
+
+test("programmatic triggers", function() {
+ expect(2);
+ var e = $("#tooltipped1").tooltip({
+ open: function(event, ui) {
+ same( event.type, "tooltipopen" );
+ },
+ close: function(event, ui) {
+ same( event.type, "tooltipclose" );
+ }
+ });
+ e.tooltip("open").tooltip("close");
+ e.tooltip("destroy");
+});
+
+test("mouse events", function() {
+ expect(4);
+ var e = $("#tooltipped1").tooltip({
+ open: function(event, ui) {
+ same( event.type, "tooltipopen" );
+ same( event.originalEvent.type, "mouseenter" );
+ },
+ close: function(event, ui) {
+ same( event.type, "tooltipclose" );
+ same( event.originalEvent.type, "mouseleave" );
+ }
+ });
+ e.trigger("mouseover").trigger("mouseout");
+ e.tooltip("destroy");
+});
+
+test("focus events", function() {
+ expect(4);
+ var e = $("#tooltipped1").tooltip({
+ open: function(event, ui) {
+ same( event.type, "tooltipopen" );
+ same( event.originalEvent.type, "focus" );
+ },
+ close: function(event, ui) {
+ same( event.type, "tooltipclose" );
+ same( event.originalEvent.type, "blur" );
+ }
+ });
+ e.trigger("focus").trigger("blur");
+ e.tooltip("destroy");
+});
+
+})(jQuery);
diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js
new file mode 100644
index 000000000..867923dd0
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_methods.js
@@ -0,0 +1,23 @@
+/*
+ * tooltip_methods.js
+ */
+(function($) {
+
+
+module("tooltip: methods");
+
+test("destroy", function() {
+ var beforeHtml = $("#tooltipped1").parent().html();
+ var afterHtml = $("#tooltipped1").tooltip().tooltip("destroy").parent().html();
+ equal( afterHtml, beforeHtml );
+});
+
+test("open", function() {
+ var e = $("#tooltipped1").tooltip();
+ ok( $(".ui-tooltip").is(":hidden") );
+ e.tooltip("open");
+ ok( $(".ui-tooltip").is(":visible") );
+ $(":ui-tooltip").tooltip("destroy");
+});
+
+})(jQuery);
diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js
new file mode 100644
index 000000000..e0262a947
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_options.js
@@ -0,0 +1,39 @@
+/*
+ * tooltip_options.js
+ */
+(function($) {
+
+module("tooltip: options");
+
+function contentTest(name, expected, impl) {
+ test(name, function() {
+ $("#tooltipped1").tooltip({
+ content: impl
+ }).tooltip("open");
+ same( $(".ui-tooltip").text(), expected );
+ $(":ui-tooltip").tooltip("destroy");
+ });
+}
+
+contentTest("content: default", "anchortitle");
+contentTest("content: return string", "customstring", function() {
+ return "customstring";
+});
+contentTest("content: callback string", "customstring2", function(response) {
+ response("customstring2");
+});
+
+test("tooltipClass, default", function() {
+ $("#tooltipped1").tooltip().tooltip("open");
+ same( $(".ui-tooltip").attr("class"), "ui-tooltip ui-widget ui-corner-all ui-widget-content");
+ $(":ui-tooltip").tooltip("destroy");
+});
+test("tooltipClass, custom", function() {
+ $("#tooltipped1").tooltip({
+ tooltipClass: "pretty fancy"
+ }).tooltip("open");
+ same( $(".ui-tooltip").attr("class"), "ui-tooltip ui-widget ui-corner-all pretty fancy");
+ $(":ui-tooltip").tooltip("destroy");
+});
+
+})(jQuery);
diff --git a/tests/unit/tooltip/tooltip_tickets.js b/tests/unit/tooltip/tooltip_tickets.js
new file mode 100644
index 000000000..5d6d0ef86
--- /dev/null
+++ b/tests/unit/tooltip/tooltip_tickets.js
@@ -0,0 +1,10 @@
+/*
+ * tooltip_tickets.js
+ */
+(function($) {
+
+module("tooltip: tickets");
+
+
+
+})(jQuery);
diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js
index 166bff407..13c809f45 100644
--- a/ui/jquery.ui.tooltip.js
+++ b/ui/jquery.ui.tooltip.js
@@ -49,10 +49,10 @@ $.widget("ui.tooltip", {
this.opacity = this.tooltip.css("opacity");
this.element
.bind("focus.tooltip mouseenter.tooltip", function(event) {
- self.open();
+ self.open( event );
})
.bind("blur.tooltip mouseleave.tooltip", function(event) {
- self.close();
+ self.close( event );
});
},
@@ -73,7 +73,7 @@ $.widget("ui.tooltip", {
return this.tooltip;
},
- open: function() {
+ open: function(event) {
var target = this.element;
// already visible? possible when both focus and mouseover events occur
if (this.current && this.current[0] == target[0])
@@ -84,14 +84,14 @@ $.widget("ui.tooltip", {
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(target, response);
+ self._show(event, target, response);
});
if (content) {
- self._show(target, content);
+ self._show(event, target, content);
}
},
- _show: function(target, content) {
+ _show: function(event, target, content) {
if (!content)
return;
@@ -116,10 +116,10 @@ $.widget("ui.tooltip", {
else
this.tooltip.is(':visible') ? this.tooltip.fadeTo("normal", this.opacity) : this.tooltip.fadeIn();
- this._trigger( "open" );
+ this._trigger( "open", event );
},
- close: function() {
+ close: function(event) {
if (!this.current)
return;
@@ -137,7 +137,7 @@ $.widget("ui.tooltip", {
else
this.tooltip.stop().fadeOut();
- this._trigger( "close" );
+ this._trigger( "close", event );
}
});