diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/js/dataTables.dateEuro.js | 28 | ||||
-rw-r--r-- | static/js/dataTables.fileSize.js | 51 | ||||
-rw-r--r-- | static/js/dataTables.percent.js | 20 |
3 files changed, 99 insertions, 0 deletions
diff --git a/static/js/dataTables.dateEuro.js b/static/js/dataTables.dateEuro.js new file mode 100644 index 0000000..5cdf4ef --- /dev/null +++ b/static/js/dataTables.dateEuro.js @@ -0,0 +1,28 @@ +/** + * Created by lundberg on 4/2/14. + */ + +// http://datatables.net/plug-ins/sorting + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "date-euro-pre": function ( a ) { + if ($.trim(a) != '') { + var frDatea = $.trim(a).split(' '); + var frTimea = frDatea[1].split(':'); + var frDatea2 = frDatea[0].split('/'); + var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1; + } else { + var x = 10000000000000; // = l'an 1000 ... + } + + return x; + }, + + "date-euro-asc": function ( a, b ) { + return a - b; + }, + + "date-euro-desc": function ( a, b ) { + return b - a; + } +} );
\ No newline at end of file diff --git a/static/js/dataTables.fileSize.js b/static/js/dataTables.fileSize.js new file mode 100644 index 0000000..86f7812 --- /dev/null +++ b/static/js/dataTables.fileSize.js @@ -0,0 +1,51 @@ +/** + * Created by lundberg on 4/2/14. + */ + +// http://datatables.net/plug-ins/type-detection +// http://datatables.net/plug-ins/sorting + +jQuery.fn.dataTableExt.aTypes.unshift( + function ( sData ) { + var sValidChars = "0123456789"; + var Char; + + /* Check the numeric part */ + for ( i=0 ; i<(sData.length - 3) ; i++ ) + { + Char = sData.charAt(i); + if (sValidChars.indexOf(Char) == -1) + { + return null; + } + } + + /* Check for size unit B, KB, MB or GB */ + if (sData.substring(sData.length - 2, sData.length) == "B" + || sData.substring(sData.length - 2, sData.length) == "KB" + || sData.substring(sData.length - 2, sData.length) == "MB" + || sData.substring(sData.length - 2, sData.length) == "GB" ) + { + return 'file-size'; + } + return null; + } +); +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "file-size-pre": function ( a ) { + var x = a.substring(0,a.length - 2); + + var x_unit = (a.substring(a.length - 2, a.length) == "MB" ? + 1000 : (a.substring(a.length - 2, a.length) == "GB" ? 1000000 : 1)); + + return parseInt( x * x_unit, 10 ); + }, + + "file-size-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "file-size-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); diff --git a/static/js/dataTables.percent.js b/static/js/dataTables.percent.js new file mode 100644 index 0000000..c0b4db4 --- /dev/null +++ b/static/js/dataTables.percent.js @@ -0,0 +1,20 @@ +/** + * Created by lundberg on 4/2/14. + */ + +// http://datatables.net/plug-ins/sorting + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "percent-pre": function ( a ) { + var x = (a == "-") ? 0 : a.replace( /%/, "" ); + return parseFloat( x ); + }, + + "percent-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "percent-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); |