jquery-tablesorter-rails4 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/jquery_tablesorter/jquery.metadata.js +116 -0
- data/app/assets/javascripts/jquery_tablesorter/jquery.tablesorter.js +1477 -0
- data/app/assets/javascripts/jquery_tablesorter/jquery.tablesorter.widgets-filter-formatter.js +924 -0
- data/app/assets/javascripts/jquery_tablesorter/jquery.tablesorter.widgets.js +1210 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-date-iso8601.js +34 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-date-month.js +32 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-date-two-digit-year.js +68 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-date-weekday.js +32 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-date.js +36 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-feet-inch-fraction.js +63 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-ignore-articles.js +47 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-input-select.js +78 -0
- data/app/assets/javascripts/jquery_tablesorter/parsers/parser-metric.js +77 -0
- data/app/assets/javascripts/jquery_tablesorter/widgets/widget-editable.js +68 -0
- data/app/assets/javascripts/jquery_tablesorter/widgets/widget-grouping.js +114 -0
- data/app/assets/javascripts/jquery_tablesorter/widgets/widget-repeatheaders.js +50 -0
- data/app/assets/javascripts/jquery_tablesorter/widgets/widget-scroller.js +240 -0
- data/app/assets/stylesheets/jquery_tablesorter/filter.formatter.css +183 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.black-ice.css +180 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.blue.css +215 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.bootstrap.css +139 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.dark.css +181 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.default.css +183 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.dropbox.css +201 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.green.css +198 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.grey.css +234 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.ice.css +189 -0
- data/app/assets/stylesheets/jquery_tablesorter/theme.jui.css +145 -0
- data/jquery-tablesorter-rails4.gemspec +25 -0
- data/lib/jquery-tablesorter-rails4.rb +1 -0
- data/lib/jquery/tablesorter/rails4.rb +10 -0
- data/lib/jquery/tablesorter/rails4/engine.rb +8 -0
- data/lib/jquery/tablesorter/rails4/version.rb +7 -0
- metadata +124 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
/*! ISO-8601 date parser
|
2
|
+
* This parser will work with dates in ISO8601 format
|
3
|
+
* 2013-02-18T18:18:44+00:00
|
4
|
+
* Written by Sean Ellingham :https://github.com/seanellingham
|
5
|
+
* See https://github.com/Mottie/tablesorter/issues/247
|
6
|
+
*/
|
7
|
+
/*global jQuery: false */
|
8
|
+
;(function($){
|
9
|
+
"use strict";
|
10
|
+
|
11
|
+
var iso8601date = /^([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?$/;
|
12
|
+
$.tablesorter.addParser({
|
13
|
+
id : 'iso8601date',
|
14
|
+
is : function(s) {
|
15
|
+
return s.match(iso8601date);
|
16
|
+
},
|
17
|
+
format : function(s) {
|
18
|
+
var result = s.match(iso8601date);
|
19
|
+
if (result) {
|
20
|
+
var date = new Date(result[1], 0, 1);
|
21
|
+
if (result[3]) {date.setMonth(result[3] - 1);}
|
22
|
+
if (result[5]) {date.setDate(result[5]);}
|
23
|
+
if (result[7]) {date.setHours(result[7]);}
|
24
|
+
if (result[8]) {date.setMinutes(result[8]);}
|
25
|
+
if (result[10]) {date.setSeconds(result[10]);}
|
26
|
+
if (result[12]) {date.setMilliseconds(Number('0.' + result[12]) * 1000);}
|
27
|
+
return date;
|
28
|
+
}
|
29
|
+
return 0;
|
30
|
+
},
|
31
|
+
type : 'numeric'
|
32
|
+
});
|
33
|
+
|
34
|
+
})(jQuery);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*! Month parser
|
2
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/477/
|
3
|
+
*/
|
4
|
+
/*jshint jquery:true */
|
5
|
+
;(function($){
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
$.tablesorter.dates = $.extend({}, $.tablesorter.dates, {
|
9
|
+
// *** modify this array to change match the language ***
|
10
|
+
monthCased : [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
|
11
|
+
});
|
12
|
+
$.tablesorter.dates.monthLower = $.tablesorter.dates.monthCased.join(',').toLocaleLowerCase().split(',');
|
13
|
+
|
14
|
+
$.tablesorter.addParser({
|
15
|
+
id: "month",
|
16
|
+
is: function(){
|
17
|
+
return false;
|
18
|
+
},
|
19
|
+
format: function(s, table) {
|
20
|
+
var j = -1, c = table.config;
|
21
|
+
s = c.ignoreCase ? s.toLocaleLowerCase() : s;
|
22
|
+
$.each($.tablesorter.dates[ 'month' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
23
|
+
if (j < 0 && s.match(v)) { j = i; }
|
24
|
+
});
|
25
|
+
// return s (original string) if there isn't a match
|
26
|
+
// (non-weekdays will sort separately and empty cells will sort as expected)
|
27
|
+
return j < 0 ? s : j;
|
28
|
+
},
|
29
|
+
type: "numeric"
|
30
|
+
});
|
31
|
+
|
32
|
+
})(jQuery);
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*! Two digit year parser
|
2
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/427/
|
3
|
+
*/
|
4
|
+
/*jshint jquery:true */
|
5
|
+
;(function($){
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
// Make the date be within +/- range of the 2 digit year
|
9
|
+
// so if the current year is 2020, and the 2 digit year is 80 (2080 - 2020 > 50), it becomes 1980
|
10
|
+
// if the 2 digit year is 50 (2050 - 2020 < 50), then it becomes 2050.
|
11
|
+
var range = 50,
|
12
|
+
|
13
|
+
// ************
|
14
|
+
regxxxxyy = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/,
|
15
|
+
regyyxxxx = /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/,
|
16
|
+
formatDate = function(s, regex, format){
|
17
|
+
s = s
|
18
|
+
// replace separators
|
19
|
+
.replace(/\s+/g," ").replace(/[-.,]/g, "/")
|
20
|
+
// reformat xx/xx/xx to mm/dd/19yy;
|
21
|
+
.replace(regex, format);
|
22
|
+
var d = new Date(s), y = d.getFullYear(),
|
23
|
+
now = new Date().getFullYear();
|
24
|
+
// if date > 50 years old (set range), add 100 years
|
25
|
+
// this will work when people start using "50" and mean "2050"
|
26
|
+
while (now - y > range) {
|
27
|
+
y += 100;
|
28
|
+
}
|
29
|
+
return d.setFullYear(y);
|
30
|
+
};
|
31
|
+
|
32
|
+
$.tablesorter.addParser({
|
33
|
+
id: "ddmmyy",
|
34
|
+
is: function() {
|
35
|
+
return false;
|
36
|
+
},
|
37
|
+
format: function(s) {
|
38
|
+
// reformat dd/mm/yy to mm/dd/19yy;
|
39
|
+
return formatDate(s, regxxxxyy, "$2/$1/19$3");
|
40
|
+
},
|
41
|
+
type: "numeric"
|
42
|
+
});
|
43
|
+
|
44
|
+
$.tablesorter.addParser({
|
45
|
+
id: "mmddyy",
|
46
|
+
is: function() {
|
47
|
+
return false;
|
48
|
+
},
|
49
|
+
format: function(s) {
|
50
|
+
// reformat mm/dd/yy to mm/dd/19yy
|
51
|
+
return formatDate(s, regxxxxyy, "$1/$2/19$3");
|
52
|
+
},
|
53
|
+
type: "numeric"
|
54
|
+
});
|
55
|
+
|
56
|
+
$.tablesorter.addParser({
|
57
|
+
id: "yymmdd",
|
58
|
+
is: function() {
|
59
|
+
return false;
|
60
|
+
},
|
61
|
+
format: function(s) {
|
62
|
+
// reformat yy/mm/dd to mm/dd/19yy
|
63
|
+
return formatDate(s, regyyxxxx, "$2/$3/19$1");
|
64
|
+
},
|
65
|
+
type: "numeric"
|
66
|
+
});
|
67
|
+
|
68
|
+
})(jQuery);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*! Weekday parser
|
2
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/477/
|
3
|
+
*/
|
4
|
+
/*jshint jquery:true */
|
5
|
+
;(function($){
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
$.tablesorter.dates = $.extend({}, $.tablesorter.dates, {
|
9
|
+
// *** modify this array to change match the language ***
|
10
|
+
weekdayCased : [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
|
11
|
+
});
|
12
|
+
$.tablesorter.dates.weekdayLower = $.tablesorter.dates.weekdayCased.join(',').toLocaleLowerCase().split(',');
|
13
|
+
|
14
|
+
$.tablesorter.addParser({
|
15
|
+
id: "weekday",
|
16
|
+
is: function(){
|
17
|
+
return false;
|
18
|
+
},
|
19
|
+
format: function(s, table) {
|
20
|
+
var j = -1, c = table.config;
|
21
|
+
s = c.ignoreCase ? s.toLocaleLowerCase() : s;
|
22
|
+
$.each($.tablesorter.dates[ 'weekday' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
23
|
+
if (j < 0 && s.match(v)) { j = i; }
|
24
|
+
});
|
25
|
+
// return s (original string) if there isn't a match
|
26
|
+
// (non-weekdays will sort separately and empty cells will sort as expected)
|
27
|
+
return j < 0 ? s : j;
|
28
|
+
},
|
29
|
+
type: "numeric"
|
30
|
+
});
|
31
|
+
|
32
|
+
})(jQuery);
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*!
|
2
|
+
* Extract dates using popular natural language date parsers
|
3
|
+
*/
|
4
|
+
/*jshint jquery:true */
|
5
|
+
;(function($){
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
/*! Sugar (http://sugarjs.com/dates#comparing_dates)
|
9
|
+
* demo: http://jsfiddle.net/Mottie/abkNM/551/
|
10
|
+
*/
|
11
|
+
$.tablesorter.addParser({
|
12
|
+
id: "sugar",
|
13
|
+
is: function() {
|
14
|
+
return false;
|
15
|
+
},
|
16
|
+
format: function(s) {
|
17
|
+
return Date.create ? Date.create(s).getTime() || s : s;
|
18
|
+
},
|
19
|
+
type: "numeric"
|
20
|
+
});
|
21
|
+
|
22
|
+
/*! Datejs (http://www.datejs.com/)
|
23
|
+
* demo: http://jsfiddle.net/Mottie/abkNM/550/
|
24
|
+
*/
|
25
|
+
$.tablesorter.addParser({
|
26
|
+
id: "datejs",
|
27
|
+
is: function() {
|
28
|
+
return false;
|
29
|
+
},
|
30
|
+
format: function(s) {
|
31
|
+
return Date.parse && Date.parse(s) || s;
|
32
|
+
},
|
33
|
+
type: "numeric"
|
34
|
+
});
|
35
|
+
|
36
|
+
})(jQuery);
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*! Distance parser
|
2
|
+
* This parser will parser numbers like 5'10" (5 foot 10 inches)
|
3
|
+
* and 31½ into sortable values.
|
4
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/154/
|
5
|
+
*/
|
6
|
+
/*global jQuery: false */
|
7
|
+
;(function($){
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
var symbolRegex = /[\u215b\u215c\u215d\u215e\u00bc\u00bd\u00be]/g,
|
11
|
+
processFractions = function(n, table){
|
12
|
+
if (n) {
|
13
|
+
var t, p = 0;
|
14
|
+
n = $.trim(n.replace(/\"/,''));
|
15
|
+
// look for a space in the first part of the number: "10 3/4" and save the "10"
|
16
|
+
if (/\s/.test(n)) {
|
17
|
+
p = $.tablesorter.formatFloat(n.split(' ')[0], table);
|
18
|
+
// remove stuff to the left of the space
|
19
|
+
n = $.trim(n.substring(n.indexOf(' '), n.length));
|
20
|
+
}
|
21
|
+
// look for a "/" to calculate fractions
|
22
|
+
if (/\//g.test(n)) {
|
23
|
+
t = n.split('/');
|
24
|
+
// turn 3/4 into .75; make sure we don't divide by zero
|
25
|
+
n = p + parseInt(t[0], 10) / parseInt(t[1] || 1, 10);
|
26
|
+
// look for fraction symbols
|
27
|
+
} else if (symbolRegex.test(n)) {
|
28
|
+
n = p + n.replace(symbolRegex, function(m){
|
29
|
+
return {
|
30
|
+
'\u215b' : '.125', // 1/8
|
31
|
+
'\u215c' : '.375', // 3/8
|
32
|
+
'\u215d' : '.625', // 5/8
|
33
|
+
'\u215e' : '.875', // 7/8
|
34
|
+
'\u00bc' : '.25', // 1/4
|
35
|
+
'\u00bd' : '.5', // 1/2
|
36
|
+
'\u00be' : '.75' // 3/4
|
37
|
+
}[m];
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}
|
41
|
+
return n || 0;
|
42
|
+
};
|
43
|
+
|
44
|
+
$.tablesorter.addParser({
|
45
|
+
id: 'distance',
|
46
|
+
is: function() {
|
47
|
+
// return false so this parser is not auto detected
|
48
|
+
return false;
|
49
|
+
},
|
50
|
+
format: function(s, table) {
|
51
|
+
if (s === '') { return ''; }
|
52
|
+
|
53
|
+
// look for feet symbol = '
|
54
|
+
// very generic test to catch 1.1', 1 1/2' and 1½'
|
55
|
+
var d = (/^\s*\S*(\s+\S+)?\s*\'/.test(s)) ? s.split("'") : [0,s],
|
56
|
+
f = processFractions(d[0], table), // feet
|
57
|
+
i = processFractions(d[1], table); // inches
|
58
|
+
return (/[\'\"]/).test(s) ? parseFloat(f) + (parseFloat(i)/12 || 0) : parseFloat(f) + parseFloat(i);
|
59
|
+
},
|
60
|
+
type: 'numeric'
|
61
|
+
});
|
62
|
+
|
63
|
+
})(jQuery);
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/*! Title parser
|
2
|
+
* This parser will remove "The", "A" and "An" from the beginning of a book
|
3
|
+
* or movie title, so it sorts by the second word or number
|
4
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/5/
|
5
|
+
*/
|
6
|
+
/*global jQuery: false */
|
7
|
+
;(function($){
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
// basic list from http://en.wikipedia.org/wiki/Article_%28grammar%29
|
11
|
+
$.tablesorter.ignoreArticles = {
|
12
|
+
"en" : "the, a, an",
|
13
|
+
"de" : "der, die, das, des, dem, den, ein, eine, einer, eines, einem, einen",
|
14
|
+
"nl" : "de, het, de, een",
|
15
|
+
"es" : "el, la, lo, los, las, un, una, unos, unas",
|
16
|
+
"pt" : "o, a, os, as, um, uma, uns, umas",
|
17
|
+
"fr" : "le, la, l'_, les, un, une, des",
|
18
|
+
"it" : "il, lo, la, l'_, i, gli, le, un', uno, una, un",
|
19
|
+
"hu" : "a, az, egy"
|
20
|
+
};
|
21
|
+
|
22
|
+
// To add a custom parser, define:
|
23
|
+
// $.tablesorter.ignoreArticles['xx'] = "A, B, C";
|
24
|
+
// and then set the language id 'xx' in the headers option
|
25
|
+
// ignoreArticles : 'xx'
|
26
|
+
|
27
|
+
$.tablesorter.addParser({
|
28
|
+
id: 'ignoreArticles',
|
29
|
+
is: function() {
|
30
|
+
return false;
|
31
|
+
},
|
32
|
+
format: function(s, table, cell, cellIndex) {
|
33
|
+
var c = table.config, art, lang;
|
34
|
+
if ( !(c.headers && c.headers[cellIndex] && c.headers[cellIndex].ignoreArticlesRegex) ) {
|
35
|
+
// initialize - save regex in c.headers[cellIndex].ignoreArticles
|
36
|
+
if (!c.headers) { c.headers = {}; }
|
37
|
+
if (!c.headers[cellIndex]) { c.headers[cellIndex] = {}; }
|
38
|
+
lang = $.tablesorter.getData(c.$headers.eq(cellIndex), c.headers[cellIndex], 'ignoreArticles');
|
39
|
+
art = ($.tablesorter.ignoreArticles[lang] || "the, a, an" ) + "";
|
40
|
+
c.headers[cellIndex].ignoreArticlesRegex = new RegExp('^(' + $.trim( art.split(/\s*\,\s*/).join('\\s|') + "\\s" ).replace("_\\s","") + ')', 'i');
|
41
|
+
}
|
42
|
+
return (s || '').replace(c.headers[cellIndex].ignoreArticlesRegex, '');
|
43
|
+
},
|
44
|
+
type: 'text'
|
45
|
+
});
|
46
|
+
|
47
|
+
})(jQuery);
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/*! input & select parsers for jQuery 1.7+ & tablesorter 2.7.11+
|
2
|
+
* Demo: http://mottie.github.com/tablesorter/docs/example-widget-grouping.html
|
3
|
+
*/
|
4
|
+
/*jshint browser: true, jquery:true, unused:false */
|
5
|
+
;(function($){
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
var resort = true, // resort table after update
|
9
|
+
updateServer = function(event, $table, $input){
|
10
|
+
// do something here to update your server, if needed
|
11
|
+
// event = change event object
|
12
|
+
// $table = jQuery object of the table that was just updated
|
13
|
+
// $input = jQuery object of the input or select that was modified
|
14
|
+
};
|
15
|
+
|
16
|
+
// Custom parser for parsing input values
|
17
|
+
// updated dynamically using the "change" function below
|
18
|
+
$.tablesorter.addParser({
|
19
|
+
id: "inputs",
|
20
|
+
is: function(){
|
21
|
+
return false;
|
22
|
+
},
|
23
|
+
format: function(s, table, cell) {
|
24
|
+
return $(cell).find('input').val() || s;
|
25
|
+
},
|
26
|
+
type: "text"
|
27
|
+
});
|
28
|
+
|
29
|
+
// Custom parser for including checkbox status if using the grouping widget
|
30
|
+
// updated dynamically using the "change" function below
|
31
|
+
$.tablesorter.addParser({
|
32
|
+
id: "checkbox",
|
33
|
+
is: function(){
|
34
|
+
return false;
|
35
|
+
},
|
36
|
+
format: function(s, table, cell) {
|
37
|
+
// using plain language here because this is what is shown in the group headers
|
38
|
+
// change it as desired
|
39
|
+
var $c = $(cell).find('input');
|
40
|
+
return $c.length ? $c.is(':checked') ? 'checked' : 'unchecked' : s;
|
41
|
+
},
|
42
|
+
type: "text"
|
43
|
+
});
|
44
|
+
|
45
|
+
// Custom parser which returns the currently selected options
|
46
|
+
// updated dynamically using the "change" function below
|
47
|
+
$.tablesorter.addParser({
|
48
|
+
id: "select",
|
49
|
+
is: function(){
|
50
|
+
return false;
|
51
|
+
},
|
52
|
+
format: function(s, table, cell) {
|
53
|
+
return $(cell).find('select').val() || s;
|
54
|
+
},
|
55
|
+
type: "text"
|
56
|
+
});
|
57
|
+
|
58
|
+
// update select and all input types in the tablesorter cache when the change event fires.
|
59
|
+
// This method only works with jQuery 1.7+
|
60
|
+
// you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired
|
61
|
+
// if this code interferes somehow, target the specific table $('#mytable'), instead of $('table')
|
62
|
+
$(window).load(function(){
|
63
|
+
// this flag prevents the updateCell event from being spammed
|
64
|
+
// it happens when you modify input text and hit enter
|
65
|
+
var alreadyUpdating = false;
|
66
|
+
$('table').find('tbody').on('change', 'select, input', function(e){
|
67
|
+
if (!alreadyUpdating) {
|
68
|
+
var $tar = $(e.target),
|
69
|
+
$table = $tar.closest('table');
|
70
|
+
alreadyUpdating = true;
|
71
|
+
$table.trigger('updateCell', [ $tar.closest('td'), resort ]);
|
72
|
+
updateServer(e, $table, $tar);
|
73
|
+
setTimeout(function(){ alreadyUpdating = false; }, 10);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
});
|
77
|
+
|
78
|
+
})(jQuery);
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/*! Metric parser
|
2
|
+
* Demo: http://jsfiddle.net/Mottie/abkNM/382/
|
3
|
+
* Set the metric name in the header (defaults to "m|meter"), e.g.
|
4
|
+
* <th data-metric-name="b|byte">HDD Size</th>
|
5
|
+
* <th data-metric-name="m|meter">Distance</th>
|
6
|
+
*/
|
7
|
+
/*jshint jquery:true */
|
8
|
+
;(function($){
|
9
|
+
"use strict";
|
10
|
+
|
11
|
+
var prefixes = {
|
12
|
+
// "prefix" : [ base 10, base 2 ]
|
13
|
+
// skipping IEEE 1541 defined prefixes: kibibyte, mebibyte, etc, for now.
|
14
|
+
"Y|Yotta|yotta" : [ 1e24, Math.pow(1024, 8) ], // 1024^8
|
15
|
+
"Z|Zetta|zetta" : [ 1e21, Math.pow(1024, 7) ], // 1024^7
|
16
|
+
"E|Exa|exa" : [ 1e18, Math.pow(1024, 6) ], // 1024^6
|
17
|
+
"P|Peta|peta" : [ 1e15, Math.pow(1024, 5) ], // 1024^5
|
18
|
+
"T|Tera|tera" : [ 1e12, Math.pow(1024, 4) ], // 1024^4
|
19
|
+
"G|Giga|giga" : [ 1e9, Math.pow(1024, 3) ], // 1024^3
|
20
|
+
"M|Mega|mega" : [ 1e6, Math.pow(1024, 2) ], // 1024^2
|
21
|
+
"k|Kilo|kilo" : [ 1e3, 1024 ], // 1024
|
22
|
+
// prefixes below here are rarely, if ever, used in binary
|
23
|
+
"h|hecto" : [ 1e2, 1e2 ],
|
24
|
+
"da|deka" : [ 1e1, 1e1 ],
|
25
|
+
"d|deci" : [ 1e-1, 1e-1 ],
|
26
|
+
"c|centi" : [ 1e-2, 1e-2],
|
27
|
+
"m|milli" : [ 1e-3, 1e-3 ],
|
28
|
+
"µ|micro" : [ 1e-6, 1e-6 ],
|
29
|
+
"n|nano" : [ 1e-9, 1e-9 ],
|
30
|
+
"p|pico" : [ 1e-12, 1e-12 ],
|
31
|
+
"f|femto" : [ 1e-15, 1e-15 ],
|
32
|
+
"a|atto" : [ 1e-18, 1e-18 ],
|
33
|
+
"z|zepto" : [ 1e-21, 1e-21 ],
|
34
|
+
"y|yocto" : [ 1e-24, 1e-24 ]
|
35
|
+
},
|
36
|
+
// the \\d+ will not catch digits with spaces, commas or decimals; so use the value from n instead
|
37
|
+
RegLong = "(\\d+)(\\s+)?([Zz]etta|[Ee]xa|[Pp]eta|[Tt]era|[Gg]iga|[Mm]ega|kilo|hecto|deka|deci|centi|milli|micro|nano|pico|femto|atto|zepto|yocto)(",
|
38
|
+
RegAbbr = "(\\d+)(\\s+)?(Z|E|P|T|G|M|k|h|da|d|c|m|µ|n|p|f|a|z|y)(";
|
39
|
+
|
40
|
+
$.tablesorter.addParser({
|
41
|
+
id: 'metric',
|
42
|
+
is: function() {
|
43
|
+
return false;
|
44
|
+
},
|
45
|
+
format: function(s, table, cell, cellIndex) {
|
46
|
+
var v = 'm|meter',
|
47
|
+
b, t,
|
48
|
+
// process number here to get a numerical format (us or eu)
|
49
|
+
n = $.tablesorter.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table),
|
50
|
+
$t = $(table).find('thead').children().children('[data-column="' + cellIndex + '"]'),
|
51
|
+
m = $t.data('metric');
|
52
|
+
if (!m) {
|
53
|
+
// stored values
|
54
|
+
t = ($t.attr('data-metric-name') || v).split('|');
|
55
|
+
m = [ t[1] || t[0].substring(1), t[0] ];
|
56
|
+
m[2] = new RegExp(RegLong + m[0] + "|" + m[1] + ")");
|
57
|
+
m[3] = new RegExp(RegAbbr + m[1] + ")");
|
58
|
+
$t.data('metric', m);
|
59
|
+
}
|
60
|
+
// find match to full name or abbreviation
|
61
|
+
t = s.match(m[2]) || s.match(m[3]);
|
62
|
+
if (t) {
|
63
|
+
for (v in prefixes) {
|
64
|
+
if (t[3].match(v)) {
|
65
|
+
// exception when using binary prefix
|
66
|
+
// change base for binary use
|
67
|
+
b = /^[b|bit|byte|o|octet]/.test(t[4]) ? 1 : 0;
|
68
|
+
return n * prefixes[v][b];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return n;
|
73
|
+
},
|
74
|
+
type: 'numeric'
|
75
|
+
});
|
76
|
+
|
77
|
+
})(jQuery);
|