Skip to content

Conversation

eikes
Copy link
Contributor

@eikes eikes commented Jul 28, 2011

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.

…cess its "data-" attributes and traverse the DOM from there to find content etc.
@briancray
Copy link
Owner

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';
    }

@eikes
Copy link
Contributor Author

eikes commented Jul 28, 2011

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.

@briancray
Copy link
Owner

still okay

var $el = $(this);
$el.data('rootel').whatever();

@eikes
Copy link
Contributor Author

eikes commented Jul 28, 2011

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.

@briancray
Copy link
Owner

great eye!

If that's the only change in your pull request, I'll pull.

Thanks again!

@eikes eikes closed this Jul 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants