rails_bootstrap_sortable 1.9.0 → 1.10.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48f04380ee2cc19345a6e5a9227bb0503275a26a
|
4
|
+
data.tar.gz: f613f54e81e5fd52b0a8789d0b271087133c0faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361564163a278667e2e5c21603adf9d3f817febf0085b40c9c1b2f75e102aa0592863c87bf930d74c04ed36866e2fda2754ac0b2bcbde1d84498bb52f6be51fc
|
7
|
+
data.tar.gz: 47f979a70da9fa386f256b5e181e9a17a204f0b6293a4d027eb0777231678c27a33b88ed12a3430bf503598174d25f9ed71022847f83852bc17875ea2112af09
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# rails_bootstrap_sortable
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rails_bootstrap_sortable.svg)](http://badge.fury.io/rb/rails_bootstrap_sortable)
|
4
|
+
|
3
5
|
This gem packages the lovely bootstrap-sortable gem from [drvic10k/bootstrap-sortable](https://github.com/drvic10k/bootstrap-sortable) into an easy to use form. rails_bootstrap_sortable adds the ability to sort bootstrap tables (or any type of table, for that matter) via Javascript by clicking on the headers of the table. The bootstrap-sortable gem is © 2014 Matúš Brliť (drvic10k), bootstrap-sortable contributors.
|
4
6
|
|
5
7
|
## Installation
|
@@ -7,12 +9,14 @@ This gem packages the lovely bootstrap-sortable gem from [drvic10k/bootstrap-sor
|
|
7
9
|
Add these lines to your rails project's Gemfile:
|
8
10
|
|
9
11
|
gem 'momentjs-rails'
|
10
|
-
|
12
|
+
gem 'rails_bootstrap_sortable'
|
11
13
|
|
12
14
|
Install the new gems:
|
13
15
|
|
14
16
|
$ bundle install
|
15
17
|
|
18
|
+
(for more info see [rails_bootstrap_sortable on rubygems.org](https://rubygems.org/gems/rails_bootstrap_sortable))
|
19
|
+
|
16
20
|
Add this line to application.css.scss:
|
17
21
|
```
|
18
22
|
*= require bootstrap-sortable
|
@@ -4,8 +4,6 @@
|
|
4
4
|
(function ($) {
|
5
5
|
|
6
6
|
var $document = $(document),
|
7
|
-
bsSort = [],
|
8
|
-
lastSort,
|
9
7
|
signClass;
|
10
8
|
|
11
9
|
$.bootstrapSortable = function (applyLast, sign) {
|
@@ -18,13 +16,16 @@
|
|
18
16
|
|
19
17
|
// set attributes needed for sorting
|
20
18
|
$('table.sortable').each(function () {
|
21
|
-
var $this = $(this)
|
19
|
+
var $this = $(this),
|
20
|
+
context = lookupSortContext($this),
|
21
|
+
bsSort = context.bsSort;
|
22
22
|
applyLast = (applyLast === true);
|
23
23
|
$this.find('span.sign').remove();
|
24
24
|
$this.find('thead tr').each(function (rowIndex) {
|
25
25
|
var columnsSkipped = 0;
|
26
26
|
$(this).find('th').each(function (columnIndex) {
|
27
27
|
var $this = $(this);
|
28
|
+
$this.addClass('nosort').removeClass('up down');
|
28
29
|
$this.attr('data-sortcolumn', columnIndex + columnsSkipped);
|
29
30
|
$this.attr('data-sortkey', columnIndex + '-' + rowIndex);
|
30
31
|
if ($this.attr("colspan") !== undefined) {
|
@@ -46,7 +47,7 @@
|
|
46
47
|
var $sortTable = $this.closest('table.sortable');
|
47
48
|
$this.data('sortTable', $sortTable);
|
48
49
|
var sortKey = $this.attr('data-sortkey');
|
49
|
-
var thisLastSort = applyLast ? lastSort : -1;
|
50
|
+
var thisLastSort = applyLast ? context.lastSort : -1;
|
50
51
|
bsSort[sortKey] = applyLast ? bsSort[sortKey] : $this.attr('data-defaultsort');
|
51
52
|
if (bsSort[sortKey] !== undefined && (applyLast === (sortKey === thisLastSort))) {
|
52
53
|
bsSort[sortKey] = bsSort[sortKey] === 'asc' ? 'desc' : 'asc';
|
@@ -64,9 +65,22 @@
|
|
64
65
|
$table.trigger('sorted');
|
65
66
|
});
|
66
67
|
|
68
|
+
// Look up sorting data appropriate for the specified table (jQuery element).
|
69
|
+
// This allows multiple tables on one page without collisions.
|
70
|
+
function lookupSortContext($table) {
|
71
|
+
var context = $table.data("bootstrap-sortable-context");
|
72
|
+
if(context == null) {
|
73
|
+
context = { bsSort: [], lastSort: null };
|
74
|
+
$table.data("bootstrap-sortable-context", context);
|
75
|
+
}
|
76
|
+
return context;
|
77
|
+
}
|
78
|
+
|
67
79
|
//Sorting mechanism separated
|
68
80
|
function doSort($this, $table) {
|
69
|
-
var sortColumn = $this.attr('data-sortcolumn')
|
81
|
+
var sortColumn = $this.attr('data-sortcolumn'),
|
82
|
+
context = lookupSortContext($table),
|
83
|
+
bsSort = context.bsSort;
|
70
84
|
|
71
85
|
var colspan = $this.attr('colspan');
|
72
86
|
if (colspan) {
|
@@ -85,6 +99,10 @@
|
|
85
99
|
var localSignClass = $this.attr('data-defaultsign') || signClass;
|
86
100
|
|
87
101
|
// update arrow icon
|
102
|
+
$table.find('th').each(function() {
|
103
|
+
$(this).removeClass('up').removeClass('down').addClass('nosort');
|
104
|
+
});
|
105
|
+
|
88
106
|
if ($.browser.mozilla) {
|
89
107
|
var moz_arrow = $table.find('div.mozilla');
|
90
108
|
if (moz_arrow !== undefined) {
|
@@ -103,14 +121,19 @@
|
|
103
121
|
var sortKey = $this.attr('data-sortkey');
|
104
122
|
var initialDirection = $this.attr('data-firstsort') !== 'desc' ? 'desc' : 'asc';
|
105
123
|
|
106
|
-
lastSort = sortKey;
|
124
|
+
context.lastSort = sortKey;
|
107
125
|
bsSort[sortKey] = (bsSort[sortKey] || initialDirection) === 'asc' ? 'desc' : 'asc';
|
108
|
-
if (bsSort[sortKey] === 'desc') {
|
126
|
+
if (bsSort[sortKey] === 'desc') {
|
127
|
+
$this.find('span.sign').addClass('up');
|
128
|
+
$this.addClass('up').removeClass('down nosort');
|
129
|
+
} else {
|
130
|
+
$this.addClass('down').removeClass('up nosort');
|
131
|
+
}
|
109
132
|
|
110
133
|
// sort rows
|
111
134
|
var rows = $table.children('tbody').children('tr');
|
112
135
|
rows.tsort('td:eq(' + sortColumn + ')', { order: bsSort[sortKey], attr: 'data-value' });
|
113
|
-
|
136
|
+
|
114
137
|
// add class to sorted column cells
|
115
138
|
$table.find('td.sorted, th.sorted').removeClass('sorted');
|
116
139
|
rows.find('td:eq(' + sortColumn + ')').addClass('sorted');
|
@@ -1,4 +1,4 @@
|
|
1
|
-
table.sortable span.sign {
|
1
|
+
table.sortable span.sign {
|
2
2
|
display: block;
|
3
3
|
position: absolute;
|
4
4
|
top: 50%;
|
@@ -8,7 +8,21 @@ table.sortable span.sign {
|
|
8
8
|
color: #bfbfc1;
|
9
9
|
}
|
10
10
|
|
11
|
-
table.sortable
|
11
|
+
table.sortable th:after {
|
12
|
+
display: block;
|
13
|
+
position: absolute;
|
14
|
+
top: 50%;
|
15
|
+
right: 5px;
|
16
|
+
font-size: 12px;
|
17
|
+
margin-top: -10px;
|
18
|
+
color: #bfbfc1;
|
19
|
+
}
|
20
|
+
|
21
|
+
table.sortable th.arrow:after {
|
22
|
+
content: '';
|
23
|
+
}
|
24
|
+
|
25
|
+
table.sortable span.arrow, span.reversed, th.arrow.down:after, th.reversedarrow.down:after, th.arrow.up:after, th.reversedarrow.up:after {
|
12
26
|
border-style: solid;
|
13
27
|
border-width: 5px;
|
14
28
|
font-size: 0;
|
@@ -19,52 +33,54 @@ table.sortable span.arrow, span.reversed {
|
|
19
33
|
margin-top: -2px;
|
20
34
|
}
|
21
35
|
|
22
|
-
table.sortable span.arrow.up {
|
36
|
+
table.sortable span.arrow.up, th.arrow.up:after {
|
23
37
|
border-color: transparent transparent #ccc transparent;
|
24
38
|
margin-top: -7px;
|
25
39
|
}
|
26
40
|
|
27
|
-
table.sortable span.reversed {
|
41
|
+
table.sortable span.reversed, th.reversedarrow.down:after {
|
28
42
|
border-color: transparent transparent #ccc transparent;
|
29
43
|
margin-top: -7px;
|
30
44
|
}
|
31
45
|
|
32
|
-
table.sortable span.reversed.up {
|
46
|
+
table.sortable span.reversed.up, th.reversedarrow.up:after {
|
33
47
|
border-color: #ccc transparent transparent transparent;
|
34
48
|
margin-top: -2px;
|
35
49
|
}
|
36
50
|
|
37
|
-
|
38
|
-
|
39
|
-
table.sortable span.az:before {
|
51
|
+
table.sortable span.az:before, th.az.down:after {
|
40
52
|
content: "a .. z";
|
41
53
|
}
|
42
54
|
|
43
|
-
table.sortable span.az.up:before {
|
55
|
+
table.sortable span.az.up:before, th.az.up:after {
|
44
56
|
content: "z .. a";
|
45
57
|
}
|
46
58
|
|
47
|
-
table.sortable
|
59
|
+
table.sortable th.az.nosort:after, th.AZ.nosort:after, th._19.nosort:after, th.month.nosort:after {
|
60
|
+
content: "..";
|
61
|
+
}
|
62
|
+
|
63
|
+
table.sortable span.AZ:before, th.AZ.down:after {
|
48
64
|
content: "A .. Z";
|
49
65
|
}
|
50
66
|
|
51
|
-
table.sortable span.AZ.up:before {
|
67
|
+
table.sortable span.AZ.up:before, th.AZ.up:after {
|
52
68
|
content: "Z .. A";
|
53
69
|
}
|
54
70
|
|
55
|
-
table.sortable span._19:before {
|
71
|
+
table.sortable span._19:before, th._19.down:after {
|
56
72
|
content: "1 .. 9";
|
57
73
|
}
|
58
74
|
|
59
|
-
table.sortable span._19.up:before {
|
75
|
+
table.sortable span._19.up:before, th._19.up:after {
|
60
76
|
content: "9 .. 1";
|
61
77
|
}
|
62
78
|
|
63
|
-
table.sortable span.month:before {
|
79
|
+
table.sortable span.month:before, th.month.down:after {
|
64
80
|
content: "jan .. dec";
|
65
81
|
}
|
66
82
|
|
67
|
-
table.sortable span.month.up:before {
|
83
|
+
table.sortable span.month.up:before, th.month.up:after {
|
68
84
|
content: "dec .. jan";
|
69
85
|
}
|
70
86
|
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
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.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SamKelly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: momentjs-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.8.3
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.8.3
|
55
55
|
description: ''
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.md
|
65
65
|
- README.md
|
@@ -79,12 +79,12 @@ require_paths:
|
|
79
79
|
- lib
|
80
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|