tags:

views:

61

answers:

6

so I'm using qtip for a super simple tool tip implementation.

I'm not including qtip on every page, only the pages that needed, so I'm trying to check for qtip's existence before calling it.

 /*
  * Tool Tip
  * inits qtip on any link with class="tt"
  */
  if( $.isFunction( $.qtip ) ){
  $(".tt").qtip();
  }

I've no idea what this isn't working. it's always returning false. Any ideas? Thx.

+4  A: 

IMO, you should check

if($.isFunction($.fn.qtip))
Rafael
Do'h! Thanks man!
CreativeNotice
you're welcome :)
Rafael
A: 

If the implementation is consistent accross all you your pages, then just put

$(function(){
    $(".tt").qtip();
}

at the bottom of the qtip.js file, that way, it is executed whenever qtip is included.

Paul Creasey
on second thoughts this is probably a bad plan, could be very confusing 6 months down the line!
Paul Creasey
+1  A: 

try this:

if( $.isFunction( $.fn.qtip ) ){
    $(".tt").qtip();
}

as plugins reside in the $.fn object

Juraj Blahunka
A: 

I prefer using the typof operator since it's not jQuery dependent.

if(typeof window.myFunction == 'function') {
    // function exists, so we can now call it
    myFunction();
}

On a side note it's a great way to "extend" javascript on "If" something exists (like form validation)

Mech Software
Since the qtip function is itself dependent on jQuery, I've no issues using isFunction.
CreativeNotice
A: 
if( $.isFunction(qtip) ){
 //bla bla
}

try this or with commas

if( $.isFunction("qtip") ){
     //bla bla
    }
Amad
won't work, because the `qtip` resides in jQuery fn object -> `jQuery.fn`
Juraj Blahunka
A: 

Try removing the "$." before the qtip in the isFunction check.

Fire G
`qtip` is a jquery plugin, so he cannot remove jquery dollar sign `$`
Juraj Blahunka