rails_bootstrap_sortable 1.10.1 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80aa2b027e8a10843058a7c38c9ce1078c06821f
4
- data.tar.gz: 22934f38a1b0f47c974aea559ebf6572fedb2c9d
3
+ metadata.gz: 3a88c8537f2ba2e7ef823f56465a0a131b99cd02
4
+ data.tar.gz: 0c0b825fa4fd8b19cd5980c2936baebb4ccef54c
5
5
  SHA512:
6
- metadata.gz: 04a2429a70592cb85df5893908f449c017d638e702f5384b65cf7b119de7f966f47a5b442a8496491097e7cfe199f1e8878f996fc725bf0457d06c891cd1c9b6
7
- data.tar.gz: 60608feafe2b84c794ff84cfe91a747091037524b920f78aa1cf4279bde447d644e0eaa1fa5203c6f70753d180b3a3d989e88104ef6cc6973edb0376f95acf0d
6
+ metadata.gz: 2fefa1ccb034b8583acd7dd13e422b8fd9310f39ff0f2f1ecac03105b630aa85efd72969f283eb0478284f3f92d0010dbb88e5b436f42df296eb7ca00833ce7f
7
+ data.tar.gz: 8977f4985dee38201897227d43a62d421f94fcdb507055757c75f87379bfe861c15b9ce067ef1514f98596f873509058fd27b21de1a594db5e7a230d016af4c7
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapSortable
2
- VERSION = "1.10.1"
2
+ VERSION = "1.11.1"
3
3
  end
