Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide when clicking anywhere BUT the tooltip #13

Open
jackmcdade opened this issue Oct 4, 2011 · 7 comments
Open

Hide when clicking anywhere BUT the tooltip #13

jackmcdade opened this issue Oct 4, 2011 · 7 comments

Comments

@jackmcdade
Copy link
Contributor

Hey there, what would be the correct method for hiding the tooltipsy when you click anywhere BUT in the tooltip? For example, i'm using the tooltip to display some webapp controls, and i want them visible until you click elsewhere.

@briancray
Copy link
Owner

Try:

$('.hastip').tooltipsy();
$(document).click(function () {
    $('.hastip').data('tooltipsy').hide();
});

@briancray briancray reopened this Oct 4, 2011
@briancray
Copy link
Owner

Go ahead and close it if this fixes your issue. Also, instead of hide() you can do destroy() if you want the tooltip removed permanently from DOM.

@jackmcdade
Copy link
Contributor Author

Yeah i tried that, but it closes the tooltip when you click inside the tip too. Also, it only closes the first instance of a tooltip, it won't close them all. So i tried to play with stopPropagation(), but it caused some other issues.

What should hideEvent be set to?

@jackmcdade
Copy link
Contributor Author

Also, i'm using showEvent: 'click', so your example prevents tooltipsy from running at all.

@briancray
Copy link
Owner

something like this may work:

$(document).click(function (e) {
    if (e && e.target && $(e.target).hasClass('tooltipsy')) {
        return;
    }
    $('.tooltipsy').parent().hide();
});

@jackmcdade
Copy link
Contributor Author

Well that would remove the link that triggers the tooltipsy, not the tooltipsy itself. It works for the first instance if i target .data('tooltipsy').hide(), but not any other occurances on the page.

If i'm using a class selector, how do i make sure i kill the RIGHT instance of tooltipsy?

@jackmcdade
Copy link
Contributor Author

Here's my code. Obviously the hideEvent won't work with click events in it's current form, but i really can't get an event to trigger that will allow me to remove the correct popover and still allow me to trigger it again.

$('.pop').tooltipsy({
    showEvent: 'click',
    hideEvent: 'focusout',
    alignTo: 'element',
    offset: [-15, 0],
    content: $('#popover-content').html(),
    show: function (e, $el) {
        $el.show();
    },
    hide: function (e, $el) {
        $el.hide();
    },
    delay: 0,
    className: 'popovers',
    css: {}
});

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

No branches or pull requests

2 participants