-
-
Save dshaw/652870 to your computer and use it in GitHub Desktop.
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; | |
} |
when jQuery is version 1.10.0, and tests against 1.9.0 it returns false. To fix change 6th line to:
if (min[i] && (+$vrs[i]) < (+min[i])) {
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.
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;
}
usage:
minVersion('1.4.2')
minVersion('1.4')
minVersion('2')