jquery-tablesorter 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.8(6/5/2012), [documentation]
6
+ Current version: 2.3.10(6/21/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.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -32,7 +32,7 @@ namespace :jquery_tablesorter do
32
32
  'vendor/assets/javascripts/jquery-tablesorter/addons/',
33
33
  :verbose => true
34
34
  FileUtils.cp_r 'tablesorter/addons/pager/icons',
35
- 'vendor/assets/images/jquery-tablesorter/addons/icons',
35
+ 'vendor/assets/images/jquery-tablesorter/addons',
36
36
  :verbose => true
37
37
 
38
38
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * TableSorter 2.3.8 - Client-side table sorting with ease!
2
+ * TableSorter 2.3.10 - 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.8";
21
+ this.version = "2.3.10";
22
22
 
23
23
  var parsers = [], widgets = [];
24
24
  this.defaults = {
@@ -384,7 +384,7 @@
384
384
  $t = $(this);
385
385
  ch = c.headers[index];
386
386
  this.innerHTML = '<div class="tablesorter-header-inner">' + this.innerHTML + '</div>'; // faster than wrapInner
387
- if (c.onRenderHeader) { c.onRenderHeader.apply($th, [index]); }
387
+ if (c.onRenderHeader) { c.onRenderHeader.apply($t, [index]); }
388
388
  this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
389
389
  this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
390
390
  this.count = -1; // set to -1 because clicking on the header automatically adds one
@@ -464,7 +464,9 @@
464
464
  for (i = 0; i < l; i++) {
465
465
  s = sortList[i];
466
466
  o = c.headerList[s[0]];
467
- o.count = s[1] % (c.sortReset ? 3 : 2);
467
+ if (o) { // prevents error if sorton array is wrong
468
+ o.count = s[1] % (c.sortReset ? 3 : 2);
469
+ }
468
470
  }
469
471
  }
470
472
 
@@ -602,6 +604,23 @@
602
604
  return b - a;
603
605
  }
604
606
 
607
+ function checkResort($table, flag, callback) {
608
+ var t = $table[0];
609
+ if (flag !== false) {
610
+ $table.trigger("sorton", [t.config.sortList, function(){
611
+ $table.trigger('updateComplete');
612
+ if (typeof callback === "function") {
613
+ callback(t);
614
+ }
615
+ }]);
616
+ } else {
617
+ $table.trigger('updateComplete');
618
+ if (typeof callback === "function") {
619
+ callback(t);
620
+ }
621
+ }
622
+ }
623
+
605
624
  /* public methods */
