tidy-table-rails 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +4 -0
  5. data/README.md +3 -3
  6. data/Rakefile +5 -0
  7. data/lib/tidy/table/rails/version.rb +1 -1
  8. data/spec/dummy/README.rdoc +28 -0
  9. data/spec/dummy/Rakefile +6 -0
  10. data/spec/dummy/app/assets/images/.keep +0 -0
  11. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  12. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  13. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  14. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/mailers/.keep +0 -0
  17. data/spec/dummy/app/models/.keep +0 -0
  18. data/spec/dummy/app/models/concerns/.keep +0 -0
  19. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/spec/dummy/bin/bundle +3 -0
  21. data/spec/dummy/bin/rails +4 -0
  22. data/spec/dummy/bin/rake +4 -0
  23. data/spec/dummy/bin/setup +29 -0
  24. data/spec/dummy/config/application.rb +31 -0
  25. data/spec/dummy/config/boot.rb +5 -0
  26. data/spec/dummy/config/database.yml +25 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +41 -0
  29. data/spec/dummy/config/environments/production.rb +79 -0
  30. data/spec/dummy/config/environments/test.rb +42 -0
  31. data/spec/dummy/config/initializers/assets.rb +11 -0
  32. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  34. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  35. data/spec/dummy/config/initializers/inflections.rb +16 -0
  36. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  37. data/spec/dummy/config/initializers/session_store.rb +3 -0
  38. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  39. data/spec/dummy/config/locales/en.yml +23 -0
  40. data/spec/dummy/config/routes.rb +56 -0
  41. data/spec/dummy/config/secrets.yml +22 -0
  42. data/spec/dummy/config.ru +4 -0
  43. data/spec/dummy/db/test.sqlite3 +0 -0
  44. data/spec/dummy/lib/assets/.keep +0 -0
  45. data/spec/dummy/log/.keep +0 -0
  46. data/spec/dummy/log/test.log +2 -0
  47. data/spec/dummy/public/404.html +67 -0
  48. data/spec/dummy/public/422.html +67 -0
  49. data/spec/dummy/public/500.html +66 -0
  50. data/spec/dummy/public/favicon.ico +0 -0
  51. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9dUiGLnCoYGlMMoyJxiA6sYZaTzO5E0z3LXIndUkZxA.cache +1 -0
  52. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/I7iA12QXi0v_d_m9KnwGlJs0i-jxq8jOTjoSGgThLS8.cache +0 -0
  53. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/IdEQpyq95L1ZCKsvyYXpmwrJ5m4re1-PU4QWSvGO2cA.cache +3 -0
  54. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J0T-ieNYyNasfJXbNOX-i8gPFlnz7umulnY5jHQ8cMg.cache +0 -0
  55. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/RArjhRyejO70EgWK-qg6b3QMyrhdPgj5Zi3dagQrXqE.cache +1 -0
  56. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UE6Uhwge2PToyGuiqGSQteTsHGYAmixLx_rU0U6e1s0.cache +3 -0
  57. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UvnNaNyNiZ6RVDZb8QtaAxMilES3-i161zcJdqBni8k.cache +2 -0
  58. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/YwCR5bONajMEo7HvhY050SUpBt5yJPUJICk_rWmhGAk.cache +0 -0
  59. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e46AYnIIxZHGEJgpFAx3S37NZDTxLp11WZxCi7cf8l8.cache +2 -0
  60. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hCbJZ7N6h55f6Ebq0l5bneTKIpaMVaSh0PpNRkN5lEM.cache +1 -0
  61. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uufkynyrXOoO6kmUBbcwIGiKVVoM5NavmXUQH2vidWA.cache +0 -0
  62. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/vP_muxnzZtn8RNqAm02_r_zYcckWlo8C7xmvFctN44c.cache +0 -0
  63. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wr7plbJR8oEsGvgnc_0dRRL3L0dPh9yZ-MVE6mSpRbI.cache +1 -0
  64. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zpU64aTKUJH4CAknZnsxZxRdJDE3H7fAuZX0ObycI5Q.cache +1 -0
  65. data/spec/features/assets_spec.rb +13 -0
  66. data/spec/spec_helper.rb +4 -0
  67. data/tidy-table-rails.gemspec +5 -1
  68. data/vendor/assets/javascripts/tidy-table.js +124 -132
  69. data/vendor/assets/stylesheets/tidy-table.css +1 -4
  70. metadata +169 -20
