Peter
Peter

Reputation: 11835

jQuery qTip - Trigger before create

i try to trigger someFunction() before the qtip is created

$('.selector').qtip({
   content: {
      text: someFunction(this.id) }
});

This code works but i think this is a dirty solution. Is there maybe a start: event like in the most jquery plugins (for example draggable)? I found nothing about this it in the documentation.

EDIT: Ok, this code wont work. He trigger the function on pageload and not onhover.

UPDATE:

function someFunction(someId)
{
    // some code ...
    var searchResult = ' ... some results from the search -> from '+someId+' ... ';
    return searchResult;

}

Upvotes: 6

Views: 1701

Answers (3)

amdstorm
amdstorm

Reputation: 66

In Qtip2, it has changed to jquery style ui events

$('.selector').qtip({
   events: {
      render: function(event, api) { }, // old onRender
      show: function(event, api) {}, // old beforeHide (return false or call event.preventDefault() to stop the show)
      hide: function(event, api) {} // old beforeHide (same as above)
   }
})

Upvotes: 0

AlexBay
AlexBay

Reputation: 1313

Use the Callback option beforeShow : , it's a better way to do this.

Reference here.

Remove brackets from someFunction as well.

$('.selector').qtip({
    api : {
        beforeShow : function (someId)
        {
            // some code ...
            var searchResult = ' ... some results from the search -> from '+someId+' ... ';
            // place text in tooltip
        }
    }
});

Working Sample.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318778

You need to pass someFunction, not someFunction(). The latter calls the function and assigns the return value to text and then never calls the function again. By passing the function itself qTip will see the function and call it when necessary.

Upvotes: 3

Related Questions