jquery-tablesorter 1.10.1 → 1.10.10

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/{README.markdown → README.md} +8 -3
  3. data/Rakefile +39 -35
  4. data/lib/jquery-tablesorter/version.rb +1 -1
  5. data/lib/jquery-tablesorter.rb +1 -1
  6. data/vendor/assets/javascripts/jquery-tablesorter/addons/pager/jquery.tablesorter.pager.js +66 -29
  7. data/vendor/assets/javascripts/jquery-tablesorter/extras/jquery.quicksearch.js +191 -0
  8. data/vendor/assets/javascripts/jquery-tablesorter/extras/semver-mod.js +1026 -0
  9. data/vendor/assets/javascripts/jquery-tablesorter/extras/semver.js +1011 -0
  10. data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.js +156 -99
  11. data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets-filter-formatter.js +22 -22
  12. data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets.js +68 -42
  13. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-date-iso8601.js +34 -0
  14. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-date-month.js +33 -0
  15. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-date-two-digit-year.js +74 -0
  16. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-date-weekday.js +33 -0
  17. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-date.js +36 -0
  18. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-feet-inch-fraction.js +63 -0
  19. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-file-type.js +73 -0
  20. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ignore-articles.js +47 -0
  21. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-input-select.js +87 -0
  22. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-ipv6.js +76 -0
  23. data/vendor/assets/javascripts/jquery-tablesorter/parsers/parser-metric.js +77 -0
  24. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-alignChar.js +145 -0
  25. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-build-table.js +441 -0
  26. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-columnSelector.js +306 -0
  27. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-cssStickyHeaders.js +67 -0
  28. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-editable.js +89 -0
  29. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-grouping.js +249 -0
  30. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-headerTitles.js +91 -0
  31. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-pager.js +864 -0
  32. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-repeatheaders.js +50 -0
  33. data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-scroller.js +241 -0
  34. data/vendor/assets/stylesheets/jquery-tablesorter/theme.black-ice.css +4 -0
  35. data/vendor/assets/stylesheets/jquery-tablesorter/theme.blue.css +4 -0
  36. data/vendor/assets/stylesheets/jquery-tablesorter/theme.bootstrap.css +14 -5
  37. data/vendor/assets/stylesheets/jquery-tablesorter/theme.bootstrap_2.css +4 -0
  38. data/vendor/assets/stylesheets/jquery-tablesorter/theme.dark.css +4 -0
  39. data/vendor/assets/stylesheets/jquery-tablesorter/theme.default.css +4 -0
  40. data/vendor/assets/stylesheets/jquery-tablesorter/theme.dropbox.css +4 -0
  41. data/vendor/assets/stylesheets/jquery-tablesorter/theme.green.css +4 -0
  42. data/vendor/assets/stylesheets/jquery-tablesorter/theme.grey.css +4 -0
  43. data/vendor/assets/stylesheets/jquery-tablesorter/theme.ice.css +4 -0
  44. data/vendor/assets/stylesheets/jquery-tablesorter/theme.jui.css +9 -3
  45. metadata +28 -12
  46. data/vendor/assets/images/jquery-tablesorter/dropbox-asc1.png +0 -0
  47. data/vendor/assets/images/jquery-tablesorter/dropbox-asc2.png +0 -0
  48. data/vendor/assets/images/jquery-tablesorter/dropbox-desc1.png +0 -0
  49. data/vendor/assets/images/jquery-tablesorter/dropbox-desc2.png +0 -0
  50. data/vendor/assets/images/jquery-tablesorter/green-asc.png +0 -0
  51. data/vendor/assets/images/jquery-tablesorter/green-desc.png +0 -0
  52. data/vendor/assets/images/jquery-tablesorter/green-header.png +0 -0
  53. data/vendor/assets/images/jquery-tablesorter/green-unsorted.png +0 -0
