Closed eikes closed 13 years ago
It can be, as shown on the AJAX sample on this site.
content: function () {
var $el = $(this);
$.get('api.php', function (data) {
$el.html(data).show();
});
return 'Fallback content';
}
What you are showing is how "this" is bound to the tooltipsy element itself but there is no way to access the node which triggered the tooltip.
My extension allows the following:
<span class="a">Oh hai!</span>
<span style="display: none">
<span class="c">
More <a href="http://example.com">Info</a>!
</span>
</span>
<script>
$('.a').tooltipsy({
content: function(el) {
return $(el).next().find(".c");
});
</script>
This is very useful as you can embed html to display in the tooltip next to the element that will show it.
still okay
var $el = $(this);
$el.data('rootel').whatever();
That can't work, because this.$tip.data('rootel', this.$el);
is set after the content function is called, which causes rootel
to be undefined
at the time.
It works though if the last two lines in readify
are changed to:
this.$tip = $('<div class="' + this.settings.className + '">').appendTo(this.$tipsy);
this.$tip.data('rootel', this.$el);
this.$tip.html(this.settings.content != '' ? this.settings.content(this.$el) : this.title);
I can open another pull request if you like.
great eye!
If that's the only change in your pull request, I'll pull.
Thanks again!
provide the current element to the content function to allow it to access its "data-" attributes and traverse the DOM from there to find content etc.