rails_bootstrap_sortable 1.11.2 → 2.0.0

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: efac0d3b6bad0b1dff278613be5a8aab39c66607
4
- data.tar.gz: 27edb2e5dc1157c6cba2055d52438c0cb72c6efd
3
+ metadata.gz: 637e10266713b22faa3fa473f7a7bc74441655ac
4
+ data.tar.gz: d763848bc8d27f58c20b4263a64134b22c7afbd3
5
5
  SHA512:
6
- metadata.gz: 27342cf52a2334d61955cfb09e0c4b644bdb29213f43e05e9324f6825a367d5df8bf9c59fa1fc4929c9bd88642f772fe57c02ca8d698efca58c407cd5799a2cc
7
- data.tar.gz: 3b784a1efb9c42d8e7654104e1db5743af6873d617646b563aa4b480d200ba2ac81050b50f50e29456d59658be05752f06a7d652cd6b8c1d34cd770f9da26f04
6
+ metadata.gz: 75f6e7c3ff9ac11aa53db78217605264909db683af956353e0582b57321d62a952d18e2cb9a2bde610a0be84e912f26cec8b47c639c824a85deb56d3f8b54785
7
+ data.tar.gz: 1da48ab2ca83197057bbb395b824661a20a78a48c1a1e88825a00a84f1babf3ab7bdfa128caf6f6399ba82de0e060bbabcd78432d32aa0fd53f591f4caabc957
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_sortable (1.11.2)
4
+ rails_bootstrap_sortable (2.0.0)
5
5
  momentjs-rails (~> 2, >= 2.8.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (4.2.1)
11
- actionview (= 4.2.1)
12
- activesupport (= 4.2.1)
10
+ actionpack (4.2.6)
11
+ actionview (= 4.2.6)
12
+ activesupport (= 4.2.6)
13
13
  rack (~> 1.6)
14
14
  rack-test (~> 0.6.2)
15
15
  rails-dom-testing (~> 1.0, >= 1.0.5)
16
- rails-html-sanitizer (~> 1.0, >= 1.0.1)
17
- actionview (4.2.1)
18
- activesupport (= 4.2.1)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (4.2.6)
18
+ activesupport (= 4.2.6)
19
19
  builder (~> 3.1)
20
20
  erubis (~> 2.7.0)
21
21
  rails-dom-testing (~> 1.0, >= 1.0.5)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
- activesupport (4.2.1)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ activesupport (4.2.6)
24
24
  i18n (~> 0.7)
25
25
  json (~> 1.7, >= 1.7.7)
26
26
  minitest (~> 5.1)
@@ -29,32 +29,32 @@ GEM
29
29
  builder (3.2.2)
30
30
  erubis (2.7.0)
31
31
  i18n (0.7.0)
32
- json (1.8.2)
33
- loofah (2.0.2)
32
+ json (1.8.3)
33
+ loofah (2.0.3)
34
34
  nokogiri (>= 1.5.9)
35
- mini_portile (0.6.2)
36
- minitest (5.6.1)
37
- momentjs-rails (2.10.2)
35
+ mini_portile2 (2.0.0)
36
+ minitest (5.8.4)
37
+ momentjs-rails (2.11.0)
38
38
  railties (>= 3.1)
39
- nokogiri (1.6.6.2)
40
- mini_portile (~> 0.6.0)
41
- rack (1.6.1)
39
+ nokogiri (1.6.7.2)
40
+ mini_portile2 (~> 2.0.0.rc2)
41
+ rack (1.6.4)
42
42
  rack-test (0.6.3)
43
43
  rack (>= 1.0)
44
44
  rails-deprecated_sanitizer (1.0.3)
45
45
  activesupport (>= 4.2.0.alpha)
46
- rails-dom-testing (1.0.6)
46
+ rails-dom-testing (1.0.7)
47
47
  activesupport (>= 4.2.0.beta, < 5.0)
48
48
  nokogiri (~> 1.6.0)
49
49
  rails-deprecated_sanitizer (>= 1.0.1)
50
- rails-html-sanitizer (1.0.2)
50
+ rails-html-sanitizer (1.0.3)
51
51
  loofah (~> 2.0)
52
- railties (4.2.1)
53
- actionpack (= 4.2.1)
54
- activesupport (= 4.2.1)
52
+ railties (4.2.6)
53
+ actionpack (= 4.2.6)
54
+ activesupport (= 4.2.6)
55
55
  rake (>= 0.8.7)
56
56
  thor (>= 0.18.1, < 2.0)
57
- rake (10.4.2)
57
+ rake (11.1.2)
58
58
  thor (0.19.1)
59
59
  thread_safe (0.3.5)
60
60
  tzinfo (1.2.2)
@@ -67,3 +67,6 @@ DEPENDENCIES
67
67
  bundler (~> 1.6)
68
68
  rails_bootstrap_sortable!
69
69
  rake
70
+
71
+ BUNDLED WITH
72
+ 1.11.2
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapSortable
2
- VERSION = "1.11.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,3 +1,13 @@
1
+ /**
2
+ * adding sorting ability to HTML tables with Bootstrap styling
3
+ * @summary HTML tables sorting ability
4
+ * @version 2.0.0
5
+ * @requires tinysort, moment.js, jQuery
6
+ * @license MIT
7
+ * @author Matus Brlit (drvic10k)
8
+ * @copyright Matus Brlit (drvic10k), bootstrap-sortable contributors
9
+ */
10
+
1
11
  /**
2
12
  * TinySort is a small script that sorts HTML elements. It sorts by text- or attribute value, or by that of one of it's children.
3
13
  * @summary A nodeElement sorting script.
@@ -13,25 +23,42 @@
13
23
 
14
24
  var $document = $(document),
15
25
  signClass,
16
- sortEngine;
26
+ sortEngine,
27
+ emptyEnd;
17
28
 
18
- $.bootstrapSortable = function (applyLast, sign, customSort) {
29
+ $.bootstrapSortable = function (options) {
30
+ if (options == undefined) {
31
+ initialize({});
32
+ }
33
+ else if (options.constructor === Boolean) {
34
+ initialize({ applyLast: options });
35
+ }
36
+ else if (options.sortingHeader !== undefined) {
37
+ sortByColumn(options.sortingHeader);
38
+ }
39
+ else {
40
+ initialize(options);
41
+ }
42
+ };
19
43
 
44
+ function initialize(options) {
20
45
  // Check if moment.js is available
21
46
  var momentJsAvailable = (typeof moment !== 'undefined');
22
47
 
23
48
  // Set class based on sign parameter
24
- signClass = !sign ? "arrow" : sign;
49
+ signClass = !options.sign ? "arrow" : options.sign;
25
50
 
26
51
  // Set sorting algorithm
27
- if (customSort == 'default')
28
- customSort = defaultSortEngine;
29
- sortEngine = customSort || sortEngine || defaultSortEngine;
52
+ if (options.customSort == 'default')
53
+ options.customSort = defaultSortEngine;
54
+ sortEngine = options.customSort || sortEngine || defaultSortEngine;
55
+
56
+ emptyEnd = options.emptyEnd;
30
57
 
31
58
  // Set attributes needed for sorting
32
59
  $('table.sortable').each(function () {
33
60
  var $this = $(this);
34
- applyLast = (applyLast === true);
61
+ var applyLast = (options.applyLast === true);
35
62
  $this.find('span.sign').remove();
36
63
 
37
64
  // Add placeholder cells for colspans
@@ -57,24 +84,46 @@
57
84
  // Set indexes to header cells
58
85
  $this.find('thead tr').each(function (rowIndex) {
59
86
  $(this).find('th').each(function (columnIndex) {
60
- var $this = $(this);
61
- $this.addClass('nosort').removeClass('up down');
62
- $this.attr('data-sortcolumn', columnIndex);
63
- $this.attr('data-sortkey', columnIndex + '-' + rowIndex);
87
+ var $header = $(this);
88
+ $header.addClass('nosort').removeClass('up down');
89
+ $header.attr('data-sortcolumn', columnIndex);
90
+ $header.attr('data-sortkey', columnIndex + '-' + rowIndex);
64
91
  });
65
92
  });
66
93
 
67
94
  // Cleanup placeholder cells
68
95
  $this.find('thead .rowspan-compensate, .colspan-compensate').remove();
69
96
 
97
+ // Initialize sorting values specified in header
98
+ $this.find('th').each(function () {
99
+ var $header = $(this);
100
+ if ($header.attr('data-dateformat') !== undefined && momentJsAvailable) {
101
+ var colNumber = parseFloat($header.attr('data-sortcolumn'));
102
+ $this.find('td:nth-child(' + (colNumber + 1) + ')').each(function () {
103
+ var $cell = $(this);
104
+ $cell.attr('data-value', moment($cell.text(), $header.attr('data-dateformat')).format('YYYY/MM/DD/HH/mm/ss'));
105
+ });
106
+ }
107
+ else if ($header.attr('data-valueprovider') !== undefined) {
108
+ var colNumber = parseFloat($header.attr('data-sortcolumn'));
109
+ $this.find('td:nth-child(' + (colNumber + 1) + ')').each(function () {
110
+ var $cell = $(this);
111
+ $cell.attr('data-value', new RegExp($header.attr('data-valueprovider')).exec($cell.text())[0]);
112
+ });
113
+ }
114
+ });
115
+
70
116
  // Initialize sorting values
71
117
  $this.find('td').each(function () {
72
- var $this = $(this);
73
- if ($this.attr('data-dateformat') !== undefined && momentJsAvailable) {
74
- $this.attr('data-value', moment($this.text(), $this.attr('data-dateformat')).format('YYYY/MM/DD/HH/mm/ss'));
118
+ var $cell = $(this);
119
+ if ($cell.attr('data-dateformat') !== undefined && momentJsAvailable) {
120
+ $cell.attr('data-value', moment($cell.text(), $cell.attr('data-dateformat')).format('YYYY/MM/DD/HH/mm/ss'));
121
+ }
122
+ else if ($cell.attr('data-valueprovider') !== undefined) {
123
+ $cell.attr('data-value', new RegExp($cell.attr('data-valueprovider')).exec($cell.text())[0]);
75
124
  }
76
125
  else {
77
- $this.attr('data-value') === undefined && $this.attr('data-value', $this.text());
126
+ $cell.attr('data-value') === undefined && $cell.attr('data-value', $cell.text());
78
127
  }
79
128
  });
80
129
 
@@ -82,28 +131,33 @@
82
131
  bsSort = context.bsSort;
83
132
 
84
133
  $this.find('thead th[data-defaultsort!="disabled"]').each(function (index) {
85
- var $this = $(this);
86
- var $sortTable = $this.closest('table.sortable');
87
- $this.data('sortTable', $sortTable);
88
- var sortKey = $this.attr('data-sortkey');
134
+ var $header = $(this);
135
+ var $sortTable = $header.closest('table.sortable');
136
+ $header.data('sortTable', $sortTable);
137
+ var sortKey = $header.attr('data-sortkey');
89
138
  var thisLastSort = applyLast ? context.lastSort : -1;
90
- bsSort[sortKey] = applyLast ? bsSort[sortKey] : $this.attr('data-defaultsort');
139
+ bsSort[sortKey] = applyLast ? bsSort[sortKey] : $header.attr('data-defaultsort');
91
140
  if (bsSort[sortKey] !== undefined && (applyLast === (sortKey === thisLastSort))) {
92
141
  bsSort[sortKey] = bsSort[sortKey] === 'asc' ? 'desc' : 'asc';
93
- doSort($this, $sortTable);
142
+ doSort($header, $sortTable);
94
143
  }
95
144
  });
96
145
  $this.trigger('sorted');
97
146
  });
98
- };
147
+ }
99
148
 
100
149
  // Add click event to table header
101
- $document.on('click', 'table.sortable thead th[data-defaultsort!="disabled"]', function (e) {
102
- var $this = $(this), $table = $this.data('sortTable') || $this.closest('table.sortable');
150
+ $document.on('click', 'table.sortable>thead th[data-defaultsort!="disabled"]', function (e) {
151
+ sortByColumn(this);
152
+ });
153
+
154
+ // element is the header of the column to sort (the clicked header)
155
+ function sortByColumn(element) {
156
+ var $this = $(element), $table = $this.data('sortTable') || $this.closest('table.sortable');
103
157
  $table.trigger('before-sort');
104
158
  doSort($this, $table);
105
159
  $table.trigger('sorted');
106
- });
160
+ }
107
161
 
108
162
  // Look up sorting data appropriate for the specified table (jQuery element).
109
163
  // This allows multiple tables on one page without collisions.
@@ -173,8 +227,13 @@
173
227
  var sortKey = $this.attr('data-sortkey');
174
228
  var initialDirection = $this.attr('data-firstsort') !== 'desc' ? 'desc' : 'asc';
175
229
 
230
+ var newDirection = (bsSort[sortKey] || initialDirection);
231
+ if (context.lastSort === sortKey || bsSort[sortKey] === undefined) {
232
+ newDirection = newDirection === 'asc' ? 'desc' : 'asc';
233
+ }
234
+ bsSort[sortKey] = newDirection;
176
235
  context.lastSort = sortKey;
177
- bsSort[sortKey] = (bsSort[sortKey] || initialDirection) === 'asc' ? 'desc' : 'asc';
236
+
178
237
  if (bsSort[sortKey] === 'desc') {
179
238
  $this.find('span.sign').addClass('up');
180
239
  $this.addClass('up').removeClass('down nosort');
@@ -182,13 +241,34 @@
182
241
  $this.addClass('down').removeClass('up nosort');
183
242
  }
184
243
 
185
- // sort rows
244
+ // remove rows that should not be sorted
186
245
  var rows = $table.children('tbody').children('tr');
187
- sortEngine(rows, { selector: 'td:nth-child(' + (sortColumn + 1) + ')', order: bsSort[sortKey], data: 'value' });
246
+ var fixedRows = [];
247
+ $(rows.filter('[data-disablesort="true"]').get().reverse()).each(function (index, fixedRow) {
248
+ var $fixedRow = $(fixedRow);
249
+ fixedRows.push({ index: rows.index($fixedRow), row: $fixedRow });
250
+ $fixedRow.remove();
251
+ });
252
+
253
+ // sort rows
254
+ var rowsToSort = rows.not('[data-disablesort="true"]');
255
+ if (rowsToSort.length != 0) {
256
+ var emptySorting = bsSort[sortKey] === 'asc' ? emptyEnd : false;
257
+ sortEngine(rowsToSort, { emptyEnd: emptySorting, selector: 'td:nth-child(' + (sortColumn + 1) + ')', order: bsSort[sortKey], data: 'value' });
258
+ }
259
+
260
+ // add back the fixed rows
261
+ $(fixedRows.reverse()).each(function (index, row) {
262
+ if (row.index === 0) {
263
+ $table.children('tbody').prepend(row.row);
264
+ } else {
265
+ $table.children('tbody').children('tr').eq(row.index - 1).after(row.row);
266
+ }
267
+ });
188
268
 
189
269
  // add class to sorted column cells
190
270
  $table.find('td.sorted, th.sorted').removeClass('sorted');
191
- rows.find('td:eq(' + sortColumn + ')').addClass('sorted');
271
+ rowsToSort.find('td:eq(' + sortColumn + ')').addClass('sorted');
192
272
  $this.addClass('sorted');
193
273
  }
194
274
 
@@ -206,4 +286,4 @@
206
286
  // Initialise on DOM ready
207
287
  $($.bootstrapSortable);
208
288
 
209
- }(jQuery));
289
+ }(jQuery));
@@ -1,4 +1,14 @@
1
- table.sortable span.sign {
1
+ /**
2
+ * adding sorting ability to HTML tables with Bootstrap styling
3
+ * @summary HTML tables sorting ability
4
+ * @version 2.0.0
5
+ * @requires tinysort, moment.js, jQuery
6
+ * @license MIT
7
+ * @author Matus Brlit (drvic10k)
8
+ * @copyright Matus Brlit (drvic10k), bootstrap-sortable contributors
9
+ */
10
+
11
+ table.sortable span.sign {
2
12
  display: block;
3
13
  position: absolute;
4
14
  top: 50%;
@@ -84,17 +94,17 @@ table.sortable span.month.up:before, th.month.up:after {
84
94
  content: "dec .. jan";
85
95
  }
86
96
 
87
- table.sortable thead th:not([data-defaultsort=disabled]) {
97
+ table.sortable>thead th:not([data-defaultsort=disabled]) {
88
98
  cursor: pointer;
89
99
  position: relative;
90
100
  top: 0;
91
101
  left: 0;
92
102
  }
93
103
 
94
- table.sortable thead th:hover:not([data-defaultsort=disabled]) {
104
+ table.sortable>thead th:hover:not([data-defaultsort=disabled]) {
95
105
  background: #efefef;
96
106
  }
97
107
 
98
- table.sortable thead th div.mozilla {
108
+ table.sortable>thead th div.mozilla {
99
109
  position: relative;
100
110
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamKelly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.4.5
99
+ rubygems_version: 2.5.1
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: A gem that packages the bootstrap-sortable js library from https://github.com/drvic10k/bootstrap-sortable