jquery-tablesorter 1.0.4 → 1.0.5

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.
@@ -3,7 +3,7 @@ jQuery Table Sorter plugin for Rails
3
3
 
4
4
  Simple integration of jquery-tablesorter into the asset pipeline.
5
5
 
6
- Current version: 2.3.10(6/21/2012), [documentation]
6
+ Current version: 2.3.11(7/12/2012), [documentation]
7
7
 
8
8
  Any issue associate with the js/css files, please report to [Mottie's fork].
9
9
 
@@ -1,3 +1,3 @@
1
1
  module JqueryTablesorter
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * TableSorter 2.3.10 - Client-side table sorting with ease!
2
+ * TableSorter 2.3.11 - Client-side table sorting with ease!
3
3
  * @requires jQuery v1.2.6+
4
4
  *
5
5
  * Copyright (c) 2007 Christian Bach
@@ -18,7 +18,7 @@
18
18
  $.extend({
19
19
  tablesorter: new function() {
20
20
 
21
- this.version = "2.3.10";
21
+ this.version = "2.3.11";
22
22
 
23
23
  var parsers = [], widgets = [];
24
24
  this.defaults = {
@@ -111,11 +111,7 @@
111
111
  if (c.supportsTextContent) {
112
112
  text = node.textContent; // newer browsers support this
113
113
  } else {
114
- if (node.childNodes[0] && node.childNodes[0].hasChildNodes()) {
115
- text = node.childNodes[0].innerHTML;
116
- } else {
117
- text = node.innerHTML;
118
- }
114
+ text = $(node).text();
119
115
  }
120
116
  } else {
121
117
  if (typeof(t) === "function") {
@@ -177,7 +173,7 @@
177
173
  l = rows[0].cells.length;
178
174
  for (i = 0; i < l; i++) {
179
175
  // tons of thanks to AnthonyM1229 for working out the following selector (issue #74) to make this work in IE8!
180
- h = $headers.filter(':not([colspan])[data-column="'+i+'"]:last,[colspan="1"][data-column="'+i+'"]:last');
176
+ h = $headers.filter(':not([colspan])[data-column="' + i + '"]:last,[colspan="1"][data-column="' + i + '"]:last');
181
177
  ch = c.headers[i];
182
178
  // get column parser
183
179
  p = getParserById( ts.getData(h, ch, 'sorter') );
@@ -476,12 +472,12 @@
476
472
 
477
473
  /* sorting methods - reverted sorting method back to version 2.0.3 */
478
474
  function multisort(table, sortList) {
479
- var dynamicExp, col, mx = 0, dir = 0, tc = table.config,
475
+ var dynamicExp, sortWrapper, col, mx = 0, dir = 0, tc = table.config,
480
476
  l = sortList.length, bl = table.tBodies.length,
481
477
  sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol;
482
478
  if (tc.debug) { sortTime = new Date(); }
483
479
  for (k = 0; k < bl; k++) {
484
- dynamicExp = "var sortWrapper = function(a,b) {";
480
+ dynamicExp = "sortWrapper = function(a,b) {";
485
481
  cache = tc.cache[k];
486
482
  lc = cache.normalized.length;
487
483
  for (i = 0; i < l; i++) {
@@ -504,7 +500,7 @@
504
500
  dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0;
505
501
  }
506
502
  }
507
- dynamicExp += "var " + e + " = sort" + s + "(table,a[" + c + "],b[" + c + "]," + c + "," + mx + "," + dir + "); ";
503
+ dynamicExp += "var " + e + " = $.tablesorter.sort" + s + "(table,a[" + c + "],b[" + c + "]," + c + "," + mx + "," + dir + "); ";
508
504
  dynamicExp += "if (" + e + ") { return " + e + "; } ";
509
505
  dynamicExp += "else { ";
510
506
  }
@@ -516,94 +512,11 @@
516
512
  }
517
513
  dynamicExp += "return 0; ";
518
514
  dynamicExp += "}; ";
519
- eval(dynamicExp);
520
- cache.normalized.sort(sortWrapper); // sort using eval expression
515
+ cache.normalized.sort(eval(dynamicExp)); // sort using eval expression
521
516
  }
522
517
  if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order+ " time", sortTime); }
523
518
  }
524
519
 
525
- // Natural sort - https://github.com/overset/javascript-natural-sort
526
- function sortText(table, a, b, col) {
527
- if (a === b) { return 0; }
528
- var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ],
529
- r = $.tablesorter.regex, xN, xD, yN, yD, xF, yF, i, mx;
530
- if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
531
- if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
532
- if (typeof c.textSorter === 'function') { return c.textSorter(a, b, table, col); }
533
- // chunk/tokenize
534
- xN = a.replace(r[0], '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0');
535
- yN = b.replace(r[0], '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0');
536
- // numeric, hex or date detection
537
- xD = parseInt(a.match(r[2])) || (xN.length !== 1 && a.match(r[1]) && Date.parse(a));
538
- yD = parseInt(b.match(r[2])) || (xD && b.match(r[1]) && Date.parse(b)) || null;
539
- // first try and sort Hex codes or Dates
540
- if (yD) {
541
- if ( xD < yD ) { return -1; }
542
- if ( xD > yD ) { return 1; }
543
- }
544
- mx = Math.max(xN.length, yN.length);
545
- // natural sorting through split numeric strings and default strings
546
- for (i = 0; i < mx; i++) {
547
- // find floats not starting with '0', string or 0 if not defined (Clint Priest)
548
- xF = (!(xN[i] || '').match(r[3]) && parseFloat(xN[i])) || xN[i] || 0;
549
- yF = (!(yN[i] || '').match(r[3]) && parseFloat(yN[i])) || yN[i] || 0;
550
- // handle numeric vs string comparison - number < string - (Kyle Adams)
551
- if (isNaN(xF) !== isNaN(yF)) { return (isNaN(xF)) ? 1 : -1; }
552
- // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
553
- if (typeof xF !== typeof yF) {
554
- xF += '';
555
- yF += '';
556
- }
557
- if (xF < yF) { return -1; }
558
- if (xF > yF) { return 1; }
559
- }
560
- return 0;
561
- }
562
-
563
- function sortTextDesc(table, a, b, col) {
564
- if (a === b) { return 0; }
565
- var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
566
- if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
567
- if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
568
- if (typeof c.textSorter === 'function') { return c.textSorter(b, a, table, col); }
569
- return sortText(table, b, a);
570
- }
571
-
572
- // return text string value by adding up ascii value
573
- // so the text is somewhat sorted when using a digital sort
574
- // this is NOT an alphanumeric sort
575
- function getTextValue(a, mx, d) {
576
- if (mx) {
577
- // make sure the text value is greater than the max numerical value (mx)
578
- var i, l = a.length, n = mx + d;
579
- for (i = 0; i < l; i++) {
580
- n += a.charCodeAt(i);
581
- }
582
- return d * n;
583
- }
584
- return 0;
585
- }
586
-
587
- function sortNumeric(table, a, b, col, mx, d) {
588
- if (a === b) { return 0; }
589
- var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
590
- if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
591
- if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
592
- if (isNaN(a)) { a = getTextValue(a, mx, d); }
593
- if (isNaN(b)) { b = getTextValue(b, mx, d); }
594
- return a - b;
595
- }
596
-
597
- function sortNumericDesc(table, a, b, col, mx, d) {
598
- if (a === b) { return 0; }
599
- var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
600
- if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
601
- if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
602
- if (isNaN(a)) { a = getTextValue(a, mx, d); }
603
- if (isNaN(b)) { b = getTextValue(b, mx, d); }
604
- return b - a;
605
- }
606
-
607
520
  function checkResort($table, flag, callback) {
608
521
  var t = $table[0];
609
522
  if (flag !== false) {
@@ -701,7 +614,7 @@
701
614
  // add other columns if header spans across multiple
702
615
  if (this.colSpan > 1) {
703
616
  for (j = 1; j < this.colSpan; j++) {
704
- c.sortList.push([i+j, o]);
617
+ c.sortList.push([i + j, o]);
705
618
  }
706
619
  }
707
620
  }
@@ -729,7 +642,7 @@
729
642
  // add other columns if header spans across multiple
730
643
  if (this.colSpan > 1) {
731
644
  for (j = 1; j < this.colSpan; j++) {
732
- c.sortList.push([i+j, o]);
645
+ c.sortList.push([i + j, o]);
733
646
  }
734
647
  }
735
648
  }
@@ -749,8 +662,6 @@
749
662
  setHeadersCss($this[0], $headers, c.sortList);
750
663
  multisort($this[0], c.sortList);
751
664
  appendToTable($this[0]);
752
- // stop normal event by returning false
753
- return false;
754
665
  }
