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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);