Created
October 29, 2010 03:42
-
-
Save dshaw/652870 to your computer and use it in GitHub Desktop.
Determine if a page has the minimum jQuery version you need to do what you're doing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minVersion(version) { | |
var $vrs = window.jQuery.fn.jquery.split('.'), | |
min = version.split('.'); | |
for (var i=0, len=$vrs.length; i<len; i++) { | |
console.log($vrs[i], min[i]); | |
if (min[i] && $vrs[i] < min[i]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Hi,
I was trying this but it doesn't work with some combinations ... so I came up with this variation which builds a single number from the major.minor.patch versions and compares that.
(I multiply the major version by 1000 to cater for having minor versions that go beyond 9 )
function minVersion(version) {
//console.log('minVersion:: testing for jquery minimum of ' + version );
if(typeof window.jQuery == 'undefined'){
console.log('minVersion:: no jquery found ...');
return false;
}
var vrs = window.jQuery.fn.jquery.split('.'),
min = version.split('.');
//pad the arrays to 3 digits
while(vrs.length < 3)
vrs.push(0);
while(min.length < 3)
min.push(0);
//build a number
var req = parseInt(min[0])*1000 + parseInt(min[1])*10 + parseInt(min[2]);
var ins = parseInt(vrs[0])*1000 + parseInt(vrs[1])*10 + parseInt(vrs[2]);
//DEBUG:
console.log('req = ' + req + ' and ins = ' + ins );
return ins >= req;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Dshaw, I tried it wasn't working to tests jQuery version 2.0.3 against 1.9.1 -- I made a fix in my fork: https://gist.github.com/budiadiono/7954617, please have a take a look.