@@ -3,19 +3,14 @@
3
3
  * Create a HTML table from JSON that can be sorted, selected
4
4
  * and post-processed using a simple callback.
5
5
  *
6
- * Copyright 2012-2015, Marc S. Brooks (https://mbrooks.info)
6
+ * Copyright 2012-2016, Marc S. Brooks (https://mbrooks.info)
7
7
  * Licensed under the MIT license:
8
8
  * http://www.opensource.org/licenses/mit-license.php
9
- *
10
- * Dependencies:
11
- * jquery.js
12
9
  */
13
10
 
14
- if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace('.', '')) < parseInt('1.8.3'.replace('.', '')))) {
15
- throw new Error('Tidy-Table requires jQuery 1.8.3 or greater.');
16
- }
11
+ (function() {
12
+ "use strict";
17
13
 
18
- (function($) {
19
14
  var table = null;
20
15
 
21
16
  /**
@@ -30,16 +25,16 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
30
25
  * @method init
31
26
  *
32
27
  * @example
33
- * $('#container').TidyTable(settings, config);
28
+ * document.getElementById('container').TidyTable(settings, config);
34
29
  *
35
30
  * @param {Object} settings
36
31
  * @param {Object} config
37
32
  *
38
- * @returns {Object} jQuery object
33
+ * @returns {Object} DOM element
39
34
  */
40
35
  "init": function(settings, config) {
41
- var $this = $(this),
42
- data = $this.data();
36
+ var _self = this,
37
+ data = _self.data;
43
38
 
44
39
  // Default settings
45
40
  var defaults = {
@@ -50,34 +45,34 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
50
45
  };
51
46
 
52
47
  if (arguments.length > 1) {
53
- $.extend(defaults, settings);
48
+ Object.assign(defaults, settings);
54
49
  }
55
50
  else {
56
51
  config = settings;
57
52
  }
58
53
 
59
54
  // Config defaults
60
- config = $.extend({
55
+ config = Object.assign({
61
56
  sortByPattern: function(col_num, val) {
62
- if ( $.trim(col_num) ) {
57
+ if (col_num && val) {
63
58
  return String(val).replace(/$|%|#/g, '');
64
59
  }
65
60
  }
66
61
  }, config);
67
62
 
68
- if ( $.isEmptyObject(data) ) {
69
- $this.data({
63
+ if (typeof data === 'undefined') {
64
+ _self.data = {
70
65
  settings: defaults,
71
66
  config: config
72
- });
67
+ };
73
68
  }
74
69
 
75
70
  // Responsive layout?
76
71
  if (defaults.responsive) {
77
- $this.addClass('tidy_table media');
72
+ _self.className = 'tidy_table media';
78
73
  }
79
74
 
80
- return $this.TidyTable('_createTable');
75
+ return _self.TidyTable('_createTable');
81
76
  },
82
77
 
83
78
  /**
@@ -87,10 +82,10 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
87
82
  * @method destroy
88
83
  *
89
84
  * @example
90
- * $('#container').TidyTable('destroy');
85
+ * document.getElementById('container').TidyTable('destroy');
91
86
  */
92
87
  "destroy": function() {
93
- $(this).removeData();
88
+ this.remove();
94
89
  },
95
90
 
96
91
  /**
@@ -103,37 +98,34 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
103
98
  * @param {String|undefined} num
104
99
  * @param {String|undefined} order
105
100
  *
106
- * @returns {Object} jQuery object
101
+ * @returns {Object} DOM element
107
102
  */
108
103
  "_createTable": function(num, order) {
109
- var $this = $(this),
110
- data = $this.data();
104
+ var _self = this,
105
+ data = _self.data;
111
106
 
112
107
  // 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; });
108
+ table = document.createElement('table');
109
+ table.className = 'tidy_table';
119
110
 
120
- var thead = $('<thead></thead>'),
121
- tbody = $('<tbody></tbody>'),
111
+ var thead = document.createElement('thead'),
112
+ tbody = document.createElement('tbody'),
122
113
  titles = null;
123
114
 
124
115
  // .. <THEAD>
125
116
  (function() {
126
117
  titles = data.config.columnTitles;
127
118
 
128
- var row = $('<tr></tr>');
119
+ var row = document.createElement('tr');
129
120
 
130
121
  for (var i = 0; i < titles.length; i++) {
131
122
  var title = titles[i];
132
123
 
133
- var col = $('<th></th>')
134
- .append(title)
135
- .attr('title', title);
136
- row.append(col);
124
+ var col = document.createElement('th');
125
+ col.appendChild(document.createTextNode(title));
126
+ col.setAttribute('title', title);
127
+
128
+ row.appendChild(col);
137
129
 
138
130
  var col_class;
139
131
 
@@ -161,109 +153,106 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
161
153
 
162
154
  // Highlight selected column.
163
155
  if (num == i) {
164
- col.addClass(col_class);
156
+ col.className = col_class;
165
157
  }
166
158
 
159
+ col.index = i;
160
+
167
161
  // 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
- });
162
+ col.addEventListener('click', function() {
163
+ _self.TidyTable('_sortByColumn', this.index, ((num == this.index) ? this.order : 'asc'));
164
+ }, false);
175
165
  }
176
166
 
177
- thead.append(row);
167
+ thead.appendChild(row);
178
168
  })();
179
169
 
180
170
  // .. <TBODY>
181
171
  (function() {
182
- var vals = data.config.columnValues;
172
+ var vals = data.config.columnValues,
173
+ col = null;
183
174
 
184
175
  for (var j = 0; j < vals.length; j++) {
185
- var row = $('<tr></tr>');
176
+
177
+ // Create the row.
178
+ var row = document.createElement('tr');
186
179
 
187
180
  for (var k = 0; k < vals[j].length; k++) {
188
181
  var val = vals[j][k];
189
182
 
190
- var col = $('<td></td>')
191
- .append(val)
192
- .attr('title', val);
193
- row.append(col);
183
+ // Create the column.
184
+ col = document.createElement('td');
185
+ col.appendChild(document.createTextNode(val));
186
+ col.setAttribute('title', val);
187
+
188
+ row.appendChild(col);
194
189
 
195
190
  // Post-process table column HTML object.
196
- if (data.config.postProcess && $.isFunction(data.config.postProcess.column)) {
191
+ if (data.config.postProcess && (typeof data.config.postProcess.column === "function")) {
197
192
  data.config.postProcess.column(col);
198
193
  }
199
194
  }
200
195
 
201
- tbody.append(row);
196
+ tbody.appendChild(row);
202
197
  }
203
198
 
204
- table.append(thead);
205
- table.append(tbody);
199
+ table.appendChild(thead);
200
+ table.appendChild(tbody);
206
201
 
207
202
  // Append check boxes to beginning each row.
208
203
  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');
204
+ var rows = table.querySelectorAll('tr');
214
205
 
215
- var col;
206
+ for (var i = 0; i < rows.length; i++) {
207
+ var input = document.createElement('input');
208
+ input.setAttribute('type', 'checkbox');
209
+ input.index = i;
216
210
 
217
211
  // First row is always the header.
218
- if (index === 0) {
219
- col = $('<th></th>');
212
+ if (i === 0) {
213
+ col = document.createElement('th');
220
214
 
221
215
  // Attach event to check all boxes.
222
- input.on('click', function() {
223
- $this.TidyTable('_toggleSelRows', rows);
216
+ input.addEventListener('click', function() {
217
+ _self.TidyTable('_toggleSelRows', rows);
224
218
  });
225
219
  }
226
220
  else {
227
- col = $('<td></td>');
221
+ col = document.createElement('td');
228
222
 
229
223
  // 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);
224
+ input.addEventListener('click', function() {
225
+ _self.TidyTable('_toggleSelRows', rows, this.index);
235
226
  });
236
227
  }
237
228
 
238
- col.append(input);
229
+ col.appendChild(input);
239
230
 
240
231
  // Insert before first cell.
241
- $(this).prepend(col);
242
- });
232
+ rows[i].insertBefore(col, rows[i].firstChild);
233
+ }
243
234
  }
244
235
  })();
245
236
 
246
237
  // Post-process table results HTML object.
247
- if (data.config.postProcess && $.isFunction(data.config.postProcess.table)) {
238
+ if (data.config.postProcess && (typeof data.config.postProcess.table === "function")) {
248
239
  data.config.postProcess.table(table);
249
240
  }
250
241
 
251
- var block = $this.children('table.tidy_table');
242
+ var block = _self.querySelector('table.tidy_table');
252
243
 
253
244
  // If table exists, perform an in-place update of the element.
254
- if (block[0]) {
255
- block.replaceWith(table);
245
+ if (block) {
246
+ block.parentNode.replaceChild(table, block);
256
247
  }
257
248
 
258
249
  // Generate table/menu elements.
259
250
  else {
260
251
  if (data.settings && data.settings.enableMenu) {
261
- $this.append(
262
- $this.TidyTable('_createMenu', 'options')
263
- );
252
+ _self.appendChild( _self.TidyTable('_createMenu', 'options') );
264
253
  }
265
254
 
266
- $this.append(table);
255
+ _self.appendChild(table);
267
256
  }
268
257
 
269
258
  return table;
@@ -278,38 +267,41 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
278
267
  *
279
268
  * @param {String} name
280
269
  *
281
- * @returns {Object} jQuery object
270
+ * @returns {Object} DOM element
282
271
  */
283
272
  "_createMenu": function(name) {
284
- var $this = $(this),
285
- data = $this.data();
273
+ var _self = this,
274
+ data = _self.data;
286
275
 
287
276
  // Create reusable elements.
288
- var select = $('<select></select>')
289
- .addClass('tidy_table ' + name)
290
- .change(function() {
291
- var elm = $(this);
277
+ var select = document.createElement('select');
278
+ select.className = 'tidy_table ' + name;
292
279
 
293
- var callback = data.config.menuOptions[ elm.val() ][1]['callback'];
280
+ // Listen for select menu events.
281
+ select.addEventListener('change', function() {
282
+ var elm = this;
294
283
 
295
- // Callback event
296
- if ( $.isFunction(callback) ) {
297
- callback( $this.TidyTable('_getCheckedAsObj') );
298
- }
284
+ // Execute callback.
285
+ var callback = data.config.menuOptions[elm.value][1].callback;
299
286
 
300
- elm.val(0);
301
- });
287
+ if (typeof callback === 'function') {
288
+ callback( _self.TidyTable('_getCheckedAsObj') );
289
+ }
290
+
291
+ elm.value = 0;
292
+ });
302
293
 
303
294
  // .. Options
304
- $.each(data.config.menuOptions, function(index) {
305
- var option = $('<option>' + data.config.menuOptions[index][0] + '</option>')
306
- .attr('value', index);
295
+ for (var i = 0; i < data.config.menuOptions.length; i++) {
296
+ var option = document.createElement('option');
297
+ option.text = data.config.menuOptions[i][0];
298
+ option.value = i;
307
299
 
308
- select.append(option);
309
- });
300
+ select.appendChild(option);
301
+ }
310
302
 
311
303
  // Post-process select menu HTML object.
312
- if (data.config.postProcess && $.isFunction(data.config.postProcess.menu)) {
304
+ if (data.config.postProcess && (typeof data.config.postProcess.menu === 'function')) {
313
305
  data.config.postProcess.menu(select);
314
306
  }
315
307
 
@@ -326,8 +318,8 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
326
318
  * @returns {Array}
327
319
  */
328
320
  "_getCheckedAsObj": function() {
329
- var $this = $(this),
330
- rows = $this.find('tbody > tr'),
321
+ var _self = this,
322
+ rows = _self.querySelectorAll('tbody > tr'),
331
323
  objs = [];
332
324
 
333
325
  for (var i = 0; i < rows.length; i++) {
@@ -356,49 +348,49 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
356
348
  * @method _toggleSelRows
357
349
  * @private
358
350
  *
359
- * @param {Object} rows jQuery object
351
+ * @param {Object} rows DOM element
360
352
  * @param {Number} num
361
353
  */
362
354
  "_toggleSelRows": function(rows, num) {
363
355
  var checked = null;
364
356
 
365
- rows.each(function(index) {
366
- var row = $(this),
367
- input = row.find(':checkbox').first();
357
+ for (var i = 0; i < rows.length; i++) {
358
+ var row = rows[i],
359
+ input = row.querySelector('input[type=checkbox]');
368
360
 
369
361
  // Update all rows.
370
362
  if (!num) {
371
- if (index === 0) {
372
- checked = (input.is(':checked')) ? true : false;
373
- return;
363
+ if (i === 0) {
364
+ checked = input.checked;
365
+ continue;
374
366
  }
375
367
 
376
368
  if (checked) {
377
- row.removeClass('check_off').addClass('check_on');
378
- input.prop('checked', true);
369
+ row.className = (row.className) ? row.className.replace(/check_off/, 'check_on') : 'check_on';
370
+ input.checked = true;
379
371
  }
380
372
  else {
381
- row.removeClass('check_on').addClass('check_off');
382
- input.prop('checked', false);
373
+ row.className = row.className.replace(/check_on/, 'check_off');
374
+ input.checked = false;
383
375
  }
384
376
  }
385
377
 
386
378
  // Update selected row.
387
379
  else {
388
- if (index === 0) {
389
- return;
380
+ if (i === 0) {
381
+ continue;
390
382
  }
391
383
 
392
- if (input.is(':checked')) {
393
- row.removeClass('check_off').addClass('check_on');
394
- input.prop('checked', true);
384
+ if (input.checked === true) {
385
+ row.className = (row.className) ? row.className.replace(/check_off/, 'check_on') : 'check_on';
386
+ input.checked = true;
395
387
  }
396
388
  else {
397
- row.removeClass('check_on').addClass('check_off');
398
- input.prop('checked', false);
389
+ row.className = row.className.replace(/check_on/, 'check_off');
390
+ input.checked = false;
399
391
  }
400
392
  }
401
- });
393
+ }
402
394
  },
403
395
 
404
396
  /**
@@ -412,10 +404,10 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
412
404
  * @param {Number} order
413
405
  */
414
406
  "_sortByColumn": function(num, order) {
415
- var $this = $(this),
416
- data = $this.data();
407
+ var _self = this,
408
+ data = _self.data;
417
409
 
418
- if ( $.isFunction(data.config.sortByPattern) ) {
410
+ if (typeof data.config.sortByPattern === 'function') {
419
411
  var reverse = (order == 'desc') ? -1 : 1;
420
412
 
421
413
  // Sort JSON object by bucket number.
@@ -433,11 +425,11 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
433
425
  });
434
426
  }
435
427
 
436
- $this.TidyTable('_createTable', num, order);
428
+ _self.TidyTable('_createTable', num, order);
437
429
  }
438
430
  };
439
431
 
440
- $.fn.TidyTable = function(method) {
432
+ Element.prototype.TidyTable = function(method) {
441
433
  if (methods[method]) {
442
434
  return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
443
435
  }
@@ -446,7 +438,7 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
446
438
  return methods.init.apply(this, arguments);
447
439
  }
448
440
  else {
449
- $.error('Method ' + method + ' does not exist in jQuery.TidyTable');
441
+ throw new Error('Method ' + method + ' does not exist in TidyTable');
450
442
  }
451
443
  };
452
444
 
@@ -467,4 +459,4 @@ if (!window.jQuery || (window.jQuery && parseInt(window.jQuery.fn.jquery.replace
467
459
  function cmpInt(a, b) {
468
460
  return b - a;
469
461
  }
470
- })(jQuery);
462
+ })();
@@ -3,12 +3,9 @@
3
3
  * Create a HTML table from JSON that can be sorted, selected
4
4
  * and post-processed using a simple callback.
5
5
  *
6
- * Copyright 2012-2015, Marc S. Brooks (https://mbrooks.info)
6
+ * Copyright 2012-2016, Marc S. Brooks (https://mbrooks.info)
7
7
  * Licensed under the MIT license:
8
8
  * http://www.opensource.org/licenses/mit-license.php
9
- *
10
- * Dependencies:
11
- * jquery.js
12
9
  */
13
10
 
14
11
  table.tidy_table {