Skip to content

Instantly share code, notes, and snippets.

@javamad
Created June 28, 2015 16:19
Show Gist options
  • Save javamad/2001e2e3725ec4b07282 to your computer and use it in GitHub Desktop.
Save javamad/2001e2e3725ec4b07282 to your computer and use it in GitHub Desktop.
Hi, I was trying this but it doesn't work with some combinations ... so I came up with this variation: (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]);
return ins >= req;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment