iamceege/tooltipster — pull request #67 by evangun (2013-10-27 09:55:34+00:00)
Title: changed functionInit behavior

Hey, I changed the functionInit behavior back to what it was, as in my mind it does not make much sense with the continueInit parameter you gave it. Let me explain more and tell me what you think.

Firstly, I do not think there is a point in allowing to stop the tooltip initialization. If you do not want the tooltip to appear at some point, it is functionBefore's job to achieve that. But if you do not want the tooltip to be initialized, then why would you have tried to initialize it in the first place ?

Secondly, the main purpose of this function is to allow a change on-the-fly from the initial title attribute to the final content you will put in the tooltip. Some people may be happy to have an init callback to do something else, but that is probably not a very common need (still good to have it though).

For example, I never put raw HTML in a title attribute as it is not W3C compliant and presents XSS risks when you do not control the tooltip content. That alone demands that you have an initFunction, to handle things. Anyway in my use case, I more or less change a "Some--stuff" title to a "Some
stuff" tooltip.

If you wanted to do this with the functionInit you propose, you would probably go for :

functionInit(origin, initContinue){
var c = origin.tooltipster('val');
c = sometransformation(c);
origin.tooltipster('update', c);
initContinue();
}

But that currently does not work. As the widget is not fully initialized (not saved in .data, line 878) when functionInit is executed, you cannot use $(sel).tooltipster('val') on it. You would have to edit the .tooltipster() function for this to work, but I find this overkill, for a not-so-great behavior anyway.

So in the end, I cannot see the point for an initContinue parameter, but I do see the point in being able to change the tooltip content in a very easy way, just by returning something at the end of the function. It's simpler than playing with the val and update methods :

functionInit(origin, content){
return sometransformation(content);
}

Thank you !