755
666
  });
756
667
  if (c.cancelSelection) {
@@ -861,6 +772,88 @@
861
772
  });
862
773
  };
863
774
 
775
+ // Natural sort - https://github.com/overset/javascript-natural-sort
776
+ this.sortText = function(table, a, b, col) {
777
+ if (a === b) { return 0; }
778
+ var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ],
779
+ r = $.tablesorter.regex, xN, xD, yN, yD, xF, yF, i, mx;
780
+ if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
781
+ if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
782
+ if (typeof c.textSorter === 'function') { return c.textSorter(a, b, table, col); }
783
+ // chunk/tokenize
784
+ xN = a.replace(r[0], '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
785
+ yN = b.replace(r[0], '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
786
+ // numeric, hex or date detection
787
+ xD = parseInt(a.match(r[2]),16) || (xN.length !== 1 && a.match(r[1]) && Date.parse(a));
788
+ yD = parseInt(b.match(r[2]),16) || (xD && b.match(r[1]) && Date.parse(b)) || null;
789
+ // first try and sort Hex codes or Dates
790
+ if (yD) {
791
+ if ( xD < yD ) { return -1; }
792
+ if ( xD > yD ) { return 1; }
793
+ }
794
+ mx = Math.max(xN.length, yN.length);
795
+ // natural sorting through split numeric strings and default strings
796
+ for (i = 0; i < mx; i++) {
797
+ // find floats not starting with '0', string or 0 if not defined (Clint Priest)
798
+ xF = (!(xN[i] || '').match(r[3]) && parseFloat(xN[i])) || xN[i] || 0;
799
+ yF = (!(yN[i] || '').match(r[3]) && parseFloat(yN[i])) || yN[i] || 0;
800
+ // handle numeric vs string comparison - number < string - (Kyle Adams)
801
+ if (isNaN(xF) !== isNaN(yF)) { return (isNaN(xF)) ? 1 : -1; }
802
+ // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
803
+ if (typeof xF !== typeof yF) {
804
+ xF += '';
805
+ yF += '';
806
+ }
807
+ if (xF < yF) { return -1; }
808
+ if (xF > yF) { return 1; }
809
+ }
810
+ return 0;
811
+ };
812
+
813
+ this.sortTextDesc = function(table, a, b, col) {
814
+ if (a === b) { return 0; }
815
+ var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
816
+ if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
817
+ if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
818
+ if (typeof c.textSorter === 'function') { return c.textSorter(b, a, table, col); }
819
+ return this.sortText(table, b, a);
820
+ };
821
+
822
+ // return text string value by adding up ascii value
823
+ // so the text is somewhat sorted when using a digital sort
824
+ // this is NOT an alphanumeric sort
825
+ this.getTextValue = function(a, mx, d) {
826
+ if (mx) {
827
+ // make sure the text value is greater than the max numerical value (mx)
828
+ var i, l = a.length, n = mx + d;
829
+ for (i = 0; i < l; i++) {
830
+ n += a.charCodeAt(i);
831
+ }
832
+ return d * n;
833
+ }
834
+ return 0;
835
+ };
836
+
837
+ this.sortNumeric = function(table, a, b, col, mx, d) {
838
+ if (a === b) { return 0; }
839
+ var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
840
+ if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : -e || -1; }
841
+ if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : e || 1; }
842
+ if (isNaN(a)) { a = this.getTextValue(a, mx, d); }
843
+ if (isNaN(b)) { b = this.getTextValue(b, mx, d); }
844
+ return a - b;
845
+ };
846
+
847
+ this.sortNumericDesc = function(table, a, b, col, mx, d) {
848
+ if (a === b) { return 0; }
849
+ var c = table.config, e = c.string[ (c.empties[col] || c.emptyTo ) ];
850
+ if (a === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? -1 : 1) : e || 1; }
851
+ if (b === '' && e !== 0) { return (typeof(e) === 'boolean') ? (e ? 1 : -1) : -e || -1; }
852
+ if (isNaN(a)) { a = this.getTextValue(a, mx, d); }
853
+ if (isNaN(b)) { b = this.getTextValue(b, mx, d); }
854
+ return b - a;
855
+ };
856
+
864
857
  this.destroy = function(table, removeClasses){
865
858
  var $t = $(table), c = table.config;
866
859
  // remove widget added rows
@@ -1026,19 +1019,14 @@
1026
1019
  ts.addParser({
1027
1020
  id: "ipAddress",
1028
1021
  is: function(s) {
1029
- return (/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/).test(s);
1022
+ return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
1030
1023
  },
1031
1024
  format: function(s, table) {
1032
- var i, item, a = s.split("."),
1025
+ var i, a = s.split("."),
1033
1026
  r = "",
1034
1027
  l = a.length;
1035
1028
  for (i = 0; i < l; i++) {
1036
- item = a[i];
1037
- if (item.length === 2) {
1038
- r += "0" + item;
1039
- } else {
1040
- r += item;
1041
- }
1029
+ r += ("00" + a[i]).slice(-3);
1042
1030
  }
1043
1031
  return ts.formatFloat(r, table);
1044
1032
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-tablesorter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties