fix tabs
This commit is contained in:
@@ -24,45 +24,53 @@
|
|||||||
* See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
|
* See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
|
||||||
*/
|
*/
|
||||||
function portSort (a, b) {
|
function portSort (a, b) {
|
||||||
var re = /(^(-?\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
|
var re = /(^(-?\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
|
||||||
// string regex
|
// string regex
|
||||||
sre = /(^[ ]*|[ ]*$)/g,
|
sre = /(^[ ]*|[ ]*$)/g,
|
||||||
// octal regex
|
// octal regex
|
||||||
ore = /^0/,
|
ore = /^0/,
|
||||||
// convert all to strings and trim()
|
// convert all to strings and trim()
|
||||||
x = a.toString().replace(sre, '') || '',
|
x = a.toString().replace(sre, '') || '',
|
||||||
y = b.toString().replace(sre, '') || '';
|
y = b.toString().replace(sre, '') || '';
|
||||||
// hack for foundry "10GigabitEthernet" -> cisco-like "TenGigabitEthernet"
|
|
||||||
x = x.replace(/^10GigabitEthernet/, 'GigabitEthernet');
|
// hack for foundry "10GigabitEthernet" -> cisco-like "TenGigabitEthernet"
|
||||||
y = y.replace(/^10GigabitEthernet/, 'GigabitEthernet');
|
x = x.replace(/^10GigabitEthernet/, 'GigabitEthernet');
|
||||||
// chunk/tokenize
|
y = y.replace(/^10GigabitEthernet/, 'GigabitEthernet');
|
||||||
var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
|
|
||||||
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
// chunk/tokenize
|
||||||
for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
|
var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
|
||||||
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
|
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0');
|
||||||
var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
|
|
||||||
var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
|
for (var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
|
||||||
// handle numeric vs string comparison - number < string - (Kyle Adams)
|
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
|
||||||
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
|
var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
|
||||||
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
|
||||||
else if (typeof oFxNcL !== typeof oFyNcL) {
|
|
||||||
oFxNcL += '';
|
// handle numeric vs string comparison - number < string - (Kyle Adams)
|
||||||
oFyNcL += '';
|
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) {
|
||||||
}
|
return (isNaN(oFxNcL)) ? 1 : -1;
|
||||||
if (oFxNcL < oFyNcL) return -1;
|
}
|
||||||
if (oFxNcL > oFyNcL) return 1;
|
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
||||||
}
|
else if (typeof oFxNcL !== typeof oFyNcL) {
|
||||||
return 0;
|
oFxNcL += '';
|
||||||
|
oFyNcL += '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oFxNcL < oFyNcL) return -1;
|
||||||
|
if (oFxNcL > oFyNcL) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
||||||
"portsort-asc": function ( a, b ) {
|
"portsort-asc": function ( a, b ) {
|
||||||
return portSort(a,b);
|
return portSort(a,b);
|
||||||
},
|
},
|
||||||
|
|
||||||
"portsort-desc": function ( a, b ) {
|
"portsort-desc": function ( a, b ) {
|
||||||
return portSort(a,b) * -1;
|
return portSort(a,b) * -1;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user