This repository was archived by the owner on Nov 15, 2023. It is now read-only.
forked from johnpolacek/stacktable.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacktable.js
More file actions
executable file
·51 lines (42 loc) · 1.34 KB
/
Copy pathstacktable.js
File metadata and controls
executable file
·51 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* stacktable.js
* Author & copyright (c) 2012: John Polacek
* Dual MIT & GPL license
*
* Page: http://johnpolacek.github.com/stacktable.js
* Repo: https://github.com/johnpolacek/stacktable.js/
*
* jQuery plugin for stacking tables on small screens
*
*/
(function ($) {
$.fn.stacktable = function (options) {
var $tables = this,
defaults = {
classname: 'stacktable'
},
settings = $.extend({}, defaults, options);
return $tables.each(function () {
var $stacktable = $('<table class="' + settings.classname + '"></table>'),
markup = '',
$table = $(this),
$headers = $table.find('thead').eq(0).children().eq(0);
if ($headers.length) {
$table.find('tbody').children().each(function (index) {
markup += '<tbody>';
$(this).children().each(function (index) {
if ($(this).html() !== '') {
markup += '<tr>';
markup += '<th>' + $headers.children().eq(index).text() + '</th>';
markup += '<td>' + $(this).html() + '</td>';
markup += '</tr>';
}
});
markup += '</tbody>';
});
$stacktable.append($(markup));
$table.addClass('is-' + settings.classname).before($stacktable);
}
});
};
}(jQuery));