tidy-table-rails 2.1.0 → 2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0998be53e8b9554aa5697edb54326fc7cbe02d97
4
- data.tar.gz: f5f23d132bdd4a90aed97bca9ecabba1d31f82b5
3
+ metadata.gz: 12e68be6086553aac38ac04b81400fd45dd50b0f
4
+ data.tar.gz: 624b9c768589b6e4435fbb2446ceafb164e27ff8
5
5
  SHA512:
6
- metadata.gz: 9a7001f75ad03469fc2b8cbbe9063362feb09849dd5ca8dfe0abd778fe84a46dfa1048a5538393447faf8bbbf83162c0e41c87b116bf18b0bea4310b7f31f6e5
7
- data.tar.gz: 60d21d3d534e7e1d6c7e5e25445d601a152360ce005d1236916bba4b7325bd33bf649e3b50f5b7e48d1ad4a78f404e978bf8c0baa06fdb480a7d29c3cf15d402
6
+ metadata.gz: 0f68d5c0091a2054bcaef4cc6f8ccdc829f2080016b1478ff3dab8fafa1eef8085df9d2f70d25aef7cba1b333e168c393f753a8014625a55f492a77924bad30c
7
+ data.tar.gz: 0f48caa076085027534bc31cf5fbbf711598e269f7ae2b40034db0fb01ca96ade6863e8efddf676e4ee8ae34d023ababb04a119b9fc7704d3188a4a175fba090
@@ -1,7 +1,7 @@
1
1
  module Tidy
2
2
  module Table
3
3
  module Rails
4
- VERSION = "2.1.0"
4
+ VERSION = "2.2.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Tidy Table
3
- * Generate a sortable HTML table from JSON
3
+ * Create a HTML table from JSON that can be sorted, selected
4
+ * and post-processed using a simple callback.
4
5
  *
5
- * Copyright 2012-2015, Marc S. Brooks (http://mbrooks.info)
6
+ * Copyright 2012-2015, Marc S. Brooks (https://mbrooks.info)
6
7
  * Licensed under the MIT license:
7
8
  * http://www.opensource.org/licenses/mit-license.php
8
9
  *
@@ -11,434 +12,459 @@
11
12
  */
12
13
 
13
14
  if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace('.', '')) < parseInt('1.8.3'.replace('.', '')))) {
14
- throw new Error('Tidy-Table requires jQuery 1.8.3 or greater.');
15
+ throw new Error('Tidy-Table requires jQuery 1.8.3 or greater.');
15
16
  }
16
17
 
