rails_bootstrap_sortable 1.10.1 → 1.11.1
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a88c8537f2ba2e7ef823f56465a0a131b99cd02
|
|
4
|
+
data.tar.gz: 0c0b825fa4fd8b19cd5980c2936baebb4ccef54c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2fefa1ccb034b8583acd7dd13e422b8fd9310f39ff0f2f1ecac03105b630aa85efd72969f283eb0478284f3f92d0010dbb88e5b436f42df296eb7ca00833ce7f
|
|
7
|
+
data.tar.gz: 8977f4985dee38201897227d43a62d421f94fcdb507055757c75f87379bfe861c15b9ce067ef1514f98596f873509058fd27b21de1a594db5e7a230d016af4c7
|
|
@@ -1,38 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
|
88
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
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.
|
|
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-
|
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|