1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-30 23:52:11 +01:00

Merge pull request #107 from timtucker/patch-20

Dev: Different algorithm for fnVersionCheck
This commit is contained in:
Allan Jardine 2012-10-07 04:10:43 -07:00
commit 8cabf6f830

View File

@ -1,5 +1,4 @@
/** /**
* Provide a common method for plug-ins to check the version of DataTables being used, in order * Provide a common method for plug-ins to check the version of DataTables being used, in order
* to ensure compatibility. * to ensure compatibility.
@ -15,25 +14,24 @@
*/ */
DataTable.fnVersionCheck = function( sVersion ) DataTable.fnVersionCheck = function( sVersion )
{ {
/* This is cheap, but effective */
var fnZPad = function (Zpad, count)
{
while(Zpad.length < count) {
Zpad += '0';
}
return Zpad;
};
var aThis = DataTable.ext.sVersion.split('.'); var aThis = DataTable.ext.sVersion.split('.');
var aThat = sVersion.split('.'); var aThat = sVersion.split('.');
var sThis = '', sThat = ''; var iThis, sThat;
for ( var i=0, iLen=aThat.length ; i<iLen ; i++ ) for ( var i=0, iLen=aThat.length ; i<iLen ; i++ ){
{ iThis = parseInt( aThis[i], 10 ) || 0;
sThis += fnZPad( aThis[i], 3 ); iThat = parseInt( aThat[i], 10 ) || 0;
sThat += fnZPad( aThat[i], 3 );
// Parts are the same, keep comparing
if (iThis === iThat)
{
continue;
}
// Parts are different, return immediately
return iThis > iThat;
} }
return true;
return parseInt(sThis, 10) >= parseInt(sThat, 10);
}; };