From 4c329ecbf9a2422dc8fe83977c95a3104c3ab629 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Thu, 27 Dec 2012 22:46:41 +0100 Subject: more CSS an JS voodoo for bugblues table view --- public/css/scrolltable.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 public/css/scrolltable.js (limited to 'public/css/scrolltable.js') diff --git a/public/css/scrolltable.js b/public/css/scrolltable.js new file mode 100644 index 00000000..1184207f --- /dev/null +++ b/public/css/scrolltable.js @@ -0,0 +1,26 @@ +function scrolltable(elem) { + var widths = new Array(); + var thead = elem.getElementsByTagName('thead')[0]; + var tbody = elem.getElementsByTagName('tbody')[0]; + var ths = Array.prototype.slice.call(thead.getElementsByTagName('th'),0); + ths = ths.concat(Array.prototype.slice.call(tbody.getElementsByTagName('tr')[0].getElementsByTagName('td'), 0)); + ths.push(tbody.getElementsByTagName('th')[0]); + console.debug(ths); + for(var i = 0; i < ths.length; i++) + widths.push(ths[i].offsetWidth); + widths.push(tbody.offsetWidth); + elem.className = elem.className + ' scrollable'; + var tbodywidth = widths.pop(); + tbody.style.width = (tbodywidth + 16) + 'px'; + tbody.style.height = (window.innerHeight - 50) + 'px'; + for(var i = 0; i < ths.length; i++) { + var paddingLeft = parseInt(window.getComputedStyle(ths[i], null).getPropertyValue('padding-left')); + var paddingRight = parseInt(window.getComputedStyle(ths[i], null).getPropertyValue('padding-right')); + var borderLeft = parseInt(window.getComputedStyle(ths[i], null).getPropertyValue('border-left-width')); + var borderRight = parseInt(window.getComputedStyle(ths[i], null).getPropertyValue('border-right-width')); + var targetwidth = widths.shift(); + ths[i].style.maxWidth = ths[i].style.minWidth = (targetwidth - paddingLeft - paddingRight - borderRight) + 'px'; + if (ths[i].offsetWidth > targetwidth) + ths[i].style.maxWidth = ths[i].style.minWidth = (parseInt(ths[i].style.minWidth) - 1) + 'px'; + } +} -- cgit v1.2.3-54-g00ecf