views:

53

answers:

1

This should be an easy question, but how do I detect the jQuery-UI version?

This is for a Greasemonkey script and the (current) target page appears to be running jQuery-UI, 1.5.2. But, different target pages may run different versions.

console.log ($.ui); did not show anything useful/obvious for version detection.

+4  A: 

You can use $.ui.version, it's actually the property jQuery UI looks for when determining if it should load itself (if it's already there, abort).

For example here's a fiddle including version 1.8.4.

Unfortunately, $.ui.version was added in jQuery-UI version 1.6.

For earlier versions, you can check for $.ui though.

So, in this case, the following might be good enough:

var version = $.ui ? $.ui.version || "pre 1.6" : 'jQuery-UI not detected';
Nick Craver
No, this does not work. Here's a fiddle refusing to show 1.5.2       http://jsfiddle.net/cCMQJ/
Brock Adams
@Brock - `$.ui.version` was added in 1.6, nothing you can really do about that, you can however check for `$.ui` and *not* `$.ui.version`, in your case that'd be 1.5.2, like this `var version = $.ui ? $.ui.version || "1.5.2" : null;`, check out a demo here: http://jsfiddle.net/nick_craver/cCMQJ/1/
Nick Craver
@Nick: I was starting to suspect as much since the 1.5.2, minified-JS file doesn't seem to have the string "1.5.2" in it.
Brock Adams
@Brock - Yup, sorry that's the situation...guess it never occurred to anyone they might need the version back then...since it was *very* trivial to add :-/
Nick Craver