rails_bootstrap_sortable 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5c053a0039eb7a0e19fd7de2964fa928635a0c6
4
+ data.tar.gz: 2cc7d7fdda3ede56c90d9e939f9d86a60106a694
5
+ SHA512:
6
+ metadata.gz: 84500fc60d7687a6240ec937966481f83aec09d0149484cab75a8a84d8f1b2cc055a929f5bf03f41320c2801294dd09763e220651ecf2a2d76ea3c1438ae858c
7
+ data.tar.gz: 2b3f1104ff420ec2d87e3cf46be2392e9c60507a277deb8380cf02cd58596a2f3ad99bc0abc0b40a0f37287ceb5e23154d9e73b0e7f3738be2616b0c6720e6b8
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_bootstrap_sortable.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2014 Sam Kelly, bootstrap-sortable_rails contributors
2
+
3
+ Copyright (c) 2014 Matúš Brliť (drvic10k), bootstrap-sortable contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # rails_bootstrap_sortable
2
+
3
+ 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
+
5
+ ## Installation
6
+
7
+ Add these lines to your rails project's Gemfile:
8
+
9
+ gem 'momentjs-rails'
10
+ gem 'rails_bootstrap_sortable'
11
+
12
+ Install the new gems:
13
+
14
+ $ bundle install
15
+
16
+ Add this line to application.css.scss:
17
+ ```
18
+ *= require bootstrap-sortable
19
+ ```
20
+
21
+ Add these lines to application.js.coffee:
22
+
23
+ //= require moment
24
+ //= require bootstrap-sortable
25
+
26
+ ## Usage
27
+
28
+ Please see [dvic10k/bootstrap-sortable](https://github.com/drvic10k/bootstrap-sortable) for full usage information.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ require "rails_bootstrap_sortable/version"
2
+
3
+ module RailsBootstrapSortable
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module RailsBootstrapSortable
2
+ VERSION = "1.9.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_bootstrap_sortable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_bootstrap_sortable"
8
+ spec.version = RailsBootstrapSortable::VERSION
9
+ spec.authors = ["SamKelly"]
10
+ spec.email = ["sam@durosoft.com"]
11
+ spec.summary = %q{A gem that packages the bootstrap-sortable js library from https://github.com/drvic10k/bootstrap-sortable}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/SamKelly/rails_bootstrap_sortable"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_dependency "momentjs-rails", "~> 2.8.3"
22
+ end
@@ -0,0 +1,134 @@
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);
3
+
4
+ (function ($) {
5
+
6
+ var $document = $(document),
7
+ bsSort = [],
8
+ lastSort,
9
+ signClass;
10
+
11
+ $.bootstrapSortable = function (applyLast, sign) {
12
+
13
+ // check if moment.js is available
14
+ var momentJsAvailable = (typeof moment !== 'undefined');
15
+
16
+ //Set class based on sign parameter
17
+ signClass = !sign ? "arrow" : sign;
18
+
19
+ // set attributes needed for sorting
20
+ $('table.sortable').each(function () {
21
+ var $this = $(this);
22
+ applyLast = (applyLast === true);
23
+ $this.find('span.sign').remove();
24
+ $this.find('thead tr').each(function (rowIndex) {
25
+ var columnsSkipped = 0;
26
+ $(this).find('th').each(function (columnIndex) {
27
+ var $this = $(this);
28
+ $this.attr('data-sortcolumn', columnIndex + columnsSkipped);
29
+ $this.attr('data-sortkey', columnIndex + '-' + rowIndex);
30
+ if ($this.attr("colspan") !== undefined) {
31
+ columnsSkipped += parseInt($this.attr("colspan")) - 1;
32
+ }
33
+ });
34
+ });
35
+ $this.find('td').each(function () {
36
+ var $this = $(this);
37
+ if ($this.attr('data-dateformat') !== undefined && momentJsAvailable) {
38
+ $this.attr('data-value', moment($this.text(), $this.attr('data-dateformat')).format('YYYY/MM/DD/HH/mm/ss'));
39
+ }
40
+ else {
41
+ $this.attr('data-value') === undefined && $this.attr('data-value', $this.text());
42
+ }
43
+ });
44
+ $this.find('thead th[data-defaultsort!="disabled"]').each(function (index) {
45
+ var $this = $(this);
46
+ var $sortTable = $this.closest('table.sortable');
47
+ $this.data('sortTable', $sortTable);
48
+ var sortKey = $this.attr('data-sortkey');
49
+ var thisLastSort = applyLast ? lastSort : -1;
50
+ bsSort[sortKey] = applyLast ? bsSort[sortKey] : $this.attr('data-defaultsort');
51
+ if (bsSort[sortKey] !== undefined && (applyLast === (sortKey === thisLastSort))) {
52
+ bsSort[sortKey] = bsSort[sortKey] === 'asc' ? 'desc' : 'asc';
53
+ doSort($this, $sortTable);
54
+ }
55
+ });
56
+ $this.trigger('sorted');
57
+ });
58
+ };
59
+
60
+ // add click event to table header
61
+ $document.on('click', 'table.sortable thead th[data-defaultsort!="disabled"]', function (e) {
62
+ var $this = $(this), $table = $this.data('sortTable') || $this.closest('table.sortable');
63
+ doSort($this, $table);
64
+ $table.trigger('sorted');
65
+ });
66
+
67
+ //Sorting mechanism separated
68
+ function doSort($this, $table) {
69
+ var sortColumn = $this.attr('data-sortcolumn');
70
+
71
+ var colspan = $this.attr('colspan');
72
+ if (colspan) {
73
+ var selector;
74
+ for (var i = parseFloat(sortColumn) ; i < parseFloat(sortColumn) + parseFloat(colspan) ; i++) {
75
+ selector = selector + ', [data-sortcolumn="' + i + '"]';
76
+ }
77
+ var subHeader = $(selector).not('[colspan]');
78
+ var mainSort = subHeader.filter('[data-mainsort]').eq(0);
79
+
80
+ sortColumn = mainSort.length ? mainSort : subHeader.eq(0);
81
+ doSort(sortColumn, $table);
82
+ return;
83
+ }
84
+
85
+ var localSignClass = $this.attr('data-defaultsign') || signClass;
86
+
87
+ // update arrow icon
88
+ if ($.browser.mozilla) {
89
+ var moz_arrow = $table.find('div.mozilla');
90
+ if (moz_arrow !== undefined) {
91
+ moz_arrow.find('.sign').remove();
92
+ moz_arrow.parent().html(moz_arrow.html());
93
+ }
94
+ $this.wrapInner('<div class="mozilla"></div>');
95
+ $this.children().eq(0).append('<span class="sign ' + localSignClass + '"></span>');
96
+ }
97
+ else {
98
+ $table.find('span.sign').remove();
99
+ $this.append('<span class="sign ' + localSignClass + '"></span>');
100
+ }
101
+
102
+ // sort direction
103
+ var sortKey = $this.attr('data-sortkey');
104
+ var initialDirection = $this.attr('data-firstsort') !== 'desc' ? 'desc' : 'asc';
105
+
106
+ lastSort = sortKey;
107
+ bsSort[sortKey] = (bsSort[sortKey] || initialDirection) === 'asc' ? 'desc' : 'asc';
108
+ if (bsSort[sortKey] === 'desc') { $this.find('span.sign').addClass('up'); }
109
+
110
+ // sort rows
111
+ var rows = $table.children('tbody').children('tr');
112
+ rows.tsort('td:eq(' + sortColumn + ')', { order: bsSort[sortKey], attr: 'data-value' });
113
+
114
+ // add class to sorted column cells
115
+ $table.find('td.sorted, th.sorted').removeClass('sorted');
116
+ rows.find('td:eq(' + sortColumn + ')').addClass('sorted');
117
+ $this.addClass('sorted');
118
+ }
119
+
120
+ // jQuery 1.9 removed this object
121
+ if (!$.browser) {
122
+ $.browser = { chrome: false, mozilla: false, opera: false, msie: false, safari: false };
123
+ var ua = navigator.userAgent;
124
+ $.each($.browser, function (c) {
125
+ $.browser[c] = ((new RegExp(c, 'i').test(ua))) ? true : false;
126
+ if ($.browser.mozilla && c === 'mozilla') { $.browser.mozilla = ((new RegExp('firefox', 'i').test(ua))) ? true : false; }
127
+ if ($.browser.chrome && c === 'safari') { $.browser.safari = false; }
128
+ });
129
+ }
130
+
131
+ // Initialise on DOM ready
132
+ $($.bootstrapSortable);
133
+
134
+ }(jQuery));
@@ -0,0 +1,84 @@
1
+ table.sortable span.sign {
2
+ display: block;
3
+ position: absolute;
4
+ top: 50%;
5
+ right: 5px;
6
+ font-size: 12px;
7
+ margin-top: -10px;
8
+ color: #bfbfc1;
9
+ }
10
+
11
+ table.sortable span.arrow, span.reversed {
12
+ border-style: solid;
13
+ border-width: 5px;
14
+ font-size: 0;
15
+ border-color: #ccc transparent transparent transparent;
16
+ line-height: 0;
17
+ height: 0;
18
+ width: 0;
19
+ margin-top: -2px;
20
+ }
21
+
22
+ table.sortable span.arrow.up {
23
+ border-color: transparent transparent #ccc transparent;
24
+ margin-top: -7px;
25
+ }
26
+
27
+ table.sortable span.reversed {
28
+ border-color: transparent transparent #ccc transparent;
29
+ margin-top: -7px;
30
+ }
31
+
32
+ table.sortable span.reversed.up {
33
+ border-color: #ccc transparent transparent transparent;
34
+ margin-top: -2px;
35
+ }
36
+
37
+
38
+
39
+ table.sortable span.az:before {
40
+ content: "a .. z";
41
+ }
42
+
43
+ table.sortable span.az.up:before {
44
+ content: "z .. a";
45
+ }
46
+
47
+ table.sortable span.AZ:before {
48
+ content: "A .. Z";
49
+ }
50
+
51
+ table.sortable span.AZ.up:before {
52
+ content: "Z .. A";
53
+ }
54
+
55
+ table.sortable span._19:before {
56
+ content: "1 .. 9";
57
+ }
58
+
59
+ table.sortable span._19.up:before {
60
+ content: "9 .. 1";
61
+ }
62
+
63
+ table.sortable span.month:before {
64
+ content: "jan .. dec";
65
+ }
66
+
67
+ table.sortable span.month.up:before {
68
+ content: "dec .. jan";
69
+ }
70
+
71
+ table.sortable thead th:not([data-defaultsort=disabled]) {
72
+ cursor: pointer;
73
+ position: relative;
74
+ top: 0;
75
+ left: 0;
76
+ }
77
+
78
+ table.sortable thead th:hover:not([data-defaultsort=disabled]) {
79
+ background: #efefef;
80
+ }
81
+
82
+ table.sortable thead th div.mozilla {
83
+ position: relative;
84
+ }
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_bootstrap_sortable
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.0
5
+ platform: ruby
6
+ authors:
7
+ - SamKelly
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: momentjs-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.8.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.3
55
+ description: ''
56
+ email:
57
+ - sam@durosoft.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.md
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rails_bootstrap_sortable.rb
68
+ - lib/rails_bootstrap_sortable/version.rb
69
+ - rails_bootstrap_sortable.gemspec
70
+ - vendor/assets/javascripts/bootstrap-sortable.js
71
+ - vendor/assets/stylesheets/bootstrap-sortable.css
72
+ homepage: https://github.com/SamKelly/rails_bootstrap_sortable
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A gem that packages the bootstrap-sortable js library from https://github.com/drvic10k/bootstrap-sortable
96
+ test_files: []