This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathjquery-responsiveTables.js
107 lines (92 loc) · 3.23 KB
/
jquery-responsiveTables.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Generated by CoffeeScript 1.6.3
/*
*
* jQuery ResponsiveTables by Gary Hepting - https://github.com/ghepting/jquery-responsive-tables
*
* Open source under the MIT License.
*
* Copyright © 2013 Gary Hepting. All rights reserved.
*
*/
(function() {
var ResponsiveTable, delayedAdjust, responsiveTableIndex;
delayedAdjust = [];
responsiveTableIndex = 0;
ResponsiveTable = (function() {
function ResponsiveTable(el) {
this.index = responsiveTableIndex++;
this.el = el;
this.compression = $(this.el).data('compression') || 5;
this.minFontSize = $(this.el).data('min') || 10;
this.maxFontSize = $(this.el).data('max') || Number.POSITIVE_INFINITY;
this.width = $(this.el).data('width') || "100%";
this.height = $(this.el).data('height') || "auto";
this.adjustParents = $(this.el).data('adjust-parents') || true;
this.styled = $(this.el).data('styled') || true;
this.columns = $('tbody tr', $(this.el)).first().find('th, td').length;
this.rows = $('tbody tr', $(this.el)).length;
this.init();
}
ResponsiveTable.prototype.init = function() {
this.setupTable();
this.adjustOnLoad();
return this.adjustOnResize();
};
ResponsiveTable.prototype.fontSize = function() {
var compressed;
if (this.height === "auto") {
compressed = $('tbody td', $(this.el)).first().width() / this.compression;
} else {
compressed = $(this.el).height() / this.rows / this.compression;
}
return Math.min(this.maxFontSize, Math.max(compressed, this.minFontSize));
};
ResponsiveTable.prototype.setupTable = function() {
$(this.el).css('width', this.width);
if (this.height !== "auto") {
$(this.el).css('height', this.height);
}
$("th, td", $(this.el)).css('width', (100 / this.columns) + "%");
if (this.styled) {
$(this.el).addClass("responsiveTable");
}
if (this.height !== "auto") {
$("th, td", $(this.el)).css('height', (100 / this.rows) + "%");
if (this.adjustParents) {
$(this.el).parents().each(function() {
return $(this).css('height', '100%');
});
}
}
return $(this.el).css('font-size', this.fontSize());
};
ResponsiveTable.prototype.resizeTable = function() {
return $(this.el).css('font-size', this.minFontSize).css('font-size', this.fontSize());
};
ResponsiveTable.prototype.adjustOnLoad = function() {
var _this = this;
return $(window).on('load', function() {
return _this.resizeTable();
});
};
ResponsiveTable.prototype.adjustOnResize = function() {
var _this = this;
return $(window).on('resize', function() {
clearTimeout(delayedAdjust[_this.index]);
return delayedAdjust[_this.index] = setTimeout(function() {
return _this.resizeTable();
}, 20);
});
};
return ResponsiveTable;
})();
(function($) {
var responsiveTableElements;
responsiveTableElements = [];
return $.fn.responsiveTables = function(options) {
return this.each(function() {
return responsiveTableElements.push(new ResponsiveTable(this));
});
};
})(jQuery);
}).call(this);