0

How do you keep your tooltip stay forever, like a sticky, when you have clicked its hot* element, and return normal behavior when you click it again ?
* = the element that triggered the tooltip

e-motiv
  • 5,795
  • 5
  • 27
  • 28
  • -1. When self-answering, you should explain everything including pre-answer code. As for the answer, a code dump is never a good answer. Ask and answer this like it's not for you. – Sterling Archer Jul 30 '14 at 19:20
  • Jee, you are really harboiled, including already downvoting it because of that. It's in the question. But I'll change it. – e-motiv Jul 31 '14 at 11:21
  • By the way the explanation was in the comments of the code. I have seen popular answers like that. But well, it is a bit better now. – e-motiv Jul 31 '14 at 11:26

1 Answers1

0

This means you have to unbind the mouseleave event and rebind it on alternate click. Alternate click via variable, e.g. tipsyStick. The problem with mouseleave is that we don't know the original event. After a bit of searching in the main tipsy code, this the way to call the tipsy leave function: $(this).tipsy().leave if $(this) is the hot area.

Working code:

    $('.tooltip')
        .click(function() {
            /*Sticky and back on click*/
            //Remember status (and already reverse here, so also defined)
            this.tipsyStick=!this.tipsyStick;
            //Bind or rebind depending on status
            if (this.tipsyStick) 
                $(this).unbind('mouseleave'); 
            else
                $(this).bind('mouseleave', $(this).tipsy().leave);
        })
        //General tipsy triggering
        .tipsy();

Beware though that tipsy might have bind it via live() in stead of bind(), depending on your initial options. In that case, change the mouseleave methods accordingly with die and liverespectively.

e-motiv
  • 5,795
  • 5
  • 27
  • 28