foo_table-rails 0.5.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.
@@ -0,0 +1,128 @@
1
+ (function ($, w, undefined) {
2
+ if (w.footable == undefined || w.footable == null)
3
+ throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
4
+
5
+ var defaults = {
6
+ paginate: true,
7
+ pageSize: 10,
8
+ pageNavigation: '.footable-nav'
9
+ };
10
+
11
+ function pageInfo(ft) {
12
+ var $table = $(ft.table), $tbody = $table.find('> tbody');
13
+ this.pageNavigation = $table.data('page-navigation') || ft.options.pageNavigation;
14
+ this.pageSize = $table.data('page-size') || ft.options.pageSize;
15
+ this.currentPage = 0;
16
+ this.pages = [];
17
+ };
18
+
19
+ function Paginate() {
20
+ var p = this;
21
+ p.name = 'Footable Paginate';
22
+
23
+ p.init = function (ft) {
24
+ if (ft.options.paginate == true) {
25
+ var $table = $(ft.table), $tbody = $table.find('> tbody');
26
+ $(ft.table).bind({
27
+ 'footable_initialized': function (e) {
28
+ e.ft.pageInfo = new pageInfo(e.ft);
29
+ var $table = $(e.ft.table), $tbody = $table.find('> tbody');
30
+ p.createPages(e.ft, $tbody);
31
+ p.createNavigation(e.ft, $tbody);
32
+ p.fillPage(e.ft, $tbody, 0);
33
+ },
34
+ 'footable_sorted': function (e) {
35
+ var $tbody = $(e.ft.table).find('> tbody');
36
+ p.createPages(e.ft, $tbody);
37
+ p.fillPage(e.ft, $tbody, e.ft.pageInfo.currentPage);
38
+ },
39
+ 'footable_filtered': function (e) {
40
+ var $tbody = $(e.ft.table).find('> tbody');
41
+ p.createPages(e.ft, $tbody);
42
+ p.createNavigation(e.ft, $tbody);
43
+ p.fillPage(e.ft, $tbody, e.ft.pageInfo.currentPage);
44
+ }
45
+ });
46
+ }
47
+ };
48
+
49
+ p.createPages = function (ft, tbody) {
50
+ var pages = 1;
51
+ var info = ft.pageInfo;
52
+ var pageCount = pages * info.pageSize;
53
+ var page = [];
54
+ var lastPage = [];
55
+ info.pages = [];
56
+ var rows = tbody.find('> tr:not(.footable-filtered,.footable-row-detail)');
57
+ rows.each(function (i, row) {
58
+ page.push(row);
59
+ if (i === pageCount - 1) {
60
+ info.pages.push(page);
61
+ pages++;
62
+ pageCount = pages * info.pageSize;
63
+ page = [];
64
+ } else if (i >= rows.length - (rows.length % info.pageSize)) {
65
+ lastPage.push(row);
66
+ }
67
+ });
68
+ if (lastPage.length > 0) info.pages.push(lastPage);
69
+ if (info.currentPage >= info.pages.length) info.currentPage = info.pages.length - 1;
70
+ if (info.currentPage < 0) info.currentPage = 0;
71
+ };
72
+
73
+ p.createNavigation = function (ft, tbody) {
74
+ var $nav = $(ft.pageInfo.pageNavigation);
75
+ if ($nav.length == 0) return;
76
+ $nav.find('li').remove();
77
+ var info = ft.pageInfo;
78
+ if (info.pages.length > 0) {
79
+
80
+ $nav.append('<li class="footable-page-arrow"><a data-page="prev" href="#prev">&laquo;</a></li>');
81
+ $.each(info.pages, function (i, page) {
82
+ if (page.length > 0) {
83
+ $nav.append('<li class="footable-page"><a data-page="' + i + '" href="#">' + (i + 1) + '</a></li>');
84
+ }
85
+ });
86
+ $nav.append('<li class="footable-page-arrow"><a data-page="next" href="#next">&raquo;</a></li>');
87
+ }
88
+ $nav.find('a').click(function (e) {
89
+ e.preventDefault();
90
+ var page = $(this).data('page');
91
+ var newPage = info.currentPage;
92
+ if (page == 'prev') {
93
+ if (newPage > 0) newPage--;
94
+ } else if (page == 'next') {
95
+ if (newPage < info.pages.length - 1) newPage++;
96
+ } else {
97
+ newPage = page;
98
+ }
99
+ if (info.currentPage != newPage) {
100
+ p.fillPage(ft, tbody, newPage);
101
+ }
102
+ $nav.find('li').removeClass('footable-page-current');
103
+ $nav.find('li.footable-page > a[data-page=' + info.currentPage + ']').parent().addClass('footable-page-current');
104
+ });
105
+ $nav.find('li.footable-page > a[data-page=' + info.currentPage + ']').parent().addClass('footable-page-current');
106
+ };
107
+
108
+ p.fillPage = function (ft, tbody, pageNumber) {
109
+ ft.pageInfo.currentPage = pageNumber;
110
+ tbody.find('> tr').hide();
111
+ $(ft.pageInfo.pages[pageNumber]).each(function () {
112
+ p.showRow(this, ft);
113
+ });
114
+ };
115
+
116
+ p.showRow = function (row, ft) {
117
+ var $row = $(row), $next = $row.next(), $table = $(ft.table);
118
+ if ($table.hasClass('breakpoint') && $row.hasClass('footable-detail-show') && $next.hasClass('footable-row-detail')) {
119
+ $row.add($next).show();
120
+ ft.createOrUpdateDetailRow(row);
121
+ }
122
+ else $row.show();
123
+ };
124
+ };
125
+
126
+ w.footable.plugins.register(new Paginate(), defaults);
127
+
128
+ })(jQuery, window);
@@ -0,0 +1,160 @@
1
+ (function($, w, undefined) {
2
+ if (w.footable == undefined || w.footable == null)
3
+ throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
4
+
5
+ var defaults = {
6
+ sort: true,
7
+ sorters: {
8
+ alpha: function(a, b) {
9
+ if (a == b) return 0;
10
+ if (a < b) return -1;
11
+ return 1;
12
+ },
13
+ numeric: function(a, b) {
14
+ return a - b;
15
+ }
16
+ },
17
+ parsers: {
18
+ numeric: function(cell) {
19
+ var val = $(cell).data('value') || $(cell).text().replace(/[^0-9.-]/g, '');
20
+ val = parseFloat(val);
21
+ if (isNaN(val)) val = 0;
22
+ return val;
23
+ }
24
+ },
25
+ classes: {
26
+ sort: {
27
+ sortable: 'footable-sortable',
28
+ sorted: 'footable-sorted',
29
+ descending: 'footable-sorted-desc',
30
+ indicator: 'footable-sort-indicator'
31
+ }
32
+ }
33
+ };
34
+
35
+ function Sortable() {
36
+ var p = this;
37
+ p.name = 'Footable Sortable';
38
+ p.init = function(ft) {
39
+ if (ft.options.sort == true) {
40
+ $(ft.table).bind({
41
+ 'footable_initialized': function(e) {
42
+ var cls = ft.options.classes.sort, column;
43
+
44
+ var $table = $(e.ft.table), $tbody = $table.find('> tbody'), $th;
45
+
46
+ $table.find('> thead > tr:last-child > th, > thead > tr:last-child > td').each(function(ec) {
47
+ $th = $(this), column = e.ft.columns[$th.index()];
48
+ if (column.sort.ignore != true) {
49
+ $th.addClass(cls.sortable);
50
+ $('<span />').addClass(cls.indicator).appendTo($th);
51
+ }
52
+ });
53
+
54
+ $table.find('> thead > tr:last-child > th.' + cls.sortable + ', > thead > tr:last-child > td.' + cls.sortable).click(function(ec) {
55
+ $th = $(this), column = e.ft.columns[$th.index()];
56
+ if (column.sort.ignore == true) return true;
57
+ ec.preventDefault();
58
+
59
+ $table.find('> thead > tr:last-child > th, > thead > tr:last-child > td').not($th).removeClass(cls.sorted + ' ' + cls.descending);
60
+
61
+ if ($th.hasClass(cls.sorted)) {
62
+ p.reverse(e.ft, $tbody);
63
+ $th.removeClass(cls.sorted).addClass(cls.descending);
64
+ } else if ($th.hasClass(cls.descending)) {
65
+ p.reverse(e.ft, $tbody);
66
+ $th.removeClass(cls.descending).addClass(cls.sorted);
67
+ } else {
68
+ p.sort(e.ft, $tbody, column);
69
+ $th.removeClass(cls.descending).addClass(cls.sorted);
70
+ }
71
+ e.ft.bindToggleSelectors();
72
+ e.ft.raise('footable_sorted', { column : column });
73
+ return false;
74
+ });
75
+
76
+ var didSomeSorting = false;
77
+ for (var c in e.ft.columns) {
78
+ column = e.ft.columns[c];
79
+ if (column.sort.initial) {
80
+ p.sort(e.ft, $tbody, column);
81
+ didSomeSorting = true;
82
+ $th = $table.find('> thead > tr:last-child > th:eq(' + c + '), > thead > tr:last-child > td:eq(' + c + ')');
83
+
84
+ if (column.sort.initial == 'descending') {
85
+ p.reverse(e.ft, $tbody);
86
+ $th.addClass(cls.descending);
87
+ } else {
88
+ $th.addClass(cls.sorted);
89
+ }
90
+
91
+ break;
92
+ } else if (column.sort.ignore != true) {
93
+
94
+ }
95
+ }
96
+ if (didSomeSorting) {
97
+ e.ft.bindToggleSelectors();
98
+ }
99
+ },
100
+ 'footable_column_data': function(e) {
101
+ var $th = $(e.column.th);
102
+ e.column.data.sort = e.column.data.sort || {};
103
+ e.column.data.sort.initial = $th.data('sort-initial') || false;
104
+ e.column.data.sort.ignore = $th.data('sort-ignore') || false;
105
+ e.column.data.sort.selector = $th.data('sort-selector') || null;
106
+
107
+ var match = $th.data('sort-match') || 0;
108
+ if (match >= e.column.data.matches.length) match = 0;
109
+ e.column.data.sort.match = e.column.data.matches[match];
110
+ }
111
+ });
112
+ }
113
+ };
114
+
115
+ p.rows = function(ft, tbody, column) {
116
+ var rows = [];
117
+ tbody.find('> tr').each(function() {
118
+ var $row = $(this), $next = null;
119
+ if ($row.hasClass('footable-row-detail')) return true;
120
+ if ($row.next().hasClass('footable-row-detail')) {
121
+ $next = $row.next().get(0);
122
+ }
123
+ var row = { 'row': $row, 'detail': $next };
124
+ if (column != undefined) {
125
+ row.value = ft.parse(this.cells[column.sort.match], column);
126
+ }
127
+ rows.push(row);
128
+ return true;
129
+ }).remove();
130
+ return rows;
131
+ };
132
+
133
+ p.sort = function(ft, tbody, column) {
134
+ var rows = p.rows(ft, tbody, column);
135
+ var sorter = ft.options.sorters[column.type] || ft.options.sorters.alpha;
136
+ rows.sort(function(a, b) { return sorter(a.value, b.value); });
137
+ for (var j = 0; j < rows.length; j++) {
138
+ tbody.append(rows[j].row);
139
+ if (rows[j].detail != null) {
140
+ tbody.append(rows[j].detail);
141
+ }
142
+ }
143
+ };
144
+
145
+ p.reverse = function(ft, tbody) {
146
+ var rows = p.rows(ft, tbody);
147
+ for (var i = rows.length - 1; i >= 0; i--) {
148
+ tbody.append(rows[i].row);
149
+ if (rows[i].detail != null) {
150
+ tbody.append(rows[i].detail);
151
+ }
152
+ }
153
+ };
154
+ }
155
+
156
+ ;
157
+
158
+ w.footable.plugins.register(new Sortable(), defaults);
159
+
160
+ })(jQuery, window);
@@ -0,0 +1,44 @@
1
+ (function ($, w, undefined) {
2
+ if (w.footable == undefined || w.foobox == null)
3
+ throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
4
+
5
+ var defaults = {
6
+ /*
7
+ Plugin options here, example:
8
+
9
+ var defaults = {
10
+ myPlugin: {
11
+ enabled: true
12
+ }
13
+ };
14
+
15
+ This would allow you to access this option using ft.options.myPlugin.enabled
16
+ */
17
+ };
18
+
19
+ function MyPlugin() {
20
+ var p = this;
21
+ p.name = 'Footable MyPlugin';
22
+ p.init = function(ft) {
23
+ $(ft.table).bind({
24
+ /*
25
+ Bind to relevant events here to modify/add functionality to Footable, example:
26
+
27
+ $(ft.table).bind({
28
+ 'footable_initialized': function(e){
29
+ if (e.ft.options.myPlugin.enabled == true){
30
+ alert('Hello World');
31
+ }
32
+ }
33
+ });
34
+
35
+ This would listen for the 'footable_initialized' event and when called check if the plugin is enabled
36
+ and if it is alert 'Hello World' to the user.
37
+ */
38
+ });
39
+ };
40
+ };
41
+
42
+ w.footable.plugins.register(new MyPlugin(), defaults);
43
+
44
+ })(jQuery, window);
@@ -0,0 +1,116 @@
1
+ .footable {
2
+ border-collapse: separate;
3
+ border-spacing: 0;
4
+ width: 100%;
5
+ border: solid #ccc 1px;
6
+ -moz-border-radius: 6px;
7
+ -webkit-border-radius: 6px;
8
+ border-radius: 6px;
9
+ font-family: 'trebuchet MS' , 'Lucida sans' , Arial;
10
+ font-size: 14px;
11
+ color: #444;
12
+ }
13
+
14
+ .footable.breakpoint > tbody > tr > td.expand {
15
+ background: url('img/plus.png') no-repeat 5px center;
16
+ padding-left: 40px;
17
+ }
18
+
19
+ .footable.breakpoint > tbody > tr.footable-detail-show > td.expand {
20
+ background: url('img/minus.png') no-repeat 5px center;
21
+ }
22
+
23
+ .footable.breakpoint > tbody > tr.footable-row-detail {
24
+ background: #eee;
25
+ }
26
+
27
+ .footable > tbody > tr:hover {
28
+ background: #fbf8e9;
29
+ }
30
+
31
+ .footable.breakpoint > tbody > tr:hover:not(.footable-row-detail) {
32
+ cursor: pointer;
33
+ }
34
+
35
+ .footable > tbody > tr > td, .footable > thead > tr > th {
36
+ border-left: 1px solid #ccc;
37
+ border-top: 1px solid #ccc;
38
+ padding: 10px;
39
+ text-align: left;
40
+ }
41
+
42
+ .footable > thead > tr > th, .footable > thead > tr > td {
43
+ background-color: #dce9f9;
44
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
45
+ background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
46
+ background-image: -moz-linear-gradient(top, #ebf3fc, #dce9f9);
47
+ background-image: -ms-linear-gradient(top, #ebf3fc, #dce9f9);
48
+ background-image: -o-linear-gradient(top, #ebf3fc, #dce9f9);
49
+ background-image: linear-gradient(to bottom, #ebf3fc, #dce9f9);
50
+ -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
51
+ -moz-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
52
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
53
+ border-top: none;
54
+ text-shadow: 0 1px 0 rgba(255,255,255,.5);
55
+ }
56
+
57
+ .footable > thead > tr:first-child > th.footable-first-column, .footable > thead > tr:first-child > td.footable-first-column {
58
+ -moz-border-radius: 6px 0 0 0;
59
+ -webkit-border-radius: 6px 0 0 0;
60
+ border-radius: 6px 0 0 0;
61
+ }
62
+
63
+ .footable > thead > tr:first-child > th.footable-last-column, .footable > thead > tr:first-child > td.footable-last-column {
64
+ -moz-border-radius: 0 6px 0 0;
65
+ -webkit-border-radius: 0 6px 0 0;
66
+ border-radius: 0 6px 0 0;
67
+ }
68
+
69
+ .footable > thead > tr:first-child > th.footable-first-column.footable-last-column, .footable > thead > tr:first-child > td.footable-first-column.footable-last-column {
70
+ -moz-border-radius: 6px 6px 0 0;
71
+ -webkit-border-radius: 6px 6px 0 0;
72
+ border-radius: 6px 6px 0 0;
73
+ }
74
+
75
+ .footable > tbody > tr:last-child > td.footable-first-column {
76
+ -moz-border-radius: 0 0 0 6px;
77
+ -webkit-border-radius: 0 0 0 6px;
78
+ border-radius: 0 0 0 6px;
79
+ }
80
+
81
+ .footable > tbody > tr:last-child > td.footable-last-column {
82
+ -moz-border-radius: 0 0 6px 0;
83
+ -webkit-border-radius: 0 0 6px 0;
84
+ border-radius: 0 0 6px 0;
85
+ }
86
+
87
+ .footable > tbody > tr:last-child > td.footable-first-column.footable-last-column {
88
+ -moz-border-radius: 0 0 6px 6px;
89
+ -webkit-border-radius: 0 0 6px 6px;
90
+ border-radius: 0 0 6px 6px;
91
+ }
92
+
93
+ .footable > thead > tr > th.footable-first-column, .footable > thead > tr > td.footable-first-column,
94
+ .footable > tbody > tr > td.footable-first-column {
95
+ border-left: none;
96
+ }
97
+
98
+ .footable > tbody img {
99
+ vertical-align:middle;
100
+ }
101
+
102
+ .footable > tfoot > tr > th, .footable > tfoot > tr > td {
103
+ background-color: #dce9f9;
104
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
105
+ background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
106
+ background-image: -moz-linear-gradient(top, #ebf3fc, #dce9f9);
107
+ background-image: -ms-linear-gradient(top, #ebf3fc, #dce9f9);
108
+ background-image: -o-linear-gradient(top, #ebf3fc, #dce9f9);
109
+ background-image: linear-gradient(to bottom, #ebf3fc, #dce9f9);
110
+ -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
111
+ -moz-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
112
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
113
+ border-top: 1px solid #ccc;
114
+ text-shadow: 0 1px 0 rgba(255,255,255,.5);
115
+ padding: 10px;
116
+ }
@@ -0,0 +1,31 @@
1
+ tfoot.footable-pagination tr td {
2
+ text-align: center;
3
+ }
4
+
5
+ .footable-nav {
6
+ list-style: none;
7
+ padding: 0;
8
+ margin: 0;
9
+ display: inline-block;
10
+ }
11
+
12
+ .footable-nav li {
13
+ display: inline-block;
14
+ }
15
+
16
+ .footable-nav li a {
17
+ display: inline-block;
18
+ padding: 5px 10px;
19
+ text-decoration: none;
20
+ color: #0066cc;
21
+ font-weight: bold;
22
+ }
23
+
24
+ .footable-nav .footable-page-current {
25
+ background: #888;
26
+ border-radius: 50%;
27
+ }
28
+
29
+ .footable-nav .footable-page-current a{
30
+ color: #fff;
31
+ }
@@ -0,0 +1,24 @@
1
+ .footable > thead > tr > th > span.footable-sort-indicator {
2
+ width: 16px;
3
+ height: 16px;
4
+ display: block;
5
+ float:right;
6
+ background: url('img/sorting_sprite.png') no-repeat top left;
7
+ }
8
+
9
+ .footable > thead > tr > th.footable-sortable:hover {
10
+ cursor:pointer;
11
+ }
12
+
13
+ .footable > thead > tr > th.footable-sortable > span {
14
+
15
+ }
16
+
17
+ .footable > thead > tr > th.footable-sorted > span.footable-sort-indicator {
18
+ background-position: 0 -16px;
19
+ }
20
+
21
+ .footable > thead > tr > th.footable-sorted-desc > span.footable-sort-indicator {
22
+ background-position: 0 -32px;
23
+ }
24
+