diff --git a/responsive-tables.js b/responsive-tables.js index beb79c0..93efe27 100644 --- a/responsive-tables.js +++ b/responsive-tables.js @@ -23,47 +23,44 @@ $(window).on("resize", updateTables); - function splitTable(original) - { - original.wrap("
"); + function splitTable(original) + { + original.wrap(""); - var copy = original.clone(); - copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none"); - copy.removeClass("responsive"); + var copy = original.clone(); + copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none"); + copy.removeClass("responsive"); - original.closest(".table-wrapper").append(copy); - copy.wrap(""); - original.wrap(""); + original.closest(".table-wrapper").append(copy); + copy.wrap(""); + original.wrap(""); setCellHeights(original, copy); - } + setTableHeights(original, copy); + } - function unsplitTable(original) { + function unsplitTable(original) { original.closest(".table-wrapper").find(".pinned").remove(); original.unwrap(); original.unwrap(); - } + } function setCellHeights(original, copy) { - var tr = original.find('tr'), - tr_copy = copy.find('tr'), - heights = []; - - tr.each(function (index) { - var self = $(this), - tx = self.find('th, td'); - - tx.each(function () { - var height = $(this).outerHeight(true); - heights[index] = heights[index] || 0; - if (height > heights[index]) heights[index] = height; - }); - + $('tr', original).each(function(index){ + oheight = $(this).height(); + cheight = $('tr:eq('+index+')', copy).height(); + height = (oheight > cheight ? oheight : cheight); + $('th,td', original).css('height', height+'px'); + $('th,td', copy).css('height', height+'px'); }); + } - tr_copy.each(function (index) { - $(this).height(heights[index]); - }); + function setTableHeights(original, copy) { + oheight = original.outerHeight(); + cheight = copy.outerHeight(); + height = (oheight > cheight ? oheight : cheight); + original.css('min-height', height+'px'); + copy.css('min-height', height+'px'); } });