views:

100

answers:

3

I have a tooltip that I want to disable. It is from this site and is basically set and called as follows:

this.tooltip = function(){....}
$(document).ready(function(){
 tooltip();
});

I don't want to unbind the hover or mouseover events since they are also tied to other effects. I have tried to disable without success as follows (at the bottom of the page):

 $(document).ready(function(){
  this.tooltip = function() {}
 })

and

 $(document).ready(function(){
  function tooltip() {}
 })

Am I missing something?

A: 

EDIT: Heres a thought... try taking your override out of the ready statement. That way it should override the function definition before onReady is ever fired.

this.tooltip = function(){return false;};

That wont work because the script calls itself in an external file, thus if you try to make it a blank function before hand then it overrides it, and if you do it afterwards it has already run, so while you override it it has already added its event handlers to the stack. You could jsut not include the file on the pages where you dont want the tooltips.

An easy way to handle this is to make the event handlers named functions instead of anonymous, then you can easily unbine only those functions from the event stacks with $('a.tooltip').unbind('click', tooltipClick); Ofcourse the more thorough way is to refactor it in to your own plugin with remove option or something of that nature. Also there are several tooltip plugins for jQ out there and im sure at least one, if not all will allow for disabling.

prodigitalson
Hmmm that makes sense, but the problem is I don't control the scripts being loaded (it's a guild hosting site that allows me to add scripting but I can't disable what's already there).
fudgey
Adding the `return false` inside the function didn't work either =(
fudgey
ITs not abotu the return false.. its about placing this snippet outside `$(document).ready()` so that it overrides the tooltip function before before the ready state is reached.
prodigitalson
wow... I forgot about this question. Looking at it again, I see what you are saying to do. I eventually added a new tooltip using the same mehtod - defining the `this.tooltip = function(){..}` outside of the document ready, but I never overrode the original function. I still get two #tooltip divs, but it works either way. Still no solution, but I'll change it to accept your answer anyway.
fudgey
A: 

You do not need to unbind the tooltip function (since its purpose is only to run once) but the anonymous functions that it adds to the events of some elements..

There is a way to do it, only if you can alter the original tooltip code to include a namespace when binding the anonymous functions..

some examples..

in the tooltip source code there is

$("a.tooltip").hover(function(e){...})

this should be

$("a.tooltip").bind('hover.tooltip',(function(e){...});

the .tooltip next to hover means that we have defined a namespace for this function and we can now unbind it with

$("a.tooltip").unbind('hover.tooltip');
Gaby
That would probably work, but sadly I don't have control over the tooltip script. It's provided from a guild hosting site and loaded as part of the base functionality.
fudgey
A: 

Ok, I was able to do it with this function. But it seems kind of hackish and may not be the most elegant solution.

$(document).ready(function() {
 $(".tooltip").mouseover(function(){ $('#tooltip').remove() });
});

I'll keep this question open in case any better ideas show up.

fudgey