@@ -1,38 +1,72 @@
1
- /* TINY SORT modified according to this https://github.com/Sjeiti/TinySort/pull/51*/
2
- (function (e, t) { function h(e) { return e && e.toLowerCase ? e.toLowerCase() : e } function p(e, t) { for (var r = 0, i = e.length; r < i; r++) if (e[r] == t) return !n; return n } var n = !1, r = null, i = parseFloat, s = Math.min, o = /(-?\d+\.?\d*)$/g, u = /(\d+\.?\d*)$/g, a = [], f = [], l = function (e) { return typeof e == "string" }, c = Array.prototype.indexOf || function (e) { var t = this.length, n = Number(arguments[1]) || 0; n = n < 0 ? Math.ceil(n) : Math.floor(n); if (n < 0) n += t; for (; n < t; n++) { if (n in this && this[n] === e) return n } return -1 }; e.tinysort = { id: "TinySort", version: "1.5.2", copyright: "Copyright (c) 2008-2013 Ron Valstar", uri: "http://tinysort.sjeiti.com/", licensed: { MIT: "http://www.opensource.org/licenses/mit-license.php", GPL: "http://www.gnu.org/licenses/gpl.html" }, plugin: function () { var e = function (e, t) { a.push(e); f.push(t) }; e.indexOf = c; return e }(), defaults: { order: "asc", attr: r, data: r, useVal: n, place: "start", returns: n, cases: n, forceStrings: n, ignoreDashes: n, sortFunction: r } }; e.fn.extend({ tinysort: function () { var d, v, m = this, g = [], y = [], b = [], w = [], E = 0, S, x = [], T = [], N = function (t) { e.each(a, function (e, n) { n.call(n, t) }) }, C = function (t, r) { var s = 0; if (E !== 0) E = 0; while (s === 0 && E < S) { var a = w[E], c = a.oSettings, p = c.ignoreDashes ? u : o; N(c); if (c.sortFunction) { s = c.sortFunction(t, r) } else if (c.order == "rand") { s = Math.random() < .5 ? 1 : -1 } else { var d = n, v = !c.cases ? h(t.s[E]) : t.s[E], m = !c.cases ? h(r.s[E]) : r.s[E]; v = v.replace(/^\s*/i, "").replace(/\s*$/i, ""); m = m.replace(/^\s*/i, "").replace(/\s*$/i, ""); if (!A.forceStrings) { var g = l(v) ? v && v.match(p) : n, y = l(m) ? m && m.match(p) : n; if (g && y) { var b = v.substr(0, v.length - g[0].length), x = m.substr(0, m.length - y[0].length); if (b == x) { d = !n; v = i(g[0]); m = i(y[0]) } } } s = a.iAsc * (v < m ? -1 : v > m ? 1 : 0) } e.each(f, function (e, t) { s = t.call(t, d, v, m, s) }); if (s === 0) E++ } return s }; for (d = 0, v = arguments.length; d < v; d++) { var k = arguments[d]; if (l(k)) { if (x.push(k) - 1 > T.length) T.length = x.length - 1 } else { if (T.push(k) > x.length) x.length = T.length } } if (x.length > T.length) T.length = x.length; S = x.length; if (S === 0) { S = x.length = 1; T.push({}) } for (d = 0, v = S; d < v; d++) { var L = x[d], A = e.extend({}, e.tinysort.defaults, T[d]), O = !(!L || L == ""), M = O && L[0] == ":"; w.push({ sFind: L, oSettings: A, bFind: O, bAttr: !(A.attr === r || A.attr == ""), bData: A.data !== r, bFilter: M, $Filter: M ? m.filter(L) : m, fnSort: A.sortFunction, iAsc: A.order == "asc" ? 1 : -1 }) } m.each(function (n, r) { var i = e(r), s = i.parent().get(0), o, u = []; for (j = 0; j < S; j++) { var a = w[j], f = a.bFind ? a.bFilter ? a.$Filter.filter(r) : i.find(a.sFind) : i; u.push(a.bData ? f.data(a.oSettings.data) : a.bAttr ? f.attr(a.oSettings.attr) : a.oSettings.useVal ? f.val() : f.text()); if (o === t) o = f } var l = c.call(b, s); if (l < 0) { l = b.push(s) - 1; y[l] = { s: [], n: [] } } if (o.length > 0) y[l].s.push({ s: u, e: i, n: n }); else y[l].n.push({ e: i, n: n }) }); e.each(y, function (e, t) { t.s.sort(C) }); e.each(y, function (t, r) { var i = r.s.length, o = [], u = i, a = [0, 0]; switch (A.place) { case "first": e.each(r.s, function (e, t) { u = s(u, t.n) }); break; case "org": e.each(r.s, function (e, t) { o.push(t.n) }); break; case "end": u = r.n.length; break; default: u = 0 } for (d = 0; d < i; d++) { var f = p(o, d) ? !n : d >= u && d < u + r.s.length, l = (f ? r.s : r.n)[a[f ? 0 : 1]].e; l.parent().append(l); if (f || !A.returns) g.push(l.get(0)); a[f ? 0 : 1]++ } }); m.length = 0; Array.prototype.push.apply(m, g); return m } }); e.fn.TinySort = e.fn.Tinysort = e.fn.tsort = e.fn.tinysort })(jQuery);
1
+ /*! tinysort.js
2
+ * version: 2.1.1
3
+ * author: Ron Valstar (http://www.sjeiti.com/)
4
+ * license: MIT/GPL
5
+ * build: 2015-01-05
6
+ */
7
+ !function (a, b) { "use strict"; function c() { return b } "function" == typeof define && define.amd ? define("tinysort", c) : a.tinysort = b }(this, function () { "use strict"; function a(a) { function f() { 0 === arguments.length ? j({}) : d(arguments, function (a) { j(c(a) ? { selector: a } : a) }), q = C.length } function j(a) { var b = !!a.selector, c = b && ":" === a.selector[0], d = e(a || {}, t); C.push(e({ bFind: b, bAttr: !(d.attr === i || "" === d.attr), bData: d.data !== i, bFilter: c, mFilter: i, fnSort: d.sortFunction, iAsc: "asc" === d.order ? 1 : -1 }, d)) } function m() { d(a, function (a, b) { x ? x !== a.parentNode && (D = !1) : x = a.parentNode; var c = C[0], d = c.bFilter, e = c.selector, f = !e || d && a.matchesSelector(e) || e && a.querySelector(e), g = f ? A : B, h = { elm: a, pos: b, posn: g.length }; z.push(h), g.push(h) }), w = A.slice(0) } function s() { A.sort(u) } function u(a, e) { var f = 0; for (0 !== r && (r = 0) ; 0 === f && q > r;) { var i = C[r], j = i.ignoreDashes ? o : n; if (d(p, function (a) { var b = a.prepare; b && b(i) }), i.sortFunction) f = i.sortFunction(a, e); else if ("rand" == i.order) f = Math.random() < .5 ? 1 : -1; else { var k = h, m = b(a, i), s = b(e, i); if (!i.forceStrings) { var t = c(m) ? m && m.match(j) : h, u = c(s) ? s && s.match(j) : h; if (t && u) { var v = m.substr(0, m.length - t[0].length), w = s.substr(0, s.length - u[0].length); v == w && (k = !h, m = l(t[0]), s = l(u[0])) } } f = m === g || s === g ? 0 : i.iAsc * (s > m ? -1 : m > s ? 1 : 0) } d(p, function (a) { var b = a.sort; b && (f = b(i, k, m, s, f)) }), 0 === f && r++ } return 0 === f && (f = a.pos > e.pos ? 1 : -1), f } function v() { var a = A.length === z.length; D && a ? (A.forEach(function (a) { y.appendChild(a.elm) }), x.appendChild(y)) : (A.forEach(function (a) { var b = a.elm, c = k.createElement("div"); a.ghost = c, b.parentNode.insertBefore(c, b) }), A.forEach(function (a, b) { var c = w[b].ghost; c.parentNode.insertBefore(a.elm, c), c.parentNode.removeChild(c) })) } c(a) && (a = k.querySelectorAll(a)), 0 === a.length && console.warn("No elements to sort"); var w, x, y = k.createDocumentFragment(), z = [], A = [], B = [], C = [], D = !0; return f.apply(i, Array.prototype.slice.call(arguments, 1)), m(), s(), v(), A.map(function (a) { return a.elm }) } function b(a, b) { var d, e = a.elm; return b.selector && (b.bFilter ? e.matchesSelector(b.selector) || (e = i) : e = e.querySelector(b.selector)), b.bAttr ? d = e.getAttribute(b.attr) : b.useVal ? d = e.value : b.bData ? d = e.getAttribute("data-" + b.data) : e && (d = e.textContent), c(d) && (b.cases || (d = d.toLowerCase()), d = d.replace(/\s+/g, " ")), d } function c(a) { return "string" == typeof a } function d(a, b) { for (var c, d = a.length, e = d; e--;) c = d - e - 1, b(a[c], c) } function e(a, b, c) { for (var d in b) (c || a[d] === g) && (a[d] = b[d]); return a } function f(a, b, c) { p.push({ prepare: a, sort: b, sortBy: c }) } var g, h = !1, i = null, j = window, k = j.document, l = parseFloat, m = Array.prototype.indexOf, n = /(-?\d+\.?\d*)$/g, o = /(\d+\.?\d*)$/g, p = [], q = 0, r = 0, s = "2.1.0", t = { selector: i, order: "asc", attr: i, data: i, useVal: h, place: "start", returns: h, cases: h, forceStrings: h, ignoreDashes: h, sortFunction: i }; return j.Element && function (a) { a.matchesSelector = a.matchesSelector || a.mozMatchesSelector || a.msMatchesSelector || a.oMatchesSelector || a.webkitMatchesSelector || function (a) { for (var b = this, c = (b.parentNode || b.document).querySelectorAll(a), d = -1; c[++d] && c[d] != b;); return !!c[d] } }(Element.prototype), e(f, { indexOf: m, loop: d }), e(a, { plugin: f, version: s, defaults: t }) }());
3
8
 