17
18
  (function($) {
18
-
19
- /**
20
- * @namespace TidyTable
21
- */
22
- var methods = {
23
-
24
- /**
25
- * Create new instance of Tidy-Table
26
- * @memberof TidyTable
27
- * @method init
28
- * @param {Object} settings
29
- * @param {Object} config
30
- * @returns {Object} jQuery object
31
- */
32
- "init": function(settings, config) {
33
- var $this = $(this),
34
- data = $this.data();
35
-
36
- // default settings
37
- var defaults = {
38
- enableCheckbox: false,
39
- enableMenu: false,
40
- reverseSortDir: false,
41
- responsive: false
42
- };
43
-
44
- if (arguments.length > 1) {
45
- $.extend(defaults, settings);
46
- }
47
- else {
48
- config = settings;
49
- }
50
-
51
- // config defaults
52
- config = $.extend({
53
- sortByPattern: function(col_num, val) {
54
- if ( $.trim(col_num) ) {
55
- return String(val).replace(/$|%|#/g, '');
56
- }
57
- }
58
- }, config);
59
-
60
- if ( $.isEmptyObject(data) ) {
61
- $this.data({
62
- settings: defaults,
63
- config: config
64
- });
65
- }
66
-
67
- // responsive layout?
68
- if (defaults.responsive) {
69
- $this.addClass('tidy_table media');
70
- }
71
-
72
- return $this.TidyTable('_createTable');
73
- },
74
-
75
- /**
76
- * Perform cleanup
77
- * @memberof TidyTable
78
- * @method destroy
79
- */
80
- "destroy": function() {
81
- $(this).removeData();
82
- },
83
-
84
- /**
85
- * Create HTML table elements
86
- * @memberof TidyTable
87
- * @method _createTable
88
- * @param {String} num
89
- * @param {String} order
90
- * @returns {Object} jQuery object
91
- * @private
92
- */
93
- "_createTable": function(num, order) {
94
- var $this = $(this),
95
- data = $this.data();
96
-
97
- // create reusable elements
98
- var table = $('<table></table>')
99
- .addClass('tidy_table');
100
-
101
- // disable IE7/8 text selection
102
- table.mousedown(function() { return false; });
103
- table.mouseover(function() { return false; });
104
-
105
- var thead = $('<thead></thead>'),
106
- tbody = $('<tbody></tbody>'),
107
- titles = null;
108
-
109
- // .. <THEAD>
110
- (function() {
111
- titles = data.config.columnTitles;
112
-
113
- var row = $('<tr></tr>');
114
-
115
- for (var i = 0; i < titles.length; i++) {
116
- var title = titles[i];
117
-
118
- var col = $('<th></th>')
119
- .append(title)
120
- .attr('title', title);
121
- row.append(col);
122
-
123
- var col_class;
124
-
125
- // determine column result ordet
126
- if (!data.settings.reverseSortDir) {
127
- if (order == 'asc' || !order) {
128
- col_class = 'sort_asc';
129
- col.order = 'desc';
130
- }
131
- else {
132
- col_class = 'sort_desc';
133
- col.order = 'asc';
134
- }
135
- }
136
- else {
137
- if (order == 'desc' || !order) {
138
- col_class = 'sort_asc';
139
- col.order = 'asc';
140
- }
141
- else {
142
- col_class = 'sort_desc';
143
- col.order = 'desc';
144
- }
145
- }
146
-
147
- // highlight selected column
148
- if (num == i) {
149
- col.addClass(col_class);
150
- }
151
-
152
- // attach sorting event to each column
153
- col.on('click', {
154
- col_number: i,
155
- sort_order: (num == i) ? col.order : 'asc'
156
- },
157
- function(event) {
158
- $this.TidyTable('_sortByColumn', event.data.col_number, event.data.sort_order);
159
- });
160
- }
161
-
162
- thead.append(row);
163
- })();
164
-
165
- // .. <TBODY>
166
- (function() {
167
- var vals = data.config.columnValues;
168
-
169
- for (var j = 0; j < vals.length; j++) {
170
- var row = $('<tr></tr>');
171
-
172
- for (var k = 0; k < vals[j].length; k++) {
173
- var val = vals[j][k];
174
-
175
- var col = $('<td></td>')
176
- .append(val)
177
- .attr('title', val);
178
- row.append(col);
179
-
180
- // post-process table column HTML object
181
- if (data.config.postProcess && $.isFunction(data.config.postProcess.column)) {
182
- data.config.postProcess.column(col);
183
- }
184
- }
185
-
186
- tbody.append(row);
187
- }
188
-
189
- table.append(thead);
190
- table.append(tbody);
191
-
192
- // append check boxes to beginning each row
193
- if (data.settings && data.settings.enableCheckbox) {
194
- var rows = table.find('tr');
195
-
196
- rows.each(function(index) {
197
- var input = $('<input></input>')
198
- .attr('type', 'checkbox');
199
-
200
- var col;
201
-
202
- // first row is always the header
203
- if (index === 0) {
204
- col = $('<th></th>');
205
-
206
- // attach event to check all boxes
207
- input.on('click', function() {
208
- $this.TidyTable('_toggleSelRows', rows);
209
- });
210
- }
211
- else {
212
- col = $('<td></td>');
213
-
214
- // attach event to each checkbox
215
- input.on('click', {
216
- box_number: index
217
- },
218
- function(event) {
219
- $this.TidyTable('_toggleSelRows', rows, event.data.box_number);
220
- });
221
- }
222
-
223
- col.append(input);
224
-
225
- // insert before first cell
226
- $(this).prepend(col);
227
- });
228
- }
229
- })();
230
-
231
- // post-process table results HTML object
232
- if (data.config.postProcess && $.isFunction(data.config.postProcess.table)) {
233
- data.config.postProcess.table(table);
234
- }
235
-
236
- var block = $this.children('table.tidy_table');
237
-
238
- // if table exists, perform an in-place update of the element
239
- if (block[0]) {
240
- block.replaceWith(table);
241
- }
242
-
243
- // generate table/menu elements
244
- else {
245
- if (data.settings && data.settings.enableMenu) {
246
- $this.append(
247
- $this.TidyTable('_createMenu', table, 'options')
248
- );
249
- }
250
-
251
- $this.append(table);
252
- }
253
-
254
- return table;
255
- },
256
-
257
- /**
258
- * Create HTML select menu element
259
- * @memberof TidyTable
260
- * @method _createMenu
261
- * @param {Object} table jQuery object
262
- * @param {String} name
263
- * @returns {Object} jQuery object
264
- * @private
265
- */
266
- "_createMenu": function(table, name) {
267
- var $this = $(this),
268
- data = $this.data();
269
-
270
- // create reusable elements
271
- var select = $('<select></select>')
272
- .addClass('tidy_table ' + name)
273
- .change(function() {
274
- var elm = $(this);
275
-
276
- var callback = data.config.menuOptions[ elm.val() ][1]['callback'];
277
-
278
- // callback event
279
- if ( $.isFunction(callback) ) {
280
- callback( $this.TidyTable('_getCheckedAsObj', table) );
281
- }
282
-
283
- elm.val(0);
284
- });
285
-
286
- // .. options
287
- $.each(data.config.menuOptions, function(index) {
288
- var option = $('<option>' + data.config.menuOptions[index][0] + '</option>')
289
- .attr('value', index);
290
-
291
- select.append(option);
292
- });
293
-
294
- // post-process select menu HTML object
295
- if (data.config.postProcess && $.isFunction(data.config.postProcess.menu)) {
296
- data.config.postProcess.menu(select);
297
- }
298
-
299
- return select;
300
- },
301
-
302
- /**
303
- * Return selected row values as an array
304
- * @memberof TidyTable
305
- * @method _getCheckedAsObj
306
- * @param {Object} table jQuery object
307
- * @returns {Array}
308
- * @private
309
- */
310
- "_getCheckedAsObj": function(table) {
311
- var rows = table.find('tbody > tr'),
312
- objs = [];
313
-
314
- for (var i = 0; i < rows.length; i++) {
315
- var cols = rows[i].childNodes;
316
-
317
- // if the row checkbox is selected
318
- if (cols[0].firstChild.checked) {
319
- var row = [];
320
-
321
- // simulate an associative array
322
- for (var j = 1; j < cols.length; j++) {
323
- row[j - 1] = cols[j].textContent;
324
- }
325
-
326
- objs.push(row);
327
- }
328
- }
329
-
330
- return objs;
331
- },
332
-
333
- /**
334
- * Select/Deselect (input checkbox and row highlight)
335
- * @memberof TidyTable
336
- * @method _toggleSelRows
337
- * @param {Object} rows jQuery object
338
- * @param {Number} num
339
- * @private
340
- */
341
- "_toggleSelRows": function(rows, num) {
342
- var checked = null;
343
-
344
- rows.each(function(index) {
345
- var row = $(this),
346
- input = row.find(':checkbox').first();
347
-
348
- // update all rows
349
- if (!num) {
350
- if (index === 0) {
351
- checked = (input.is(':checked')) ? true : false;
352
- return;
353
- }
354
-
355
- if (checked) {
356
- row.removeClass('check_off').addClass('check_on');
357
- input.prop('checked', true);
358
- }
359
- else {
360
- row.removeClass('check_on').addClass('check_off');
361
- input.prop('checked', false);
362
- }
363
- }
364
-
365
- // update selected row
366
- else {
367
- if (index === 0) {
368
- return;
369
- }
370
-
371
- if (input.is(':checked')) {
372
- row.removeClass('check_off').addClass('check_on');
373
- input.prop('checked', true);
374
- }
375
- else {
376
- row.removeClass('check_on').addClass('check_off');
377
- input.prop('checked', false);
378
- }
379
- }
380
- });
381
- },
382
-
383
- /**
384
- * Display results ordered by selected column
385
- * @memberof TidyTable
386
- * @method _sortByColumn
387
- * @param {Number} num
388
- * @param {Number} order
389
- * @private
390
- */
391
- "_sortByColumn": function(num, order) {
392
- var $this = $(this),
393
- data = $this.data();
394
-
395
- if ( $.isFunction(data.config.sortByPattern) ) {
396
- var reverse = (order == 'desc') ? -1 : 1;
397
-
398
- // sort JSON object by bucket number
399
- data.config.columnValues.sort(function(a, b) {
400
- var str1 = data.config.sortByPattern(num, a[num]),
401
- str2 = data.config.sortByPattern(num, b[num]);
402
-
403
- if (isNaN(str1)) {
404
- return [reverse * cmpAny(str1, str2)] >
405
- [reverse * cmpAny(str2, str1)] ? -1 : 1;
406
- }
407
- else {
408
- return [reverse * cmpInt(str1, str2)];
409
- }
410
- });
411
- }
412
-
413
- $this.TidyTable('_createTable', num, order);
414
- }
415
- };
416
-
417
- $.fn.TidyTable = function(method) {
418
- if (methods[method]) {
419
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
420
- }
421
- else
422
- if (typeof method === 'object' || !method) {
423
- return methods.init.apply(this, arguments);
424
- }
425
- else {
426
- $.error('Method ' + method + ' does not exist in jQuery.TidyTable');
427
- }
428
- };
429
-
430
- /**
431
- * Generic string comparison functions
432
- * @param {String} a
433
- * @param {String} b
434
- * @returns {Number}
435
- * @protected
436
- */
437
- function cmpAny(a, b) {
438
- return (a > b) ? 1 : (a < b) ? -1 : 0;
439
- }
440
-
441
- function cmpInt(a, b) {
442
- return b - a;
443
- }
19
+ var table = null;
20
+
21
+ /**
22
+ * @namespace TidyTable
23
+ */
24
+ var methods = {
25
+
26
+ /**
27
+ * Create new instance of Tidy-Table
28
+ *
29
+ * @memberof TidyTable
30
+ * @method init
31
+ *
32
+ * @example
33
+ * $('#container').TidyTable(settings, config);
34
+ *
35
+ * @param {Object} settings
36
+ * @param {Object} config
37
+ *
38
+ * @returns {Object} jQuery object
39
+ */
40
+ "init": function(settings, config) {
41
+ var $this = $(this),
42
+ data = $this.data();
43
+
44
+ // Default settings
45
+ var defaults = {
46
+ enableCheckbox: false,
47
+ enableMenu: false,
48
+ reverseSortDir: false,
49
+ responsive: false
50
+ };
51
+
52
+ if (arguments.length > 1) {
53
+ $.extend(defaults, settings);
54
+ }
55
+ else {
56
+ config = settings;
57
+ }
58
+
59
+ // Config defaults
60
+ config = $.extend({
61
+ sortByPattern: function(col_num, val) {
62
+ if ( $.trim(col_num) ) {
63
+ return String(val).replace(/$|%|#/g, '');
64
+ }
65
+ }
66
+ }, config);
67
+
68
+ if ( $.isEmptyObject(data) ) {
69
+ $this.data({
70
+ settings: defaults,
71
+ config: config
72
+ });
73
+ }
74
+
75
+ // Responsive layout?
76
+ if (defaults.responsive) {
77
+ $this.addClass('tidy_table media');
78
+ }
79
+
80
+ return $this.TidyTable('_createTable');
81
+ },
82
+
83
+ /**
84
+ * Perform cleanup
85
+ *
86
+ * @memberof TidyTable
87
+ * @method destroy
88
+ *
89
+ * @example
90
+ * $('#container').TidyTable('destroy');
91
+ */
92
+ "destroy": function() {
93
+ $(this).removeData();
94
+ },
95
+
96
+ /**
97
+ * Create HTML table elements.
98
+ *
99
+ * @memberof TidyTable
100
+ * @method _createTable
101
+ * @private
102
+ *
103
+ * @param {String|undefined} num
104
+ * @param {String|undefined} order
105
+ *
106
+ * @returns {Object} jQuery object
107
+ */
108
+ "_createTable": function(num, order) {
109
+ var $this = $(this),
110
+ data = $this.data();
111
+
112
+ // Create reusable elements.
113
+ table = $('<table></table>')
114
+ .addClass('tidy_table');
115
+
116
+ // Disable IE7/8 text selection.
117
+ table.mousedown(function() { return false; });
118
+ table.mouseover(function() { return false; });
119
+
120
+ var thead = $('<thead></thead>'),
121
+ tbody = $('<tbody></tbody>'),
122
+ titles = null;
123
+
124
+ // .. <THEAD>
125
+ (function() {
126
+ titles = data.config.columnTitles;
127
+
128
+ var row = $('<tr></tr>');
129
+
130
+ for (var i = 0; i < titles.length; i++) {
131
+ var title = titles[i];
132
+
133
+ var col = $('<th></th>')
134
+ .append(title)
135
+ .attr('title', title);
136
+ row.append(col);
137
+
138
+ var col_class;
139
+
140
+ // Determine column result order.
141
+ if (!data.settings.reverseSortDir) {
142
+ if (order == 'asc' || !order) {
143
+ col_class = 'sort_asc';
144
+ col.order = 'desc';
145
+ }
146
+ else {
147
+ col_class = 'sort_desc';
148
+ col.order = 'asc';
149
+ }
150
+ }
151
+ else {
152
+ if (order == 'desc' || !order) {
153
+ col_class = 'sort_asc';
154
+ col.order = 'asc';
155
+ }
156
+ else {
157
+ col_class = 'sort_desc';
158
+ col.order = 'desc';
159
+ }
160
+ }
161
+
162
+ // Highlight selected column.
163
+ if (num == i) {
164
+ col.addClass(col_class);
165
+ }
166
+
167
+ // Attach sorting event to each column.
168
+ col.on('click', {
169
+ col_number: i,
170
+ sort_order: (num == i) ? col.order : 'asc'
171
+ },
172
+ function(event) {
173
+ $this.TidyTable('_sortByColumn', event.data.col_number, event.data.sort_order);
174
+ });
175
+ }
176
+
177
+ thead.append(row);
178
+ })();
179
+
180
+ // .. <TBODY>
181
+ (function() {
182
+ var vals = data.config.columnValues;
183
+
184
+ for (var j = 0; j < vals.length; j++) {
185
+ var row = $('<tr></tr>');
186
+
187
+ for (var k = 0; k < vals[j].length; k++) {
188
+ var val = vals[j][k];
189
+
190
+ var col = $('<td></td>')
191
+ .append(val)
192
+ .attr('title', val);
193
+ row.append(col);
194
+
195
+ // Post-process table column HTML object.
196
+ if (data.config.postProcess && $.isFunction(data.config.postProcess.column)) {
197
+ data.config.postProcess.column(col);
198
+ }
199
+ }
200
+
201
+ tbody.append(row);
202
+ }
203
+
204
+ table.append(thead);
205
+ table.append(tbody);
206
+
207
+ // Append check boxes to beginning each row.
208
+ if (data.settings && data.settings.enableCheckbox) {
209
+ var rows = table.find('tr');
210
+
211
+ rows.each(function(index) {
212
+ var input = $('<input></input>')
213
+ .attr('type', 'checkbox');
214
+
215
+ var col;
216
+
217
+ // First row is always the header.
218
+ if (index === 0) {
219
+ col = $('<th></th>');
220
+
221
+ // Attach event to check all boxes.
222
+ input.on('click', function() {
223
+ $this.TidyTable('_toggleSelRows', rows);
224
+ });
225
+ }
226
+ else {
227
+ col = $('<td></td>');
228
+
229
+ // Attach event to each checkbox.
230
+ input.on('click', {
231
+ box_number: index
232
+ },
233
+ function(event) {
234
+ $this.TidyTable('_toggleSelRows', rows, event.data.box_number);
235
+ });
236
+ }
237
+
238
+ col.append(input);
239
+
240
+ // Insert before first cell.
241
+ $(this).prepend(col);
242
+ });
243
+ }
244
+ })();
245
+
246
+ // Post-process table results HTML object.
247
+ if (data.config.postProcess && $.isFunction(data.config.postProcess.table)) {
248
+ data.config.postProcess.table(table);
249
+ }
250
+
251
+ var block = $this.children('table.tidy_table');
252
+
253
+ // If table exists, perform an in-place update of the element.
254
+ if (block[0]) {
255
+ block.replaceWith(table);
256
+ }
257
+
258
+ // Generate table/menu elements.
259
+ else {
260
+ if (data.settings && data.settings.enableMenu) {
261
+ $this.append(
262
+ $this.TidyTable('_createMenu', 'options')
263
+ );
264
+ }
265
+
266
+ $this.append(table);
267
+ }
268
+
269
+ return table;
270
+ },
271
+
272
+ /**
273
+ * Create HTML select menu element
274
+ *
275
+ * @memberof TidyTable
276
+ * @method _createMenu
277
+ * @private
278
+ *
279
+ * @param {String} name
280
+ *
281
+ * @returns {Object} jQuery object
282
+ */
283
+ "_createMenu": function(name) {
284
+ var $this = $(this),
285
+ data = $this.data();
286
+
287
+ // Create reusable elements.
288
+ var select = $('<select></select>')
289
+ .addClass('tidy_table ' + name)
290
+ .change(function() {
291
+ var elm = $(this);
292
+
293
+ var callback = data.config.menuOptions[ elm.val() ][1]['callback'];
294
+
295
+ // Callback event
296
+ if ( $.isFunction(callback) ) {
297
+ callback( $this.TidyTable('_getCheckedAsObj') );
298
+ }
299
+
300
+ elm.val(0);
301
+ });
302
+
303
+ // .. Options
304
+ $.each(data.config.menuOptions, function(index) {
305
+ var option = $('<option>' + data.config.menuOptions[index][0] + '</option>')
306
+ .attr('value', index);
307
+
308
+ select.append(option);
309
+ });
310
+
311
+ // Post-process select menu HTML object.
312
+ if (data.config.postProcess && $.isFunction(data.config.postProcess.menu)) {
313
+ data.config.postProcess.menu(select);
314
+ }
315
+
316
+ return select;
317
+ },
318
+
319
+ /**
320
+ * Return selected row values as an array.
321
+ *
322
+ * @memberof TidyTable
323
+ * @method _getCheckedAsObj
324
+ * @private
325
+ *
326
+ * @returns {Array}
327
+ */
328
+ "_getCheckedAsObj": function() {
329
+ var $this = $(this),
330
+ rows = $this.find('tbody > tr'),
331
+ objs = [];
332
+
333
+ for (var i = 0; i < rows.length; i++) {
334
+ var cols = rows[i].childNodes;
335
+
336
+ // If the row checkbox is selected.
337
+ if (cols[0].firstChild.checked) {
338
+ var row = [];
339
+
340
+ // Simulate an associative array.
341
+ for (var j = 1; j < cols.length; j++) {
342
+ row[j - 1] = cols[j].textContent;
343
+ }
344
+
345
+ objs.push(row);
346
+ }
347
+ }
348
+
349
+ return objs;
350
+ },
351
+
352
+ /**
353
+ * Select/Deselect (input checkbox and row highlight).
354
+ *
355
+ * @memberof TidyTable
356
+ * @method _toggleSelRows
357
+ * @private
358
+ *
359
+ * @param {Object} rows jQuery object
360
+ * @param {Number} num
361
+ */
362
+ "_toggleSelRows": function(rows, num) {
363
+ var checked = null;
364
+
365
+ rows.each(function(index) {
366
+ var row = $(this),
367
+ input = row.find(':checkbox').first();
368
+
369
+ // Update all rows.
370
+ if (!num) {
371
+ if (index === 0) {
372
+ checked = (input.is(':checked')) ? true : false;
373
+ return;
374
+ }
375
+
376
+ if (checked) {
377
+ row.removeClass('check_off').addClass('check_on');
378
+ input.prop('checked', true);
379
+ }
380
+ else {
381
+ row.removeClass('check_on').addClass('check_off');
382
+ input.prop('checked', false);
383
+ }
384
+ }
385
+
386
+ // Update selected row.
387
+ else {
388
+ if (index === 0) {
389
+ return;
390
+ }
391
+
392
+ if (input.is(':checked')) {
393
+ row.removeClass('check_off').addClass('check_on');
394
+ input.prop('checked', true);
395
+ }
396
+ else {
397
+ row.removeClass('check_on').addClass('check_off');
398
+ input.prop('checked', false);
399
+ }
400
+ }
401
+ });
402
+ },
403
+
404
+ /**
405
+ * Display results ordered by selected column.
406
+ *
407
+ * @memberof TidyTable
408
+ * @method _sortByColumn
409
+ * @private
410
+ *
411
+ * @param {Number} num
412
+ * @param {Number} order
413
+ */
414
+ "_sortByColumn": function(num, order) {
415
+ var $this = $(this),
416
+ data = $this.data();
417
+
418
+ if ( $.isFunction(data.config.sortByPattern) ) {
419
+ var reverse = (order == 'desc') ? -1 : 1;
420
+
421
+ // Sort JSON object by bucket number.
422
+ data.config.columnValues.sort(function(a, b) {
423
+ var str1 = data.config.sortByPattern(num, a[num]),
424
+ str2 = data.config.sortByPattern(num, b[num]);
425
+
426
+ if (isNaN(str1)) {
427
+ return [reverse * cmpAny(str1, str2)] >
428
+ [reverse * cmpAny(str2, str1)] ? -1 : 1;
429
+ }
430
+ else {
431
+ return [reverse * cmpInt(str1, str2)];
432
+ }
433
+ });
434
+ }
435
+
436
+ $this.TidyTable('_createTable', num, order);
437
+ }
438
+ };
439
+
440
+ $.fn.TidyTable = function(method) {
441
+ if (methods[method]) {
442
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
443
+ }
444
+ else
445
+ if (typeof method === 'object' || !method) {
446
+ return methods.init.apply(this, arguments);
447
+ }
448
+ else {
449
+ $.error('Method ' + method + ' does not exist in jQuery.TidyTable');
450
+ }
451
+ };
452
+
453
+ /**
454
+ * Generic string comparison functions.
455
+ *
456
+ * @protected
457
+ *
458
+ * @param {String} a
459
+ * @param {String} b
460
+ *
461
+ * @returns {Number}
462
+ */
463
+ function cmpAny(a, b) {
464
+ return (a > b) ? 1 : (a < b) ? -1 : 0;
465
+ }
466
+
467
+ function cmpInt(a, b) {
468
+ return b - a;
469
+ }
444
470
  })(jQuery);
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Tidy Table
3
- * Generate a sortable HTML table from JSON
3
+ * Create a HTML table from JSON that can be sorted, selected
4
+ * and post-processed using a simple callback.
4
5
  *
5
- * Copyright 2012-2015, Marc S. Brooks (http://mbrooks.info)
6
+ * Copyright 2012-2015, Marc S. Brooks (https://mbrooks.info)
6
7
  * Licensed under the MIT license:
7
8
  * http://www.opensource.org/licenses/mit-license.php
8
9
  *
@@ -11,129 +12,130 @@
11
12
  */
12
13
 
13
14
  table.tidy_table {
14
- background-color: #FFFFFF;
15
- border-collapse: collapse;
16
- border: 1px solid #CCCCCC;
17
- cursor: pointer;
18
- white-space: nowrap;
15
+ background-color: #FFFFFF;
16
+ border-collapse: collapse;
17
+ border: 1px solid #CCCCCC;
18
+ cursor: pointer;
19
+ white-space: nowrap;
19
20
  }
20
21
 
21
- table.tidy_table thead {
22
- border: none;
22
+ .tidy_table thead {
23
+ border: none;
23
24
  }
24
25
 
25
- table.tidy_table tr.check_on {
26
- background-color: #F5F5F5;
26
+ .tidy_table .check_on {
27
+ background-color: #F5F5F5;
27
28
  }
28
29
 
29
- table.tidy_table tr.check_off {
30
- background-color: #FFFFFF;
30
+ .tidy_table .check_off {
31
+ background-color: #FFFFFF;
31
32
  }
32
33
 
33
- table.tidy_table th {
34
- background-color: #DDDDDD;
34
+ .tidy_table th {
35
+ background-color: #DDDDDD;
35
36
  }
36
37
 
37
- table.tidy_table th.sort_asc {
38
- background: #EEEEEE url( images/arrow_asc.gif ) no-repeat right center;
38
+ .tidy_table .sort_asc {
39
+ background: #EEEEEE url( images/arrow_asc.gif ) no-repeat right center;
39
40
  }
40
41
 
41
- table.tidy_table th.sort_desc {
42
- background: #EEEEEE url( images/arrow_desc.gif ) no-repeat right center;
42
+ .tidy_table .sort_desc {
43
+ background: #EEEEEE url( images/arrow_desc.gif ) no-repeat right center;
43
44
  }
44
45
 
45
- table.tidy_table th,
46
- table.tidy_table td {
47
- padding: 6px 20px 6px 20px;
46
+ .tidy_table th,
47
+ .tidy_table td {
48
+ padding: 6px 20px;
48
49
  }
49
50
 
50
- table.tidy_table td {
51
- border-right: 1px solid #EEEEEE;
52
- border-top: 1px solid #CCCCCC;
53
- padding: 7px 20px 7px 20px;
51
+ .tidy_table td {
52
+ border-right: 1px solid #EEEEEE;
53
+ border-top: 1px solid #CCCCCC;
54
+ padding: 7px 20px;
54
55
  }
55
56
 
56
- table.tidy_table th:nth-child(1),
57
- table.tidy_table td:nth-child(1) {
58
- width: 10px;
57
+ .tidy_table th:nth-child(1),
58
+ .tidy_table td:nth-child(1) {
59
+ width: 10px;
59
60
  }
60
61
 
61
- table.tidy_table td:nth-child(1) {
62
- border-right: 1px solid #EEEEEE;
62
+ .tidy_table td:nth-child(1) {
63
+ border-right: 1px solid #EEEEEE;
63
64
  }
64
65
 
65
- table.tidy_table input[type=checkbox],
66
- table.tidy_table input[type=checkbox] {
67
- display: block;
68
- margin: 0px auto 0px auto;
66
+ .tidy_table input[type=checkbox],
67
+ .tidy_table input[type=checkbox] {
68
+ display: block;
69
+ margin: 0px auto;
69
70
  }
70
71
 
71
- table.tidy_table td:nth-last-child(1) {
72
- border-right: none;
72
+ .tidy_table td:nth-last-child(1) {
73
+ border-right: none;
73
74
  }
74
75
 
75
- table.tidy_table td span.label {
76
- display: none;
76
+ .tidy_table td .label {
77
+ display: none;
77
78
  }
78
79
 
79
- /* responsive (mobile devices) */
80
-
80
+ /**
81
+ * Responsive (mobile devices)
82
+ */
81
83
  @media only screen and (min-device-width: 0px) and (max-device-width: 768px) {
82
- .tidy_table.media {
83
- margin: 0px !important;
84
- width: auto !important;
85
- overflow: none;
86
- }
87
-
88
- .tidy_table.media select {
89
- position: relative;
90
- right: 30px;
91
- }
92
-
93
- .tidy_table.media table {
94
- border: 0px;
95
- border-top: 1px solid #DDDDDD;
96
- width: 100%;
97
- }
98
-
99
- .tidy_table.media table tr {
100
- border-bottom: 1px solid #CCCCCC;
101
- position: relative;
102
- }
103
-
104
- .tidy_table.media table tbody tr:last-child {
105
- border: none;
106
- }
107
-
108
- .tidy_table.media table th,
109
- .tidy_table.media table td {
110
- box-sizing: border-box;
111
- border: 0px;
112
- clear: both;
113
- float: left;
114
- padding-left: 10px;
115
- }
116
-
117
- .tidy_table.media table th:first-child,
118
- .tidy_table.media table td:first-child {
119
- background-color: transparent;
120
- padding: 10px;
121
- position: absolute;
122
- right: 0px;
123
- top: 2px;
124
- width: auto;
125
- }
126
-
127
- .tidy_table.media table th {
128
- text-align: left;
129
- width: 100%;
130
- }
131
-
132
- .tidy_table.media table th:first-child {
133
- top: -40px;
134
- }
135
-
136
- .tidy_table.media table td {
137
- background-color: transparent;
138
- }
84
+ .tidy_media {
85
+ margin: 0px !important;
86
+ width: auto !important;
87
+ overflow: none;
88
+ }
89
+
90
+ .tidy_media select {
91
+ position: relative;
92
+ right: 30px;
93
+ }
94
+
95
+ .tidy_media table {
96
+ border: 0px;
97
+ border-top: 1px solid #DDDDDD;
98
+ width: 100%;
99
+ }
100
+
101
+ .tidy_media table tr {
102
+ border-bottom: 1px solid #CCCCCC;
103
+ position: relative;
104
+ }
105
+
106
+ .tidy_media table tbody tr:last-child {
107
+ border: none;
108
+ }
109
+
110
+ .tidy_media table th,
111
+ .tidy_media table td {
112
+ box-sizing: border-box;
113
+ border: 0px;
114
+ clear: both;
115
+ float: left;
116
+ padding-left: 10px;
117
+ }
118
+
119
+ .tidy_media table th:first-child,
120
+ .tidy_media table td:first-child {
121
+ background-color: transparent;
122
+ padding: 10px;
123
+ position: absolute;
124
+ right: 0px;
125
+ top: 2px;
126
+ width: auto;
127
+ }
128
+
129
+ .tidy_media table th {
130
+ text-align: left;
131
+ width: 100%;
132
+ }
133
+
134
+ .tidy_media table th:first-child {
135
+ top: -40px;
136
+ }
137
+
138
+ .tidy_media table td {
139
+ background-color: transparent;
140
+ }
139
141
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidy-table-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dbackowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails