From 2181b1521f3223a386c8d74ae7d891fa66f69dc3 Mon Sep 17 00:00:00 2001
From: Jason Frame
Date: Tue, 22 Dec 2009 01:23:21 +0000
Subject: [PATCH] Recompute tooltip text on every hover event
---
docs/src/index.html.erb | 3 +++
src/javascripts/jquery.tipsy.js | 28 +++++++++++++++-------------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/docs/src/index.html.erb b/docs/src/index.html.erb
index 5f604ae..94c25a5 100644
--- a/docs/src/index.html.erb
+++ b/docs/src/index.html.erb
@@ -124,6 +124,9 @@ an anchor tag's title attribute.
Tipsy needs to erase any existing value for an element's title
attribute in
order to suppress the browser's native tooltips. It is stashed in the element's
original-title
attribute in case you need to retrieve it later.
+
+As of version 0.1.4, the tooltip text is recomputed on every hover event so updating the
+ title
attribute will have the expected effect.
Download
diff --git a/src/javascripts/jquery.tipsy.js b/src/javascripts/jquery.tipsy.js
index 06f3569..e0c98d1 100644
--- a/src/javascripts/jquery.tipsy.js
+++ b/src/javascripts/jquery.tipsy.js
@@ -10,24 +10,26 @@
var tip = $.data(this, 'active.tipsy');
if (!tip) {
-
- var title = '';
- if (typeof opts.title == 'string') {
- title = $(this).attr(opts.title);
- } else if (typeof opts.title == 'function') {
- title = opts.title.call(this);
- }
-
- if (!title) title = opts.fallback;
-
tip = $('');
- tip.find('.tipsy-inner').text(title)
tip.css({position: 'absolute', zIndex: 100000});
- $(this).attr('original-title', $(this).attr('title') || '').attr('title', '');
$.data(this, 'active.tipsy', tip);
-
}
+ var title;
+ if (typeof opts.title == 'string') {
+ if (opts.title == 'title') {
+ title = $(this).attr(this.hasAttribute('title') ? 'title' : 'original-title');
+ } else {
+ title = $(this).attr(opts.title);
+ }
+ $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
+ } else if (typeof opts.title == 'function') {
+ title = opts.title.call(this);
+ }
+
+ if (!title) title = opts.fallback;
+ tip.find('.tipsy-inner').text(title);
+
var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);