views:

49

answers:

2

good day everyone, hope yer all doin awesome

am very new to javascript and jquery, and i (think) i have come up with a simple fade-in/out implementation on a site am workin on (check out http://www.s5ent.com/expandjs.html - if you have the time to check it for inefficiency or what that'd be real sweet). i use the following functions/methods/collections and i would like to do a feature test before using them. uhm.. how? or is there a better way to go about this?

jQuery

$
.fadeIn([duration])
.fadeOut([duration])
.attr(attributeName,value)
.append(content)
.each(function(index,Element))
.css(propertyName,value)
.hover(handlerIn(eventObject),handlerOut(eventObject))
.stop([clearQueue],[jumpToEnd])
.parent()
.eq(index)

JavaScript

setInterval(expression,timeout)
clearInterval(timeoutId)
setTimeout(expression,timeout)
clearTimeout(timeoutId)

i tried looking into jquery.support for the jquery ones, but i find myself running into conceptual problems with it, i.e. for fadein/fadeout, i (think i) should test for $.support.opacity, but that would be false in ie whereas ie6+ could still fairly render the fades.

also am using jquery 1.2.6 coz that's enough for what i need. the support object is in 1.3. so i'm hoping to avoid dragging-in more unnecessary code if i can.

i also worked with browser sniffing, no matter how frowned-upon. but that's also a bigger problem for me because of non-standard ua strings and spoofing and everything else am not aware of.

so how do you guys think i should go about this? or should i even? is there a better way to go about making sure that i don't run code that'll eventually break the page? i've set it up to degrade into a css hover when javascript ain't there..

expertise needed. much appreciated, thanks guyz!

A: 

Use the following to check whether a jquery function is available, eg for append:

if ($.fn.append) $('div').append('Hello world');

This is useful checking to see if plugins have been installed that your code depends on.

James Westgate
sweet! i'll keep that in mind.these functions are built-in to jquery 1.2.6, though. so i'll do the if-then check for presence, but i'll need something to check too if the functions will actually work as intended.i became sensitive to this behavior when i was testing with opera 7.54. the if-then presence checks work, but it doesn't render the fadein/out properly. and sum'n funny happens when you click on the link.is there any way to check more than just presence, like if the fxn will work as expected?tnx for bein patient with a noob. :]
Zildjoms
Basically no. I would just use 1.4.2. The performance is improved and the Google Closure compiler minifies the code really well. Theres a big change going from version 1.2.6 to later versions but after that functionality settles down. Seriously, dont shoot yourself in the foot by sticking with an old version unless you have to.
James Westgate
awesome!! is this the right link - http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js ? so for the jquery functions that i'm using (a very limited list, btw), it's still totally worth it for me to move to the higher version, right? interestingly, i used that and found out my page works as expected in ff/ie/opera/safari/seamonkey (hopefully in other browsers that it should), but it perfectly degrades to my css hover in opera 7.54 (and hopefully in other browsers that it shouldn't work). thats just sweet! is that a capability-checking feature built-into 1.4.2? you're a genius, man!
Zildjoms
also, since these functions are not from a plug-in, would you still recommend me to do the if-then presence check or should i just leave my code as is?
Zildjoms
The functions are all part of jQuery, they wont be going anywhere so to be honest just skip the check. If they get removed, everyone site using jQuery will break. The url is a from Google CDN (content delivery network). Its nice becuase it means your user can download from Google whilst getting other data from your server. It also means it may be cached in the browser from a visit to another site.
James Westgate
A: 

beautiful. thanks, bud! have an awesome one.

Zildjoms