briancray / tooltipsy

Introducing a jQuery tooltip plugin for control-obsessed designers.
http://tooltipsy.com
MIT License
326 stars 97 forks source link

Pass the object to the :content option #1

Closed abrcoelho closed 13 years ago

abrcoelho commented 13 years ago

When using tooltipsy on a link and trying to fetch the content with AJAX, I couldn't get the link's href.

<a class="tooltipsy" href="?option=10">List item</a>

So I had no choice but to use the hard-coded URL for the request (like the original sample):

$('.hastip').tooltipsy({
    content: function () {
        var $el = $(this);
        $.get('api.php', function (data) {
            $el.html(data).show();
        });
        return 'Fallback content';
    },
    css: {
        'padding': '10px',
        'max-width': '200px',
        'color': '#303030',
        'background-color': '#f5f5b5',
        'border': '1px solid #deca7e',
        '-moz-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        '-webkit-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'text-shadow': 'none'
    }
});

Is there a way that I'm missing or is it really an issue? Thanks in advance.

briancray commented 13 years ago

Are you trying to get ?option=10 as the URL for the AJAX call?

If so, it's:

$('.hastip').tooltipsy({
    content: function () {
        var $el = $(this);
        $.get($el.attr('href'), function (data) {
            $el.html(data).show();
        });
        return 'Fallback content';
    },
    css: {
        'padding': '10px',
        'max-width': '200px',
        'color': '#303030',
        'background-color': '#f5f5b5',
        'border': '1px solid #deca7e',
        '-moz-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        '-webkit-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'text-shadow': 'none'
    }
});
abrcoelho commented 13 years ago

That's exactly what I'm trying to say, but I get a "undefined" on my console.log when I try to get the href via $el.attr('href'). I checked and all links are alright.

It seemed to me that $el was returning the tooltip element, not the hovered element.

briancray commented 13 years ago

OMG you're right. Sorry, working on something else so brain is elsewhere. Lemme do a quick update and get back to you :P

briancray commented 13 years ago

Updated code. Try this.

$('.hastip').tooltipsy({
    content: function () {
        var $el = $(this);
        $.get($el.data('rootel').attr('href'), function (data) {
            $el.html(data).show();
        });
        return 'Fallback content';
    },
    css: {
        'padding': '10px',
        'max-width': '200px',
        'color': '#303030',
        'background-color': '#f5f5b5',
        'border': '1px solid #deca7e',
        '-moz-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        '-webkit-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'text-shadow': 'none'
    }
});
abrcoelho commented 13 years ago

Wow, it was a "really quick update". And it worked like a charm! =)

Thanks a lot! Later I'll give you a feedback about my experience with tooltipsy on this project!

briancray commented 13 years ago

I'd love to hear it!

Cheers