jquery-tablesorter 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -11,8 +11,7 @@ Any issue associate with the js/css files, please report to [Mottie's fork].
11
11
  NOTICE:
12
12
  ---
13
13
 
14
- v0.0.5 users, from v1.0.0, the tablesorter's version will change
15
- to [Mottie's fork] :smile:.
14
+ v0.0.5 users, from v1.0.0, this gem will use [Mottie's fork] :smile:.
16
15
 
17
16
  Install
18
17
  ---
@@ -36,22 +35,24 @@ Usage
36
35
  require jquery-tablesorter
37
36
  ```
38
37
 
39
- this will require `jquery.metadata`, `jquery.tablesorter`,
40
- `jquery.tablesorter.widgets`
38
+ this will require all files.
41
39
 
42
40
  Or you can include single file with:
43
41
 
44
42
  ```
45
- require jquery-tablesorter/jquery.metadata
46
- require jquery-tablesorter/jquery.tablesorter
47
- require jquery-tablesorter/jquery.tablesorter.widgets
43
+ //= require jquery-tablesorter/jquery.metadata
44
+ //= require jquery-tablesorter/jquery.tablesorter
45
+ //= require jquery-tablesorter/jquery.tablesorter.widgets
46
+ //= require jquery-tablesorter/addons/jquery.tablesorter.pager
48
47
  ```
49
48
 
50
49
 
51
50
  ### In your `application.css`
52
51
 
53
52
  ```
54
- require jquery-tablesorter/<theme name>
53
+ /*
54
+ * = require jquery-tablesorter/<theme name>
55
+ */
55
56
  ```
56
57
 
57
58
  Avaliable theme names:
@@ -59,6 +60,7 @@ Avaliable theme names:
59
60
  * blue
60
61
  * ui
61
62
 
63
+
62
64
  ### In CoffeeScript file:
63
65
 
64
66
  ```
@@ -1,3 +1,3 @@
1
1
  module JqueryTablesorter
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -24,5 +24,16 @@ namespace :jquery_tablesorter do
24
24
  'vendor/assets/stylesheets/jquery-tablesorter/ui',
25
25
  :verbose => true
26
26
 
27
+ # addons
28
+ FileUtils.cp 'tablesorter/addons/pager/jquery.tablesorter.pager.css',
29
+ 'vendor/assets/stylesheets/jquery-tablesorter/addons/',
30
+ :verbose => true
31
+ FileUtils.cp 'tablesorter/addons/pager/jquery.tablesorter.pager.js',
32
+ 'vendor/assets/javascripts/jquery-tablesorter/addons/',
33
+ :verbose => true
34
+ FileUtils.cp_r 'tablesorter/addons/pager/icons',
35
+ 'vendor/assets/images/jquery-tablesorter/addons/icons',
36
+ :verbose => true
37
+
27
38
  end
28
39
  end
@@ -0,0 +1,420 @@
1
+ /*!
2
+ * tablesorter pager plugin
3
+ * updated 5/28/2012
4
+ */
5
+ ;(function($) {
6
+ $.extend({tablesorterPager: new function() {
7
+
8
+ this.defaults = {
9
+ // target the pager markup
10
+ container: null,
11
+
12
+ // use this format: "http:/mydatabase.com?page={page}&size={size}"
13
+ // where {page} is replaced by the page number and {size} is replaced by the number of records to show
14
+ ajaxUrl: null,
15
+
16
+ // process ajax so that the following information is returned:
17
+ // [ total_rows (number), rows (array of arrays), headers (array; optional) ]
18
+ // example:
19
+ // [
20
+ // 100, // total rows
21
+ // [
22
+ // [ "row1cell1", "row1cell2", ... "row1cellN" ],
23
+ // [ "row2cell1", "row2cell2", ... "row2cellN" ],
24
+ // ...
25
+ // [ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
26
+ // ],
27
+ // [ "header1", "header2", ... "headerN" ] // optional
28
+ // ]
29
+ ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
30
+
31
+ // output default: '{page}/{totalPages}'
32
+ output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
33
+
34
+ // apply disabled classname to the pager arrows when the rows at either extreme is visible
35
+ updateArrows: true,
36
+
37
+ // starting page of the pager (zero based index)
38
+ page: 0,
39
+
40
+ // Number of visible rows
41
+ size: 10,
42
+
43
+ // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
44
+ // table row set to a height to compensate; default is false
45
+ fixedHeight: false,
46
+
47
+ // remove rows from the table to speed up the sort of large tables.
48
+ // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
49
+ removeRows: true, // removing rows in larger tables speeds up the sort
50
+
51
+ // css class names of pager arrows
52
+ cssNext: '.next', // next page arrow
53
+ cssPrev: '.prev', // previous page arrow
54
+ cssFirst: '.first', // first page arrow
55
+ cssLast: '.last', // last page arrow
56
+ cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
57
+ cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
58
+
59
+ // class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
60
+ cssDisabled: 'disabled', // Note there is no period "." in front of this class name
61
+
62
+ // stuff not set by the user
63
+ totalRows: 0,
64
+ totalPages: 0
65
+
66
+ };
67
+
68
+ var $this = this,
69
+
70
+ // hide arrows at extremes
71
+ pagerArrows = function(c, disable) {
72
+ var a = 'addClass', r = 'removeClass',
73
+ d = c.cssDisabled, dis = !!disable;
74
+ if (c.updateArrows) {
75
+ c.container[(c.totalRows < c.size) ? a : r](d);
76
+ $(c.cssFirst + ',' + c.cssPrev, c.container)[(dis || c.page === 0) ? a : r](d);
77
+ $(c.cssNext + ',' + c.cssLast, c.container)[(dis || c.page === c.totalPages - 1) ? a : r](d);
78
+ }
79
+ },
80
+
81
+ updatePageDisplay = function(table, c) {
82
+ if (c.totalPages > 0) {
83
+ c.startRow = c.size * (c.page) + 1;
84
+ c.endRow = Math.min(c.totalRows, c.size * (c.page+1));
85
+ var out = $(c.cssPageDisplay, c.container),
86
+ // form the output string
87
+ s = c.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi, function(m){
88
+ return {
89
+ '{page}' : c.page + 1,
90
+ '{totalPages}' : c.totalPages,
91
+ '{startRow}' : c.startRow,
92
+ '{endRow}' : c.endRow,
93
+ '{totalRows}' : c.totalRows
94
+ }[m];
95
+ });
96
+ if (out[0]) {
97
+ out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s);
98
+ }
99
+ }
100
+ pagerArrows(c);
101
+ $(table).trigger('pagerComplete', c);
102
+ },
103
+
104
+ fixHeight = function(table, c) {
105
+ var d, h, $b = $(table.tBodies[0]);
106
+ if (c.fixedHeight) {
107
+ $b.find('tr.pagerSavedHeightSpacer').remove();
108
+ h = $.data(table, 'pagerSavedHeight');
109
+ if (h) {
110
+ d = h - $b.height();
111
+ if (d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.find('tr:visible').length < c.size) {
112
+ $b.append('<tr class="pagerSavedHeightSpacer remove-me" style="height:' + d + 'px;"></tr>');
113
+ }
114
+ }
115
+ }
116
+ },
117
+
118
+ changeHeight = function(table, c) {
119
+ var $b = $(table.tBodies[0]);
120
+ $b.find('tr.pagerSavedHeightSpacer').remove();
121
+ $.data(table, 'pagerSavedHeight', $b.height());
122
+ fixHeight(table, c);
123
+ $.data(table, 'pagerLastSize', c.size);
124
+ },
125
+
126
+ hideRows = function(table, c){
127
+ var i, rows = $('tr:not(.' + table.config.cssChildRow + ')', table.tBodies),
128
+ l = rows.length,
129
+ s = (c.page * c.size),
130
+ e = (s + c.size);
131
+ if (e > l) { e = l; }
132
+ for (i = 0; i < l; i++){
133
+ rows[i].style.display = (i >= s && i < e) ? '' : 'none';
134
+ }
135
+ },
136
+
137
+ hideRowsSetup = function(table, c){
138
+ c.size = parseInt($(c.cssPageSize, c.container).val(), 10) || c.size;
139
+ $.data(table, 'pagerLastSize', c.size);
140
+ pagerArrows(c);
141
+ if (!c.removeRows) {
142
+ hideRows(table, c);
143
+ $(table).bind('sortEnd.pager', function(){
144
+ hideRows(table, c);
145
+ });
146
+ }
147
+ },
148
+
149
+ renderAjax = function(data, table, c, exception){
150
+ // process data
151
+ if (typeof(c.ajaxProcessing) === "function") {
152
+ // ajaxProcessing result: [ total, rows, headers ]
153
+ var i, j, k, hsh, $f, $sh, $t = $(table), $b = $(table.tBodies).filter(':not(.' + table.config.cssInfoBlock + ')'),
154
+ hl = $t.find('thead th').length, tds = '',
155
+ err = '<tr class="remove-me"><td style="text-align: center;" colspan="' + hl + '">' +
156
+ (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '</td></tr>',
157
+ result = c.ajaxProcessing(data) || [ 0, [] ],
158
+ d = result[1] || [], l = d.length, th = result[2];
159
+ if (l > 0) {
160
+ for ( i=0; i < l; i++ ) {
161
+ tds += '<tr>';
162
+ for (j=0; j < d[i].length; j++) {
163
+ // build tbody cells
164
+ tds += '<td>' + d[i][j] + '</td>';
165
+ }
166
+ tds += '</tr>';
167
+ }
168
+ }
169
+ // only add new header text if the length matches
170
+ if (th && th.length === hl) {
171
+ hsh = $t.hasClass('hasStickyHeaders');
172
+ $sh = $t.find('.' + ((c.widgetOptions && c.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader'));
173
+ $f = $t.find('tfoot tr:first').children();
174
+ $t.find('thead tr.tablesorter-header th').each(function(j){
175
+ var $t = $(this),
176
+ // add new test within the first span it finds, or just in the header
177
+ tar = ($t.find('span').length) ? $t.find('span:first') : $t;
178
+ tar.html(th[j]);
179
+ $f.eq(j).html(th[j]);
180
+ // update sticky headers
181
+ if (hsh && $sh.length){
182
+ tar = $sh.find('th').eq(j);
183
+ tar = (tar.find('span').length) ? tar.find('span:first') : tar;
184
+ tar.html(th[j]);
185
+ }
186
+ });
187
+ }
188
+ if (exception) {
189
+ // add error row to thead instead of tbody, or clicking on the header will result in a parser error
190
+ $t.find('thead').append(err);
191
+ } else {
192
+ $b.html(tds); // add tbody
193
+ }
194
+ c.temp.remove(); // remove loading icon
195
+ $t.trigger('update');
196
+ c.totalRows = result[0] || 0;
197
+ c.totalPages = Math.ceil(c.totalRows / c.size);
198
+ updatePageDisplay(table, c);
199
+ fixHeight(table, c);
200
+ $t.trigger('pagerChange', c);
201
+ }
202
+ },
203
+
204
+ getAjax = function(table, c){
205
+ var $t = $(table),
206
+ url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size);
207
+ if (url !== '') {
208
+ // loading icon
209
+ c.temp = $('<div/>', {
210
+ id : 'tablesorterPagerLoading',
211
+ width : $t.outerWidth(true),
212
+ height: $t.outerHeight(true)
213
+ });
214
+ $t.before(c.temp);
215
+ $(document).ajaxError(function(e, xhr, settings, exception) {
216
+ renderAjax(null, table, c, exception);
217
+ });
218
+ $.getJSON(url, function(data) {
219
+ renderAjax(data, table, c);
220
+ });
221
+ }
222
+ },
223
+
224
+ renderTable = function(table, rows, c) {
225
+ var i, j, o,
226
+ f = document.createDocumentFragment(),
227
+ l = rows.length,
228
+ s = (c.page * c.size),
229
+ e = (s + c.size);
230
+ if (l < 1) { return; } // empty table, abort!
231
+ $(table).trigger('pagerChange', c);
232
+ if (!c.removeRows) {
233
+ hideRows(table, c);
234
+ } else {
235
+ if (e > rows.length ) {
236
+ e = rows.length;
237
+ }
238
+ $(table.tBodies[0]).addClass('tablesorter-hidden');
239
+ $.tablesorter.clearTableBody(table);
240
+ for (i = s; i < e; i++) {
241
+ o = rows[i];
242
+ l = o.length;
243
+ for (j = 0; j < l; j++) {
244
+ f.appendChild(o[j]);
245
+ }
246
+ }
247
+ table.tBodies[0].appendChild(f);
248
+ $(table.tBodies[0]).removeClass('tablesorter-hidden');
249
+ }
250
+ if ( c.page >= c.totalPages ) {
251
+ moveToLastPage(table, c);
252
+ }
253
+ updatePageDisplay(table, c);
254
+ if (!c.isDisabled) { fixHeight(table, c); }
255
+ $(table).trigger('applyWidgets');
256
+ },
257
+
258
+ showAllRows = function(table, c){
259
+ if (c.ajax) {
260
+ pagerArrows(c, true);
261
+ } else {
262
+ c.isDisabled = true;
263
+ $.data(table, 'pagerLastPage', c.page);
264
+ $.data(table, 'pagerLastSize', c.size);
265
+ c.page = 0;
266
+ c.size = c.totalRows;
267
+ c.totalPages = 1;
268
+ $('tr.pagerSavedHeightSpacer', table.tBodies[0]).remove();
269
+ renderTable(table, table.config.rowsCopy, c);
270
+ }
271
+ // disable size selector
272
+ $(c.cssPageSize, c.container).addClass(c.cssDisabled)[0].disabled = true;
273
+ },
274
+
275
+ moveToPage = function(table, c) {
276
+ if (c.isDisabled) { return; }
277
+ if (c.page < 0 || c.page > (c.totalPages-1)) {
278
+ c.page = 0;
279
+ }
280
+ $.data(table, 'pagerLastPage', c.page);
281
+ if (c.ajax) {
282
+ getAjax(table, c);
283
+ } else {
284
+ renderTable(table, table.config.rowsCopy, c);
285
+ }
286
+ },
287
+
288
+ setPageSize = function(table, size, c) {
289
+ c.size = size;
290
+ $.data(table, 'pagerLastPage', c.page);
291
+ $.data(table, 'pagerLastSize', c.size);
292
+ c.totalPages = Math.ceil(c.totalRows / c.size);
293
+ moveToPage(table, c);
294
+ },
295
+
296
+ moveToFirstPage = function(table, c) {
297
+ c.page = 0;
298
+ moveToPage(table, c);
299
+ },
300
+
301
+ moveToLastPage = function(table, c) {
302
+ c.page = (c.totalPages-1);
303
+ moveToPage(table, c);
304
+ },
305
+
306
+ moveToNextPage = function(table, c) {
307
+ c.page++;
308
+ if (c.page >= (c.totalPages-1)) {
309
+ c.page = (c.totalPages-1);
310
+ }
311
+ moveToPage(table, c);
312
+ },
313
+
314
+ moveToPrevPage = function(table, c) {
315
+ c.page--;
316
+ if (c.page <= 0) {
317
+ c.page = 0;
318
+ }
319
+ moveToPage(table, c);
320
+ },
321
+
322
+ destroyPager = function(table, c){
323
+ showAllRows(table, c);
324
+ c.container.hide(); // hide pager
325
+ table.config.appender = null; // remove pager appender function
326
+ $(table).unbind('destroy.pager sortEnd.pager enable.pager disable.pager');
327
+ },
328
+
329
+ enablePager = function(table, c, triggered){
330
+ var p = $(c.cssPageSize, c.container).removeClass(c.cssDisabled).removeAttr('disabled');
331
+ c.isDisabled = false;
332
+ c.page = $.data(table, 'pagerLastPage') || c.page || 0;
333
+ c.size = $.data(table, 'pagerLastSize') || parseInt(p.val(), 10) || c.size;
334
+ c.totalPages = Math.ceil(c.totalRows / c.size);
335
+ if (triggered) {
336
+ $(table).trigger('update');
337
+ setPageSize(table, c.size, c);
338
+ hideRowsSetup(table, c);
339
+ fixHeight(table, c);
340
+ }
341
+ };
342
+
343
+ $this.appender = function(table, rows) {
344
+ var c = table.config.pager;
345
+ if (!c.ajax) {
346
+ table.config.rowsCopy = rows;
347
+ c.totalRows = rows.length;
348
+ c.size = $.data(table, 'pagerLastSize') || c.size;
349
+ c.totalPages = Math.ceil(c.totalRows / c.size);
350
+ renderTable(table, rows, c);
351
+ }
352
+ };
353
+
354
+ $this.construct = function(settings) {
355
+ return this.each(function() {
356
+ var config = this.config,
357
+ c = config.pager = $.extend({}, $.tablesorterPager.defaults, settings),
358
+ table = this,
359
+ $t = $(table),
360
+ pager = $(c.container).show(); // added in case the pager is reinitialized after being destroyed.
361
+ config.appender = $this.appender;
362
+ enablePager(table, c, false);
363
+ if (typeof(c.ajaxUrl) === 'string') {
364
+ // ajax pager; interact with database
365
+ c.ajax = true;
366
+ getAjax(table, c);
367
+ } else {
368
+ c.ajax = false;
369
+ // Regular pager; all rows stored in memory
370
+ $(this).trigger("appendCache", true);
371
+ hideRowsSetup(table, c);
372
+ }
373
+
374
+ $(c.cssFirst,pager).unbind('click.pager').bind('click.pager', function() {
375
+ if (!$(this).hasClass(c.cssDisabled)) { moveToFirstPage(table, c); }
376
+ return false;
377
+ });
378
+ $(c.cssNext,pager).unbind('click.pager').bind('click.pager', function() {
379
+ if (!$(this).hasClass(c.cssDisabled)) { moveToNextPage(table, c); }
380
+ return false;
381
+ });
382
+ $(c.cssPrev,pager).unbind('click.pager').bind('click.pager', function() {
383
+ if (!$(this).hasClass(c.cssDisabled)) { moveToPrevPage(table, c); }
384
+ return false;
385
+ });
386
+ $(c.cssLast,pager).unbind('click.pager').bind('click.pager', function() {
387
+ if (!$(this).hasClass(c.cssDisabled)) { moveToLastPage(table, c); }
388
+ return false;
389
+ });
390
+ $(c.cssPageSize,pager).unbind('change.pager').bind('change.pager', function() {
391
+ $(c.cssPageSize,pager).val( $(this).val() ); // in case there are more than one pagers
392
+ if (!$(this).hasClass(c.cssDisabled)) {
393
+ setPageSize(table, parseInt($(this).val(), 10), c);
394
+ changeHeight(table, c);
395
+ }
396
+ return false;
397
+ });
398
+
399
+ $t
400
+ .unbind('disable.pager enable.pager destroy.pager')
401
+ .bind('disable.pager', function(){
402
+ showAllRows(table, c);
403
+ })
404
+ .bind('enable.pager', function(){
405
+ enablePager(table, c, true);
406
+ })
407
+ .bind('destroy.pager', function(){
408
+ destroyPager(table, c);
409
+ });
410
+ });
411
+ };
412
+
413
+ }
414
+ });
415
+ // extend plugin scope
416
+ $.fn.extend({
417
+ tablesorterPager: $.tablesorterPager.construct
418
+ });
419
+
420
+ })(jQuery);
@@ -0,0 +1,41 @@
1
+ /* pager wrapper, div */
2
+ .pager {
3
+ padding: 5px;
4
+ }
5
+ /* pager wrapper, in thead/tfoot */
6
+ td.pager {
7
+ background-color: #e6eeee;
8
+ }
9
+ /* pager navigation arrows */
10
+ .pager img {
11
+ vertical-align: middle;
12
+ margin-right: 2px;
13
+ cursor: pointer;
14
+ }
15
+ /* pager output text */
16
+ .pager .pagedisplay {
17
+ font-size: 11px;
18
+ padding: 0 5px 0 5px;
19
+ width: 50px;
20
+ text-align: center;
21
+ }
22
+
23
+ /*** loading ajax indeterminate progress indicator ***/
24
+ #tablesorterPagerLoading {
25
+ background: rgba(255,255,255,0.8) url(/assets/jquery-tablesorter/addons/icons/loading.gif) center center no-repeat;
26
+ position: absolute;
27
+ z-index: 1000;
28
+ }
29
+
30
+ /*** css used when "updateArrows" option is true ***/
31
+ /* the pager itself gets a disabled class when the number of rows is less than the size */
32
+ .pager.disabled {
33
+ display: none;
34
+ }
35
+ /* hide or fade out pager arrows when the first or last row is visible */
36
+ .pager img.disabled {
37
+ /* visibility: hidden */
38
+ opacity: 0.5;
39
+ filter: alpha(opacity=50);
40
+ cursor: default;
41
+ }
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.2
4
+ version: 1.0.3
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-06 00:00:00.000000000 Z
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -34,10 +34,17 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - vendor/assets/images/jquery-tablesorter/addons/icons/first.png
38
+ - vendor/assets/images/jquery-tablesorter/addons/icons/last.png
39
+ - vendor/assets/images/jquery-tablesorter/addons/icons/loading.gif
40
+ - vendor/assets/images/jquery-tablesorter/addons/icons/next.png
41
+ - vendor/assets/images/jquery-tablesorter/addons/icons/prev.png
42
+ - vendor/assets/javascripts/jquery-tablesorter/addons/jquery.tablesorter.pager.js
37
43
  - vendor/assets/javascripts/jquery-tablesorter/jquery.metadata.js
38
44
  - vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.js
39
45
  - vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets.js
40
46
  - vendor/assets/javascripts/jquery-tablesorter.js
47
+ - vendor/assets/stylesheets/jquery-tablesorter/addons/jquery.tablesorter.pager.css
41
48
  - vendor/assets/stylesheets/jquery-tablesorter/blue/style.css
42
49
  - vendor/assets/stylesheets/jquery-tablesorter/blue.css
43
50
  - vendor/assets/stylesheets/jquery-tablesorter/ui/style.css
@@ -63,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
70
  version: '0'
64
71
  segments:
65
72
  - 0
66
- hash: 260395834157096892
73
+ hash: -1326086202805563987
67
74
  required_rubygems_version: !ruby/object:Gem::Requirement
68
75
  none: false
69
76
  requirements:
@@ -72,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
79
  version: '0'
73
80
  segments:
74
81
  - 0
75
- hash: 260395834157096892
82
+ hash: -1326086202805563987
76
83
  requirements: []
77
84
  rubyforge_project:
78
85
  rubygems_version: 1.8.23