606
625
  this.construct = function(settings) {
607
626
  return this.each(function() {
@@ -609,12 +628,12 @@
609
628
  if (!this.tHead || this.tBodies.length === 0) { return; }
610
629
  // declare
611
630
  var $headers, $cell, $this,
612
- config, c, i, j, k, a, s, o, downTime,
631
+ c, i, j, k, a, s, o, downTime,
613
632
  m = $.metadata;
614
633
  // new blank config object
615
634
  this.config = {};
616
635
  // merge and extend.
617
- c = config = $.extend(true, this.config, $.tablesorter.defaults, settings);
636
+ c = $.extend(true, this.config, $.tablesorter.defaults, settings);
618
637
 
619
638
  if (c.debug) { $.data( this, 'startoveralltimer', new Date()); }
620
639
  // store common expression for speed
@@ -744,16 +763,16 @@
744
763
  }
745
764
  // apply easy methods that trigger binded events
746
765
  $this
747
- .bind("update", function(e, resort) {
766
+ .bind("update", function(e, resort, callback) {
748
767
  // remove rows/elements before update
749
768
  $(c.selectorRemove, this).remove();
750
769
  // rebuild parsers.
751
770
  c.parsers = buildParserCache(this, $headers);
752
771
  // rebuild the cache map
753
772
  buildCache(this);
754
- if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
773
+ checkResort($this, resort, callback);
755
774
  })
756
- .bind("updateCell", function(e, cell, resort) {
775
+ .bind("updateCell", function(e, cell, resort, callback) {
757
776
  // get position from the dom.
758
777
  var t = this, $tb = $(this).find('tbody'), row, pos,
759
778
  // update cache - format: function(s, table, cell, cellIndex)
@@ -761,9 +780,9 @@
761
780
  row = $tb.eq(tbdy).find('tr').index( $(cell).closest('tr') );
762
781
  pos = [ row, cell.cellIndex];
763
782
  t.config.cache[tbdy].normalized[pos[0]][pos[1]] = c.parsers[pos[1]].format( getElementText(t, cell, pos[1]), t, cell, pos[1] );
764
- if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
783
+ checkResort($this, resort, callback);
765
784
  })
766
- .bind("addRows", function(e, $row, resort) {
785
+ .bind("addRows", function(e, $row, resort, callback) {
767
786
  var i, rows = $row.filter('tr').length,
768
787
  dat = [], l = $row[0].cells.length, t = this,
769
788
  tbdy = $(this).find('tbody').index( $row.closest('tbody') );
@@ -781,12 +800,16 @@
781
800
  dat = [];
782
801
  }
783
802
  // resort using current settings
784
- if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
803
+ checkResort($this, resort, callback);
785
804
  })
786
- .bind("sorton", function(e, list, init) {
805
+ .bind("sorton", function(e, list, callback, init) {
787
806
  $(this).trigger("sortStart", this);
788
- // update and store the sortlist
789
- c.sortList = list;
807
+ var l = c.headerList.length;
808
+ c.sortList = [];
809
+ $.each(list, function(i,v){
810
+ // make sure column exists
811
+ if (v[0] < l) { c.sortList.push(list[i]); }
812
+ });
790
813
  // update header count index
791
814
  updateHeaderSortCount(this, c.sortList);
792
815
  // set css for headers
@@ -794,6 +817,9 @@
794
817
  // sort the table and append it to the dom
795
818
  multisort(this, c.sortList);
796
819
  appendToTable(this, init);
820
+ if (typeof callback === "function") {
821
+ callback(this);
822
+ }
797
823
  })
798
824
  .bind("appendCache", function(e, init) {
799
825
  appendToTable(this, init);
@@ -819,7 +845,7 @@
819
845
  applyWidget(this, true);
820
846
  // if user has supplied a sort list to constructor.
821
847
  if (c.sortList.length > 0) {
822
- $this.trigger("sorton", [c.sortList, !c.initWidgets]);
848
+ $this.trigger("sorton", [c.sortList, {}, !c.initWidgets]);
823
849
  } else if (c.initWidgets) {
824
850
  // apply widget format
825
851
  applyWidget(this);
@@ -886,7 +912,7 @@
886
912
  };
887
913
  this.isDigit = function(s) {
888
914
  // replace all unwanted chars and match.
889
- return (/^[\-+(]?\d*[)]?$/).test(s.replace(/[,.'\s]/g, ''));
915
+ return (/^[\-+(]?\d+[)]?$/).test(s.replace(/[,.'\s]/g, ''));
890
916
  };
891
917
 
892
918
  // regex used in natural sort
@@ -1,4 +1,4 @@
1
- /*! tableSorter 2.3 widgets - updated 6/5/2012
1
+ /*! tableSorter 2.3 widgets - updated 6/21/2012
2
2
  *
3
3
  * jQuery UI Theme
4
4
  * Column Styles
@@ -178,10 +178,11 @@ $.tablesorter.addWidget({
178
178
  $.tablesorter.addWidget({
179
179
  id: "filter",
180
180
  format: function(table) {
181
- if (!$(table).hasClass('hasFilters')) {
181
+ if (table.config.parsers && !$(table).hasClass('hasFilters')) {
182
182
  var i, j, k, l, cv, v, val, r, ff, t, x, xi, cr,
183
- sel, $tb, $tr, $td, reg2,
183
+ sel, $tb, $th, $tr, $td, reg2,
184
184
  c = table.config,
185
+ $ths = $(c.headerList),
185
186
  wo = c.widgetOptions,
186
187
  css = wo.filter_cssFilter || 'tablesorter-filter',
187
188
  $t = $(table).addClass('hasFilters'),
@@ -203,11 +204,11 @@ $.tablesorter.addWidget({
203
204
  l = $tr.length;
204
205
  // loop through the rows
205
206
  for (j = 0; j < l; j++) {
206
- // skip child rows
207
- if (reg1.test($tr[j].className)) { continue; }
208
207
  if (cv === '') {
209
208
  $tr[j].style.display = '';
210
209
  } else {
210
+ // skip child rows
211
+ if (reg1.test($tr[j].className)) { continue; }
211
212
  r = true;
212
213
  cr = $tr.eq(j).nextUntil('tr:not(.' + c.cssChildRow + ')');
213
214
  // so, if "table.config.widgetOptions.filter_childRows" is true and there is
@@ -215,6 +216,7 @@ $.tablesorter.addWidget({
215
216
  // checked here so the option can be changed dynamically
216
217
  t = (cr.length && (wo && wo.hasOwnProperty('filter_childRows') &&
217
218
  typeof wo.filter_childRows !== 'undefined' ? wo.filter_childRows : true)) ? cr.text() : '';
219
+ t = wo.filter_ignoreCase ? t.toLocaleLowerCase() : t;
218
220
  $td = $tr.eq(j).children('td');
219
221
  for (i = 0; i < cols; i++) {
220
222
  x = $.trim($td.eq(i).text());
@@ -245,18 +247,14 @@ $.tablesorter.addWidget({
245
247
  }
246
248
  // Look for quotes to get an exact match
247
249
  } else if (/[\"|\']$/.test(val) && xi === val.replace(/(\"|\')/g,'')) {
248
- r = (r) ? true : false;
250
+ ff = true;
249
251
  // Look for wild card: ? = single, or * = multiple
250
252
  } else if (/[\?|\*]/.test(val)) {
251
253
  ff = new RegExp( val.replace(/\?/g, '\\S{1}').replace(/\*/g, '\\S*') ).test(xi);
252
254
  // Look for match, and add child row data for matching
253
255
  } else {
254
256
  x = (xi + t).indexOf(val);
255
- if ( (!wo.filter_startsWith && x >= 0) || (wo.filter_startsWith && x === 0) ) {
256
- r = (r) ? true : false;
257
- } else {
258
- r = false;
259
- }
257
+ ff = ( (!wo.filter_startsWith && x >= 0) || (wo.filter_startsWith && x === 0) );
260
258
  }
261
259
  r = (ff) ? (r ? true : false) : false;
262
260
  }
@@ -272,17 +270,19 @@ $.tablesorter.addWidget({
272
270
  }
273
271
  $t.trigger('applyWidgets'); // make sure zebra widget is applied
274
272
  },
275
- buildSelect = function(i){
273
+ buildSelect = function(i, updating){
276
274
  var o, arry = [];
277
275
  i = parseInt(i, 10);
278
- o = '<option value="">' + ($(c.headerList[i]).attr('data-placeholder') || '') + '</option>';
276
+ o = '<option value="">' + ($ths.filter('[data-column="' + i + '"]:last').attr('data-placeholder') || '') + '</option>';
279
277
  for (k = 0; k < b.length; k++ ) {
280
278
  l = c.cache[k].row.length;
281
279
  // loop through the rows
282
280
  for (j = 0; j < l; j++) {
283
281
  // get non-normalized cell content
284
282
  t = c.cache[k].row[j][0].cells[i];
285
- arry.push( c.supportsTextContent ? t.textContent : $(t).text() );
283
+ if (t) {
284
+ arry.push( c.supportsTextContent ? t.textContent : $(t).text() );
285
+ }
286
286
  }
287
287
  }
288
288
  // get unique elements and sort the list
@@ -291,31 +291,44 @@ $.tablesorter.addWidget({
291
291
  for (k = 0; k < arry.length; k++) {
292
292
  o += '<option value="' + arry[k] + '">' + arry[k] + '</option>';
293
293
  }
294
- $t.find('thead').find('select.' + css + '[data-col="' + i + '"]').append(o);
294
+ $t.find('thead').find('select.' + css + '[data-column="' + i + '"]')[ updating ? 'html' : 'append' ](o);
295
+ },
296
+ buildDefault = function(updating){
297
+ // build default select dropdown
298
+ for (i = 0; i < cols; i++) {
299
+ t = $ths.filter('[data-column="' + i + '"]:last');
300
+ // look for the filter-select class, but don't build it twice.
301
+ if (t.hasClass('filter-select') && !t.hasClass('filter-false') && !(wo.filter_functions && wo.filter_functions[i] === true)){
302
+ buildSelect(i, updating);
303
+ }
304
+ }
295
305
  };
296
306
  if (c.debug) {
297
307
  time = new Date();
298
308
  }
309
+ wo.filter_ignoreCase = wo.filter_ignoreCase !== false; // set default filter_ignoreCase to true
299
310
  for (i=0; i < cols; i++){
300
- sel = (wo.filter_functions && wo.filter_functions[i] && typeof wo.filter_functions[i] !== 'function') || $(c.headerList[i]).hasClass('filter-select');
311
+ $th = $ths.filter('[data-column="' + i + '"]:last'); // assuming last cell of a column is the main column
312
+ sel = (wo.filter_functions && wo.filter_functions[i] && typeof wo.filter_functions[i] !== 'function') || $th.hasClass('filter-select');
301
313
  fr += '<td>';
302
314
  if (sel){
303
- fr += '<select data-col="' + i + '" class="' + css;
315
+ fr += '<select data-column="' + i + '" class="' + css;
304
316
  } else {
305
- fr += '<input type="search" placeholder="' + ($(c.headerList[i]).attr('data-placeholder') || "") + '" data-col="' + i + '" class="' + css;
317
+ fr += '<input type="search" placeholder="' + ($th.attr('data-placeholder') || "") + '" data-column="' + i + '" class="' + css;
306
318
  }
307
319
  // use header option - headers: { 1: { filter: false } } OR add class="filter-false"
308
320
  if ($.tablesorter.getData) {
309
321
  // get data from jQuery data, metadata, headers option or header class name
310
- fr += $.tablesorter.getData(c.headerList[i], c.headers[i], 'filter') === 'false' ? ' disabled" disabled' : '"';
322
+ fr += $.tablesorter.getData($th[0], c.headers[i], 'filter') === 'false' ? ' disabled" disabled' : '"';
311
323
  } else {
312
324
  // only class names and header options - keep this for compatibility with tablesorter v2.0.5
313
- fr += ((c.headers[i] && c.headers[i].hasOwnProperty('filter') && c.headers[i].filter === false) || $(c.headerList[i]).hasClass('filter-false') ) ? ' disabled" disabled' : '"';
325
+ fr += ((c.headers[i] && c.headers[i].hasOwnProperty('filter') && c.headers[i].filter === false) || $th.hasClass('filter-false') ) ? ' disabled" disabled' : '"';
314
326
  }
315
327
  fr += (sel ? '></select>' : '>') + '</td>';
316
328
  }
317
329
  $t
318
330
  .bind('addRows updateCell update appendCache', function(){
331
+ buildDefault(true);
319
332
  findRows();
320
333
  })
321
334
  .find('thead').eq(0).append(fr += '</tr>')
@@ -336,7 +349,7 @@ $.tablesorter.addWidget({
336
349
  if (wo.filter_functions) {
337
350
  // i = column # (string)
338
351
  for (i in wo.filter_functions) {
339
- t = $(c.headerList[i]);
352
+ t = $ths.filter('[data-column="' + i + '"]:last');
340
353
  fr = '';
341
354
  if (typeof i === 'string' && wo.filter_functions[i] === true && !t.hasClass('filter-false')) {
342
355
  buildSelect(i);
@@ -348,18 +361,11 @@ $.tablesorter.addWidget({
348
361
  fr += '<option>' + j + '</option>';
349
362
  }
350
363
  }
351
- $t.find('thead').find('select.' + css + '[data-col="' + i + '"]').append(fr);
364
+ $t.find('thead').find('select.' + css + '[data-column="' + i + '"]').append(fr);
352
365
  }
353
366
  }
354
367
  }
355
- // build default select dropdown
356
- for (i = 0; i < c.headerList.length; i++) {
357
- t = $(c.headerList[i]);
358
- // look for the filter-select class, but don't build it twice.
359
- if (t.hasClass('filter-select') && !t.hasClass('filter-false') && !(wo.filter_functions && wo.filter_functions[i] === true)){
360
- buildSelect(i);
361
- }
362
- }
368
+ buildDefault();
363
369
 
364
370
  $t.find('select.' + css).bind('change', function(){
365
371
  findRows();
@@ -1,9 +1,8 @@
1
1
  /* Blue Theme */
2
2
  table.tablesorter {
3
- font-family: arial;
3
+ font: 11px/18px Arial, Sans-serif;
4
4
  background-color: #cdcdcd;
5
5
  margin: 10px 0 15px;
6
- font-size: 11px;
7
6
  width: 100%;
8
7
  text-align: left;
9
8
  border-spacing: 0;
@@ -11,13 +10,14 @@ table.tablesorter {
11
10
  table.tablesorter,
12
11
  table.tablesorter th,
13
12
  table.tablesorter td {
14
- background-color: #e6eeee;
15
13
  border: #cdcdcd 1px solid;
16
14
  }
17
15
 
18
16
  table.tablesorter th {
17
+ background-color: #99bfe6;
18
+ color: #000;
19
19
  border-collapse: collapse;
20
- font-size: 12px;
20
+ font: 12px/18px Arial, Sans-serif;
21
21
  padding: 4px;
22
22
  }
23
23
  table.tablesorter .header,
@@ -41,7 +41,7 @@ table.tablesorter tbody td {
41
41
  }
42
42
  table.tablesorter th.headerSortUp,
43
43
  table.tablesorter th.tablesorter-headerSortUp {
44
- background-color: #8dbdd8;
44
+ background-color: #9fbfdf;
45
45
  /* black asc arrow */
46
46
  background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjB+gC+jP2ptn0WskLQA7);
47
47
  /* white asc arrow */
@@ -51,7 +51,7 @@ table.tablesorter th.tablesorter-headerSortUp {
51
51
  }
52
52
  table.tablesorter th.headerSortDown,
53
53
  table.tablesorter th.tablesorter-headerSortDown {
54
- background-color: #8dbdd8;
54
+ background-color: #8cb3d9;
55
55
  /* black desc arrow */
56
56
  background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjI8Bya2wnINUMopZAQA7);
57
57
  /* white desc arrow */
@@ -66,32 +66,44 @@ table.tablesorter .tablesorter-hidden {
66
66
 
67
67
  /* Zebra Widget - row alternating colors */
68
68
  table.tablesorter tr.odd td {
69
- background-color: #f0f0ff;
69
+ background-color: #ebf2fa;
70
70
  }
71
71
  table.tablesorter tr.even td {
72
72
  background-color: #fff;
73
73
  }
74
74
 
75
75
  /* Column Widget - column sort colors */
76
- table.tablesorter td.primary, table.tablesorter tr.odd td.primary {
77
- background-color: #c0c0ff;
76
+ .tablesorter td.primary,
77
+ .tablesorter tr.odd td.primary {
78
+ background-color: #99b3e6;
78
79
  }
79
- table.tablesorter tr.even td.primary {
80
- background-color: #e8e8ff;
80
+ .tablesorter tr.even td.primary {
81
+ background-color: #c2d1f0;
81
82
  }
82
83
 
83
- table.tablesorter td.secondary, table.tablesorter tr.odd td.secondary {
84
- background-color: #d6d6ff;
84
+ .tablesorter td.secondary,
85
+ .tablesorter tr.odd td.secondary {
86
+ background-color: #c2d1f0;
85
87
  }
86
- table.tablesorter tr.even td.secondary {
87
- background-color: #e8e8ff;
88
+ .tablesorter tr.even td.secondary {
89
+ background-color: #d6e0f5;
88
90
  }
89
91
 
90
- table.tablesorter td.tertiary, table.tablesorter tr.odd td.tertiary {
91
- background-color: #e5e5ff;
92
+ .tablesorter td.tertiary,
93
+ .tablesorter tr.odd td.tertiary {
94
+ background-color: #d6e0f5;
92
95
  }
93
- table.tablesorter tr.even td.tertiary {
94
- background-color: #f8f8ff;
96
+ .tablesorter tr.even td.tertiary {
97
+ background-color: #ebf0fa;
98
+ }
99
+
100
+ /* hovered row colors */
101
+ table.tablesorter tbody tr:hover td,
102
+ table.tablesorter tbody tr.even:hover td {
103
+ background: #d9d9d9;
104
+ }
105
+ table.tablesorter tbody tr.odd:hover td {
106
+ background: #bfbfbf;
95
107
  }
96
108
 
97
109
  /* filter widget */
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.3
4
+ version: 1.0.4
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-20 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -68,18 +68,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  - - ! '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
- segments:
72
- - 0
73
- hash: -1326086202805563987
74
71
  required_rubygems_version: !ruby/object:Gem::Requirement
75
72
  none: false
76
73
  requirements:
77
74
  - - ! '>='
78
75
  - !ruby/object:Gem::Version
79
76
  version: '0'
80
- segments:
81
- - 0
82
- hash: -1326086202805563987
83
77
  requirements: []
84
78
  rubyforge_project:
85
79
  rubygems_version: 1.8.23