UI, utils: modularize (AMD) naturalSort and move to utils

This commit is contained in:
Carl Eberhard
2015-02-10 13:42:59 -05:00
parent b3f39b8d5a
commit 3ec57d0833
10 changed files with 68 additions and 60 deletions
-27
View File
@@ -207,33 +207,6 @@ function make_popup_menus( parent ) {
});
}
// Alphanumeric/natural sort fn
function naturalSort(a, b) {
// setup temp-scope variables for comparison evauluation
var re = /(-?[0-9\.]+)/g,
x = a.toString().toLowerCase() || '',
y = b.toString().toLowerCase() || '',
nC = String.fromCharCode(0),
xN = x.replace( re, nC + '$1' + nC ).split(nC),
yN = y.replace( re, nC + '$1' + nC ).split(nC),
xD = (new Date(x)).getTime(),
yD = xD ? (new Date(y)).getTime() : null;
// natural sorting of dates
if ( yD ) {
if ( xD < yD ) { return -1; }
else if ( xD > yD ) { return 1; }
}
// natural sorting through split numeric strings and default strings
var oFxNcL, oFyNcL;
for ( var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++ ) {
oFxNcL = parseFloat(xN[cLoc]) || xN[cLoc];
oFyNcL = parseFloat(yN[cLoc]) || yN[cLoc];
if (oFxNcL < oFyNcL) { return -1; }
else if (oFxNcL > oFyNcL) { return 1; }
}
return 0;
}
$.fn.refresh_select2 = function() {
var select_elt = $(this);
var options = { placeholder:'Click to select',