Skip to content

Commit

Permalink
Recompute tooltip text on every hover event
Browse files Browse the repository at this point in the history
  • Loading branch information
jaz303 committed Dec 22, 2009
1 parent ab2a5e5 commit 2181b15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/src/index.html.erb
Expand Up @@ -124,6 +124,9 @@ an anchor tag's title attribute.</p>
<p>Tipsy needs to erase any existing value for an element's <code>title</code> attribute in
order to suppress the browser's native tooltips. It is stashed in the element's
<code>original-title</code> attribute in case you need to retrieve it later.</p>

<p>As of version 0.1.4, the tooltip text is recomputed on every hover event so updating the
<code>title</code> attribute will have the expected effect.</p>

<h2 id='download'>Download</h2>

Expand Down
28 changes: 15 additions & 13 deletions src/javascripts/jquery.tipsy.js
Expand Up @@ -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 = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
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);
Expand Down

0 comments on commit 2181b15

Please sign in to comment.