@@ -1,5 +1,5 @@
1
1
  /**!
2
- * TableSorter 2.15.1 - Client-side table sorting with ease!
2
+ * TableSorter 2.15.14 - Client-side table sorting with ease!
3
3
  * @requires jQuery v1.2.6+
4
4
  *
5
5
  * Copyright (c) 2007 Christian Bach
@@ -24,7 +24,7 @@
24
24
 
25
25
  var ts = this;
26
26
 
27
- ts.version = "2.15.1";
27
+ ts.version = "2.15.14";
28
28
 
29
29
  ts.parsers = [];
30
30
  ts.widgets = [];
@@ -114,6 +114,7 @@
114
114
  // the table and MUST only contain one class name - fixes #381
115
115
  ts.css = {
116
116
  table : 'tablesorter',
117
+ cssHasChild: 'tablesorter-hasChildRow',
117
118
  childRow : 'tablesorter-childRow',
118
119
  header : 'tablesorter-header',
119
120
  headerRow : 'tablesorter-headerRow',
@@ -289,13 +290,24 @@
289
290
  c = $(b[k].rows[i]);
290
291
  cols = [];
291
292
  // if this is a child row, add it to the last row's children and continue to the next row
292
- if (c.hasClass(tc.cssChildRow)) {
293
+ // ignore child row class, if it is the first row
294
+ if (c.hasClass(tc.cssChildRow) && i !== 0) {
293
295
  tc.cache[k].row[tc.cache[k].row.length - 1] = tc.cache[k].row[tc.cache[k].row.length - 1].add(c);
296
+ // add "hasChild" class name to parent row
297
+ if (!c.prev().hasClass(tc.cssChildRow)) {
298
+ c.prev().addClass(ts.css.cssHasChild);
299
+ }
294
300
  // go to the next for loop
295
301
  continue;
296
302
  }
297
303
  tc.cache[k].row.push(c);
298
304
  for (j = 0; j < totalCells; ++j) {
305
+ if (typeof parsers[j] === 'undefined') {
306
+ if (tc.debug) {
307
+ log('No parser found for cell:', c[0].cells[j], 'does it have a header?');
308
+ }
309
+ continue;
310
+ }
299
311
  t = getElementText(table, c[0].cells[j], j);
300
312
  // allow parsing if the string is empty, previously parsing would change it to zero,
301
313
  // in case the parser needs to extract data from the table cell attributes
@@ -331,7 +343,8 @@
331
343
  // empty table - fixes #206/#346
332
344
  if (isEmptyObject(c2)) {
333
345
  // run pager appender in case the table was just emptied
334
- return c.appender ? c.appender(table, rows) : '';
346
+ return c.appender ? c.appender(table, rows) :
347
+ table.isUpdating ? c.$table.trigger("updateComplete", table) : ''; // Fixes #532
335
348
  }
336
349
  if (c.debug) {
337
350
  appendTime = new Date();
@@ -368,9 +381,9 @@
368
381
  }
369
382
  // apply table widgets; but not before ajax completes
370
383
  if (!init && !c.appender) { ts.applyWidget(table); }
371
- // trigger sortend
372
- $(table).trigger("sortEnd", table);
373
- $(table).trigger("updateComplete", table);
384
+ if (table.isUpdating) {
385
+ c.$table.trigger("updateComplete", table);
386
+ }
374
387
  }
375
388
 
376
389
  // computeTableHeaderCellIndexes from:
@@ -380,14 +393,14 @@
380
393
  var matrix = [],
381
394
  lookup = {},
382
395
  cols = 0, // determine the number of columns
383
- trs = $(t).find('thead:eq(0), tfoot').children('tr'), // children tr in tfoot - see issue #196
396
+ trs = $(t).children('thead, tfoot').children('tr'), // children tr in tfoot - see issue #196 & #547
384
397
  i, j, k, l, c, cells, rowIndex, cellId, rowSpan, colSpan, firstAvailCol, matrixrow;
385
398
  for (i = 0; i < trs.length; i++) {
386
399
  cells = trs[i].cells;
387
400
  for (j = 0; j < cells.length; j++) {
388
401
  c = cells[j];
389
402
  rowIndex = c.parentNode.rowIndex;
390
- cellId = rowIndex + "-" + c.cellIndex;
403
+ cellId = rowIndex + "-" + $(c).index();
391
404
  rowSpan = c.rowSpan || 1;
392
405
  colSpan = c.colSpan || 1;
393
406
  if (typeof(matrix[rowIndex]) === "undefined") {
@@ -417,7 +430,6 @@
417
430
  }
418
431
  // may not be accurate if # header columns !== # tbody columns
419
432
  t.config.columns = cols + 1; // add one because it's a zero-based index
420
- return lookup;
421
433
  }
422
434
 
423
435
  function formatSortingOrder(v) {
@@ -426,13 +438,15 @@
426
438
  }
427
439
 
428
440
  function buildHeaders(table) {
429
- var header_index = computeThIndexes(table), ch, $t,
430
- h, i, t, lock, time, c = table.config;
441
+ var ch, $t,
442
+ h, i, t, lock, time,
443
+ c = table.config;
431
444
  c.headerList = [];
432
445
  c.headerContent = [];
433
446
  if (c.debug) {
434
447
  time = new Date();
435
448
  }
449
+ computeThIndexes(table);
436
450
  // add icon if cssIcon option exists
437
451
  i = c.cssIcon ? '<i class="' + ( c.cssIcon === ts.css.icon ? ts.css.icon : c.cssIcon + ' ' + ts.css.icon ) + '"></i>' : '';
438
452
  c.$headers = $(table).find(c.selectorHeaders).each(function(index) {
@@ -448,8 +462,7 @@
448
462
  $(this).html('<div class="' + ts.css.headerIn + '">' + t + '</div>'); // faster than wrapInner
449
463
 
450
464
  if (c.onRenderHeader) { c.onRenderHeader.apply($t, [index]); }
451
-
452
- this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
465
+ this.column = parseInt( $(this).attr('data-column'), 10);
453
466
  this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
454
467
  this.count = -1; // set to -1 because clicking on the header automatically adds one
455
468
  this.lockedOrder = false;
@@ -582,92 +595,95 @@
582
595
  return (parsers && parsers[i]) ? parsers[i].type || '' : '';
583
596
  }
584
597
 
585
- function initSort(table, cell, e){
586
- var a, i, j, o, s,
598
+ function initSort(table, cell, event){
599
+ var arry, indx, col, order, s,
587
600
  c = table.config,
588
- k = !e[c.sortMultiSortKey],
589
- $table = $(table);
601
+ key = !event[c.sortMultiSortKey],
602
+ $table = c.$table;
590
603
  // Only call sortStart if sorting is enabled
591
604
  $table.trigger("sortStart", table);
592
605
  // get current column sort order
593
- cell.count = e[c.sortResetKey] ? 2 : (cell.count + 1) % (c.sortReset ? 3 : 2);
606
+ cell.count = event[c.sortResetKey] ? 2 : (cell.count + 1) % (c.sortReset ? 3 : 2);
594
607
  // reset all sorts on non-current column - issue #30
595
608
  if (c.sortRestart) {
596
- i = cell;
609
+ indx = cell;
597
610
  c.$headers.each(function() {
598
611
  // only reset counts on columns that weren't just clicked on and if not included in a multisort
599
- if (this !== i && (k || !$(this).is('.' + ts.css.sortDesc + ',.' + ts.css.sortAsc))) {
612
+ if (this !== indx && (key || !$(this).is('.' + ts.css.sortDesc + ',.' + ts.css.sortAsc))) {
600
613
  this.count = -1;
601
614
  }
602
615
  });
603
616
  }
604
617
  // get current column index
605
- i = cell.column;
618
+ indx = cell.column;
606
619
  // user only wants to sort on one column
607
- if (k) {
620
+ if (key) {
608
621
  // flush the sort list
609
622
  c.sortList = [];
610
623
  if (c.sortForce !== null) {
611
- a = c.sortForce;
612
- for (j = 0; j < a.length; j++) {
613
- if (a[j][0] !== i) {
614
- c.sortList.push(a[j]);
624
+ arry = c.sortForce;
625
+ for (col = 0; col < arry.length; col++) {
626
+ if (arry[col][0] !== indx) {
627
+ c.sortList.push(arry[col]);
615
628
  }
616
629
  }
617
630
  }
618
631
  // add column to sort list
619
- o = cell.order[cell.count];
620
- if (o < 2) {
621
- c.sortList.push([i, o]);
632
+ order = cell.order[cell.count];
633
+ if (order < 2) {
634
+ c.sortList.push([indx, order]);
622
635
  // add other columns if header spans across multiple
623
636
  if (cell.colSpan > 1) {
624
- for (j = 1; j < cell.colSpan; j++) {
625
- c.sortList.push([i + j, o]);
637
+ for (col = 1; col < cell.colSpan; col++) {
638
+ c.sortList.push([indx + col, order]);
626
639
  }
627
640
  }
628
641
  }
629
642
  // multi column sorting
630
643
  } else {
631
- // get rid of the sortAppend before adding more - fixes issue #115
644
+ // get rid of the sortAppend before adding more - fixes issue #115 & #523
632
645
  if (c.sortAppend && c.sortList.length > 1) {
633
- if (ts.isValueInArray(c.sortAppend[0][0], c.sortList)) {
634
- c.sortList.pop();
646
+ for (col = 0; col < c.sortAppend.length; col++) {
647
+ s = ts.isValueInArray(c.sortAppend[col][0], c.sortList);
648
+ if (s >= 0) {
649
+ c.sortList.splice(s,1);
650
+ }
635
651
  }
636
652
  }
637
653
  // the user has clicked on an already sorted column
638
- if (ts.isValueInArray(i, c.sortList)) {
654
+ if (ts.isValueInArray(indx, c.sortList) >= 0) {
639
655
  // reverse the sorting direction
640
- for (j = 0; j < c.sortList.length; j++) {
641
- s = c.sortList[j];
642
- o = c.$headers[s[0]];
643
- if (s[0] === i) {
644
- // o.count seems to be incorrect when compared to cell.count
645
- s[1] = o.order[cell.count];
656
+ for (col = 0; col < c.sortList.length; col++) {
657
+ s = c.sortList[col];
658
+ order = c.$headers[s[0]];
659
+ if (s[0] === indx) {
660
+ // order.count seems to be incorrect when compared to cell.count
661
+ s[1] = order.order[cell.count];
646
662
  if (s[1] === 2) {
647
- c.sortList.splice(j,1);
648
- o.count = -1;
663
+ c.sortList.splice(col,1);
664
+ order.count = -1;
649
665
  }
650
666
  }
651
667
  }
652
668
  } else {
653
669
  // add column to sort list array
654
- o = cell.order[cell.count];
655
- if (o < 2) {
656
- c.sortList.push([i, o]);
670
+ order = cell.order[cell.count];
671
+ if (order < 2) {
672
+ c.sortList.push([indx, order]);
657
673
  // add other columns if header spans across multiple
658
674
  if (cell.colSpan > 1) {
659
- for (j = 1; j < cell.colSpan; j++) {
660
- c.sortList.push([i + j, o]);
675
+ for (col = 1; col < cell.colSpan; col++) {
676
+ c.sortList.push([indx + col, order]);
661
677
  }
662
678
  }
663
679
  }
664
680
  }
665
681
  }
666
682
  if (c.sortAppend !== null) {
667
- a = c.sortAppend;
668
- for (j = 0; j < a.length; j++) {
669
- if (a[j][0] !== i) {
670
- c.sortList.push(a[j]);
683
+ arry = c.sortAppend;
684
+ for (col = 0; col < arry.length; col++) {
685
+ if (arry[col][0] !== indx) {
686
+ c.sortList.push(arry[col]);
671
687
  }
672
688
  }
673
689
  }
@@ -679,6 +695,7 @@
679
695
  setHeadersCss(table);
680
696
  multisort(table);
681
697
  appendToTable(table);
698
+ $table.trigger("sortEnd", table);
682
699
  }, 1);
683
700
  }
684
701
 
@@ -724,7 +741,7 @@
724
741
  }
725
742
  // fall back to built-in numeric sort
726
743
  // var sort = $.tablesorter["sort" + s](table, a[c], b[c], c, colMax[c], dir);
727
- sort = c.numberSorter ? c.numberSorter(x[col], y[col], dir, colMax[col], table) :
744
+ sort = c.numberSorter ? c.numberSorter(a[col], b[col], dir, colMax[col], table) :
728
745
  ts[ 'sortNumeric' + (dir ? 'Asc' : 'Desc') ](a[col], b[col], num, colMax[col], col, table);
729
746
  } else {
730
747
  // set a & b depending on sort direction
@@ -751,8 +768,8 @@
751
768
  }
752
769
 
753
770
  function resortComplete($table, callback){
754
- var c = $table[0].config;
755
- if (c.pager && !c.pager.ajax) {
771
+ var table = $table[0];
772
+ if (table.isUpdating) {
756
773
  $table.trigger('updateComplete');
757
774
  }
758
775
  if (typeof callback === "function") {
@@ -761,13 +778,15 @@
761
778
  }
762
779
 
763
780
  function checkResort($table, flag, callback) {
781
+ var sl = $table[0].config.sortList;
764
782
  // don't try to resort if the table is still processing
765
783
  // this will catch spamming of the updateCell method
766
- if (flag !== false && !$table[0].isProcessing) {
767
- $table.trigger("sorton", [$table[0].config.sortList, function(){
784
+ if (flag !== false && !$table[0].isProcessing && sl.length) {
785
+ $table.trigger("sorton", [sl, function(){
768
786
  resortComplete($table, callback);
769
- }]);
787
+ }, true]);
770
788
  } else {
789
+ $table.trigger('applyWidgets');
771
790
  resortComplete($table, callback);
772
791
  }
773
792
  }
@@ -777,16 +796,17 @@
777
796
  $table = c.$table;
778
797
  // apply easy methods that trigger bound events
779
798
  $table
780
- .unbind('sortReset update updateRows updateCell updateAll addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave '.split(' ').join('.tablesorter '))
781
- .bind("sortReset.tablesorter", function(e){
799
+ .unbind('sortReset update updateRows updateCell updateAll addRows updateComplete sorton appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave '.split(' ').join(c.namespace + ' '))
800
+ .bind("sortReset" + c.namespace, function(e){
782
801
  e.stopPropagation();
783
802
  c.sortList = [];
784
803
  setHeadersCss(table);
785
804
  multisort(table);
786
805
  appendToTable(table);
787
806
  })
788
- .bind("updateAll.tablesorter", function(e, resort, callback){
807
+ .bind("updateAll" + c.namespace, function(e, resort, callback){
789
808
  e.stopPropagation();
809
+ table.isUpdating = true;
790
810
  ts.refreshWidgets(table, true, true);
791
811
  ts.restoreHeaders(table);
792
812
  buildHeaders(table);
@@ -794,14 +814,16 @@
794
814
  bindMethods(table);
795
815
  commonUpdate(table, resort, callback);
796
816
  })
797
- .bind("update.tablesorter updateRows.tablesorter", function(e, resort, callback) {
817
+ .bind("update" + c.namespace + " updateRows" + c.namespace, function(e, resort, callback) {
798
818
  e.stopPropagation();
819
+ table.isUpdating = true;
799
820
  // update sorting (if enabled/disabled)
800
821
  updateHeader(table);
801
822
  commonUpdate(table, resort, callback);
802
823
  })
803
- .bind("updateCell.tablesorter", function(e, cell, resort, callback) {
824
+ .bind("updateCell" + c.namespace, function(e, cell, resort, callback) {
804
825
  e.stopPropagation();
826
+ table.isUpdating = true;
805
827
  $table.find(c.selectorRemove).remove();
806
828
  // get position from the dom
807
829
  var l, row, icell,
@@ -814,15 +836,16 @@
814
836
  // tbody may not exist if update is initialized while tbody is removed for processing
815
837
  if ($tb.length && tbdy >= 0) {
816
838
  row = $tb.eq(tbdy).find('tr').index( $row );
817
- icell = cell.cellIndex;
839
+ icell = $(cell).index();
818
840
  l = c.cache[tbdy].normalized[row].length - 1;
819
- c.cache[tbdy].row[table.config.cache[tbdy].normalized[row][l]] = $row;
841
+ c.cache[tbdy].row[ c.cache[tbdy].normalized[row][l] ] = $row;
820
842
  c.cache[tbdy].normalized[row][icell] = c.parsers[icell].format( getElementText(table, cell, icell), table, cell, icell );
821
843
  checkResort($table, resort, callback);
822
844
  }
823
845
  })
824
- .bind("addRows.tablesorter", function(e, $row, resort, callback) {
846
+ .bind("addRows" + c.namespace, function(e, $row, resort, callback) {
825
847
  e.stopPropagation();
848
+ table.isUpdating = true;
826
849
  if (isEmptyObject(c.cache)) {
827
850
  // empty table, do an update instead - fixes #450
828
851
  updateHeader(table);
@@ -853,7 +876,10 @@
853
876
  checkResort($table, resort, callback);
854
877
  }
855
878
  })
856
- .bind("sorton.tablesorter", function(e, list, callback, init) {
879
+ .bind("updateComplete" + c.namespace, function(){
880
+ table.isUpdating = false;
881
+ })
882
+ .bind("sorton" + c.namespace, function(e, list, callback, init) {
857
883
  var c = table.config;
858
884
  e.stopPropagation();
859
885
  $table.trigger("sortStart", this);
@@ -867,31 +893,45 @@
867
893
  // sort the table and append it to the dom
868
894
  multisort(table);
869
895
  appendToTable(table, init);
896
+ $table
897
+ .trigger("sortEnd", this)
898
+ .trigger('applyWidgets');
870
899
  if (typeof callback === "function") {
871
900
  callback(table);
872
901
  }
873
902
  })
874
- .bind("appendCache.tablesorter", function(e, callback, init) {
903
+ .bind("appendCache" + c.namespace, function(e, callback, init) {
875
904
  e.stopPropagation();
876
905
  appendToTable(table, init);
877
906
  if (typeof callback === "function") {
878
907
  callback(table);
879
908
  }
880
909
  })
881
- .bind("applyWidgetId.tablesorter", function(e, id) {
910
+ .bind("updateCache" + c.namespace, function(e, callback){
911
+ // rebuild parsers
912
+ if (!c.parsers) {
913
+ buildParserCache(table);
914
+ }
915
+ // rebuild the cache map
916
+ buildCache(table);
917
+ if (typeof callback === "function") {
918
+ callback(table);
919
+ }
920
+ })
921
+ .bind("applyWidgetId" + c.namespace, function(e, id) {
882
922
  e.stopPropagation();
883
923
  ts.getWidgetById(id).format(table, c, c.widgetOptions);
884
924
  })
885
- .bind("applyWidgets.tablesorter", function(e, init) {
925
+ .bind("applyWidgets" + c.namespace, function(e, init) {
886
926
  e.stopPropagation();
887
927
  // apply widgets
888
928
  ts.applyWidget(table, init);
889
929
  })
890
- .bind("refreshWidgets.tablesorter", function(e, all, dontapply){
930
+ .bind("refreshWidgets" + c.namespace, function(e, all, dontapply){
891
931
  e.stopPropagation();
892
932
  ts.refreshWidgets(table, all, dontapply);
893
933
  })
894
- .bind("destroy.tablesorter", function(e, c, cb){
934
+ .bind("destroy" + c.namespace, function(e, c, cb){
895
935
  e.stopPropagation();
896
936
  ts.destroy(table, c, cb);
897
937
  });
@@ -907,8 +947,9 @@
907
947
  if (!table.hasInitialized && ts.buildTable && this.tagName !== 'TABLE') {
908
948
  // return the table (in case the original target is the table's container)
909
949
  ts.buildTable(table, c);
950
+ } else {
951
+ ts.setup(table, c);
910
952
  }
911
- ts.setup(table, c);
912
953
  });
913
954
  };
914
955
 
@@ -947,11 +988,19 @@
947
988
  c.$table = $table
948
989
  .addClass(ts.css.table + ' ' + c.tableClass + k)
949
990
  .attr({ role : 'grid'});
991
+
992
+ // give the table a unique id, which will be used in namespace binding
993
+ if (!c.namespace) {
994
+ c.namespace = '.tablesorter' + Math.random().toString(16).slice(2);
995
+ } else {
996
+ // make sure namespace starts with a period & doesn't have weird characters
997
+ c.namespace = '.' + c.namespace.replace(/\W/g,'');
998
+ }
999
+
950
1000
  c.$tbodies = $table.children('tbody:not(.' + c.cssInfoBlock + ')').attr({
951
1001
  'aria-live' : 'polite',
952
1002
  'aria-relevant' : 'all'
953
1003
  });
954
- //
955
1004
  if (c.$table.find('caption').length) {
956
1005
  c.$table.attr('aria-labelledby', 'theCaption');
957
1006
  }
@@ -980,7 +1029,7 @@
980
1029
  ts.applyWidget(table, true);
981
1030
  // if user has supplied a sort list to constructor
982
1031
  if (c.sortList.length > 0) {
983
- $table.trigger("sorton", [c.sortList, {}, !c.initWidgets]);
1032
+ $table.trigger("sorton", [c.sortList, {}, !c.initWidgets, true]);
984
1033
  } else {
985
1034
  setHeadersCss(table);
986
1035
  if (c.initWidgets) {
@@ -992,8 +1041,8 @@
992
1041
  // show processesing icon
993
1042
  if (c.showProcessing) {
994
1043
  $table
995
- .unbind('sortBegin.tablesorter sortEnd.tablesorter')
996
- .bind('sortBegin.tablesorter sortEnd.tablesorter', function(e) {
1044
+ .unbind('sortBegin' + c.namespace + ' sortEnd' + c.namespace)
1045
+ .bind('sortBegin' + c.namespace + ' sortEnd' + c.namespace, function(e) {
997
1046
  ts.isProcessing(table, e.type === 'sortBegin');
998
1047
  });
999
1048
  }
@@ -1021,7 +1070,7 @@
1021
1070
  // get headers from the sortList
1022
1071
  $h = $h.filter(function(){
1023
1072
  // get data-column from attr to keep compatibility with jQuery 1.2.6
1024
- return this.sortDisabled ? false : ts.isValueInArray( parseFloat($(this).attr('data-column')), c.sortList);
1073
+ return this.sortDisabled ? false : ts.isValueInArray( parseFloat($(this).attr('data-column')), c.sortList) >= 0;
1025
1074
  });
1026
1075
  }
1027
1076
  $h.addClass(ts.css.processing + ' ' + c.cssProcessing);
@@ -1059,8 +1108,8 @@
1059
1108
  $headers
1060
1109
  // http://stackoverflow.com/questions/5312849/jquery-find-self;
1061
1110
  .find(c.selectorSort).add( $headers.filter(c.selectorSort) )
1062
- .unbind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter keyup.tablesorter')
1063
- .bind('mousedown.tablesorter mouseup.tablesorter sort.tablesorter keyup.tablesorter', function(e, external) {
1111
+ .unbind('mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' '))
1112
+ .bind('mousedown mouseup sort keyup '.split(' ').join(c.namespace + ' '), function(e, external) {
1064
1113
  var cell, type = e.type;
1065
1114
  // only recognize left clicks or enter
1066
1115
  if ( ((e.which || e.button) !== 1 && !/sort|keyup/.test(type)) || (type === 'keyup' && e.which !== 13) ) {
@@ -1076,6 +1125,8 @@
1076
1125
  if (c.delayInit && isEmptyObject(c.cache)) { buildCache(table); }
1077
1126
  // jQuery v1.2.6 doesn't have closest()
1078
1127
  cell = /TH|TD/.test(this.tagName) ? this : $(this).parents('th, td')[0];
1128
+ // reference original table headers and find the same cell
1129
+ cell = c.$headers[ $headers.index( cell ) ];
1079
1130
  if (!cell.sortDisabled) {
1080
1131
  initSort(table, cell, e);
1081
1132
  }
@@ -1114,20 +1165,25 @@
1114
1165
  $h = $t.find('thead:first'),
1115
1166
  $r = $h.find('tr.' + ts.css.headerRow).removeClass(ts.css.headerRow + ' ' + c.cssHeaderRow),
1116
1167
  $f = $t.find('tfoot:first > tr').children('th, td');
1168
+ if (removeClasses === false && $.inArray('uitheme', c.widgets) >= 0) {
1169
+ // reapply uitheme classes, in case we want to maintain appearance
1170
+ $t.trigger('applyWidgetId', ['uitheme']);
1171
+ $t.trigger('applyWidgetId', ['zebra']);
1172
+ }
1117
1173
  // remove widget added rows, just in case
1118
1174
  $h.find('tr').not($r).remove();
1119
1175
  // disable tablesorter
1120
1176
  $t
1121
1177
  .removeData('tablesorter')
1122
- .unbind('sortReset update updateAll updateRows updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave keypress sortBegin sortEnd '.split(' ').join('.tablesorter '));
1178
+ .unbind('sortReset update updateAll updateRows updateCell addRows updateComplete sorton appendCache updateCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave keypress sortBegin sortEnd '.split(' ').join(c.namespace + ' '));
1123
1179
  c.$headers.add($f)
1124
1180
  .removeClass( [ts.css.header, c.cssHeader, c.cssAsc, c.cssDesc, ts.css.sortAsc, ts.css.sortDesc, ts.css.sortNone].join(' ') )
1125
- .removeAttr('data-column');
1126
- $r.find(c.selectorSort).unbind('mousedown.tablesorter mouseup.tablesorter keypress.tablesorter');
1181
+ .removeAttr('data-column')
1182
+ .removeAttr('aria-label')
1183
+ .attr('aria-disabled', 'true');
1184
+ $r.find(c.selectorSort).unbind('mousedown mouseup keypress '.split(' ').join(c.namespace + ' '));
1127
1185
  ts.restoreHeaders(table);
1128
- if (removeClasses !== false) {
1129
- $t.removeClass(ts.css.table + ' ' + c.tableClass + ' tablesorter-' + c.theme);
1130
- }
1186
+ $t.toggleClass(ts.css.table + ' ' + c.tableClass + ' tablesorter-' + c.theme, removeClasses === false);
1131
1187
  // clear flag in case the plugin is initialized again
1132
1188
  table.hasInitialized = false;
1133
1189
  if (typeof callback === 'function') {
@@ -1139,6 +1195,7 @@
1139
1195
  // regex used in natural sort
1140
1196
  ts.regex = {
1141
1197
  chunk : /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi, // chunk/tokenize numbers & letters
1198
+ chunks: /(^\\0|\\0$)/, // replace chunks @ ends
1142
1199
  hex: /^0x[0-9a-f]+$/i // hex
1143
1200
  };
1144
1201
 
@@ -1155,8 +1212,8 @@
1155
1212
  if ( xD > yD ) { return 1; }
1156
1213
  }
1157
1214
  // chunk/tokenize
1158
- xN = a.replace(r.chunk, '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
1159
- yN = b.replace(r.chunk, '\\0$1\\0').replace(/\\0$/, '').replace(/^\\0/, '').split('\\0');
1215
+ xN = a.replace(r.chunk, '\\0$1\\0').replace(r.chunks, '').split('\\0');
1216
+ yN = b.replace(r.chunk, '\\0$1\\0').replace(r.chunks, '').split('\\0');
1160
1217
  mx = Math.max(xN.length, yN.length);
1161
1218
  // natural sorting through split numeric strings and default strings
1162
1219
  for (i = 0; i < mx; i++) {
@@ -1278,14 +1335,14 @@
1278
1335
  };
1279
1336
 
1280
1337
  // *** utilities ***
1281
- ts.isValueInArray = function(v, a) {
1282
- var i, l = a.length;
1283
- for (i = 0; i < l; i++) {
1284
- if (a[i][0] === v) {
1285
- return true;
1338
+ ts.isValueInArray = function(column, arry) {
1339
+ var indx, len = arry.length;
1340
+ for (indx = 0; indx < len; indx++) {
1341
+ if (arry[indx][0] === column) {
1342
+ return indx;
1286
1343
  }
1287
1344
  }
1288
- return false;
1345
+ return -1;
1289
1346
  };
1290
1347
 
1291
1348
  ts.addParser = function(parser) {
@@ -1531,7 +1588,7 @@
1531
1588
  return (/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/).test(s);
1532
1589
  },
1533
1590
  format: function(s, table) {
1534
- return s ? ts.formatFloat((s !== "") ? (new Date(s.replace(/-/g, "/")).getTime() || "") : "", table) : s;
1591
+ return s ? ts.formatFloat((s !== "") ? (new Date(s.replace(/-/g, "/")).getTime() || s) : "", table) : s;
1535
1592
  },
1536
1593
  type: "numeric"
1537
1594
  });
@@ -1555,7 +1612,7 @@
1555
1612
  return (/^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i).test(s) || (/^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i).test(s);
1556
1613
  },
1557
1614
  format: function(s, table) {
1558
- return s ? ts.formatFloat( (new Date(s.replace(/(\S)([AP]M)$/i, "$1 $2")).getTime() || ''), table) : s;
1615
+ return s ? ts.formatFloat( (new Date(s.replace(/(\S)([AP]M)$/i, "$1 $2")).getTime() || s), table) : s;
1559
1616
  },
1560
1617
  type: "numeric"
1561
1618
  });
@@ -1580,7 +1637,7 @@
1580
1637
  s = s.replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/, "$1/$2/$3");
1581
1638
  }
1582
1639
  }
1583
- return s ? ts.formatFloat( (new Date(s).getTime() || ''), table) : s;
1640
+ return s ? ts.formatFloat( (new Date(s).getTime() || s), table) : s;
1584
1641
  },
1585
1642
  type: "numeric"
1586
1643
  });
@@ -1591,7 +1648,7 @@
1591
1648
  return (/^(([0-2]?\d:[0-5]\d)|([0-1]?\d:[0-5]\d\s?([AP]M)))$/i).test(s);
1592
1649
  },
1593
1650
  format: function(s, table) {
1594
- return s ? ts.formatFloat( (new Date("2000/01/01 " + s.replace(/(\S)([AP]M)$/i, "$1 $2")).getTime() || ""), table) : s;
1651
+ return s ? ts.formatFloat( (new Date("2000/01/01 " + s.replace(/(\S)([AP]M)$/i, "$1 $2")).getTime() || s), table) : s;
1595
1652
  },
1596
1653
  type: "numeric"
1597
1654
  });