4
9
  (function ($) {
5
10
 
6
11
  var $document = $(document),
7
- signClass;
12
+ signClass,
13
+ sortEngine;
8
14
 
9
- $.bootstrapSortable = function (applyLast, sign) {
15
+ $.bootstrapSortable = function (applyLast, sign, customSort) {
10
16
 
11
- // check if moment.js is available
17
+ // Check if moment.js is available
12
18
  var momentJsAvailable = (typeof moment !== 'undefined');
13
19
 
14
- //Set class based on sign parameter
20
+ // Set class based on sign parameter
15
21
  signClass = !sign ? "arrow" : sign;
16
22
 
17
- // set attributes needed for sorting
23
+ // Set sorting algorithm
24
+ if (customSort == 'default')
25
+ customSort = defaultSortEngine;
26
+ sortEngine = customSort || sortEngine || defaultSortEngine;
27
+
28
+ // Set attributes needed for sorting
18
29
  $('table.sortable').each(function () {
19
30
  var $this = $(this),
20
31
  context = lookupSortContext($this),
21
32
  bsSort = context.bsSort;
22
33
  applyLast = (applyLast === true);
23
34
  $this.find('span.sign').remove();
35
+
36
+ // Add placeholder cells for colspans
37
+ $this.find('thead [colspan]').each(function () {
38
+ var colspan = parseFloat($(this).attr('colspan'));
39
+ for (var i = 1; i < colspan; i++) {
40
+ $(this).after('<th class="colspan-compensate">');
41
+ }
42
+ });
43
+
44
+ // Add placeholder cells for rowspans
45
+ $this.find('thead [rowspan]').each(function () {
46
+ var $cell = $(this);
47
+ var rowspan = parseFloat($cell.attr('rowspan'));
48
+ for (var i = 1; i < rowspan; i++) {
49
+ var parentRow = $cell.parent('tr');
50
+ var nextRow = parentRow.next('tr');
51
+ var index = parentRow.children().index($cell);
52
+ nextRow.children().eq(index).before('<th class="rowspan-compensate">');
53
+ }
54
+ });
55
+
56
+ // Set indexes to header cells
24
57
  $this.find('thead tr').each(function (rowIndex) {
25
- var columnsSkipped = 0;
26
58
  $(this).find('th').each(function (columnIndex) {
27
59
  var $this = $(this);
28
60
  $this.addClass('nosort').removeClass('up down');
29
- $this.attr('data-sortcolumn', columnIndex + columnsSkipped);
61
+ $this.attr('data-sortcolumn', columnIndex);
30
62
  $this.attr('data-sortkey', columnIndex + '-' + rowIndex);
31
- if ($this.attr("colspan") !== undefined) {
32
- columnsSkipped += parseInt($this.attr("colspan")) - 1;
33
- }
34
63
  });
35
64
  });
65
+
66
+ // Cleanup placeholder cells
67
+ $this.find('thead .rowspan-compensate, .colspan-compensate').remove();
68
+
69
+ // Initialize sorting values
36
70
  $this.find('td').each(function () {
37
71
  var $this = $(this);
38
72
  if ($this.attr('data-dateformat') !== undefined && momentJsAvailable) {
@@ -58,9 +92,10 @@
58
92
  });
59
93
  };
60
94
 
61
- // add click event to table header
95
+ // Add click event to table header
62
96
  $document.on('click', 'table.sortable thead th[data-defaultsort!="disabled"]', function (e) {
63
97
  var $this = $(this), $table = $this.data('sortTable') || $this.closest('table.sortable');
98
+ $table.trigger('before-sort');
64
99
  doSort($this, $table);
65
100
  $table.trigger('sorted');
66
101
  });
@@ -69,37 +104,41 @@
69
104
  // This allows multiple tables on one page without collisions.
70
105
  function lookupSortContext($table) {
71
106
  var context = $table.data("bootstrap-sortable-context");
72
- if(context == null) {
107
+ if (context == null) {
73
108
  context = { bsSort: [], lastSort: null };
74
109
  $table.data("bootstrap-sortable-context", context);
75
110
  }
76
111
  return context;
77
112
  }
78
113
 
79
- //Sorting mechanism separated
114
+ function defaultSortEngine(rows, sortingParams) {
115
+ tinysort(rows, sortingParams);
116
+ }
117
+
118
+ // Sorting mechanism separated
80
119
  function doSort($this, $table) {
81
- var sortColumn = $this.attr('data-sortcolumn'),
120
+ var sortColumn = parseFloat($this.attr('data-sortcolumn')),
82
121
  context = lookupSortContext($table),
83
122
  bsSort = context.bsSort;
84
123
 
85
124
  var colspan = $this.attr('colspan');
86
125
  if (colspan) {
87
- var selector;
88
- for (var i = parseFloat(sortColumn) ; i < parseFloat(sortColumn) + parseFloat(colspan) ; i++) {
89
- selector = selector + ', [data-sortcolumn="' + i + '"]';
90
- }
91
- var subHeader = $(selector).not('[colspan]');
92
- var mainSort = subHeader.filter('[data-mainsort]').eq(0);
126
+ var mainSort = Math.min(colspan - 1, parseFloat($this.data('mainsort')) || 0);
127
+ var rowIndex = parseFloat($this.data('sortkey').split('-').pop());
93
128
 
94
- sortColumn = mainSort.length ? mainSort : subHeader.eq(0);
95
- doSort(sortColumn, $table);
96
- return;
129
+ // If there is one more row in header, delve deeper
130
+ if ($table.find('thead tr').length - 1 > rowIndex) {
131
+ doSort($table.find('[data-sortkey="' + (sortColumn + mainSort) + '-' + (rowIndex + 1) + '"]'), $table);
132
+ return;
133
+ }
134
+ // Otherwise, just adjust the sortColumn
135
+ sortColumn = sortColumn + mainSort;
97
136
  }
98
137
 
99
138
  var localSignClass = $this.attr('data-defaultsign') || signClass;
100
139
 
101
140
  // update arrow icon
102
- $table.find('th').each(function() {
141
+ $table.find('th').each(function () {
103
142
  $(this).removeClass('up').removeClass('down').addClass('nosort');
104
143
  });
105
144
 
@@ -132,7 +171,7 @@
132
171
 
133
172
  // sort rows
134
173
  var rows = $table.children('tbody').children('tr');
135
- rows.tsort('td:eq(' + sortColumn + ')', { order: bsSort[sortKey], attr: 'data-value' });
174
+ sortEngine(rows, { selector: 'td:nth-child(' + (sortColumn + 1) + ')', order: bsSort[sortKey], data: 'value' });
136
175
 
137
176
  // add class to sorted column cells
138
177
  $table.find('td.sorted, th.sorted').removeClass('sorted');
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.10.1
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamKelly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler