Skip to content

Commit

Permalink
Incorporated changes from this pull request: zurb#21.
Browse files Browse the repository at this point in the history
Fixes issues:
- zurb#15
- zurb#18
- zurb#21

NOTE:  I could not pull the PR manually, as the the changes were from an "unknown repository". Credit for this commit should go to https://github.com/seriouslysean.
  • Loading branch information
NicholasRBowers committed Apr 15, 2015
1 parent c9adf6a commit cfe0ab8
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions responsive-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,44 @@
$(window).on("resize", updateTables);


function splitTable(original)
{
original.wrap("<div class='table-wrapper' />");
function splitTable(original)
{
original.wrap("<div class='table-wrapper' />");

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("<div class='pinned' />");
original.wrap("<div class='scrollable' />");
original.closest(".table-wrapper").append(copy);
copy.wrap("<div class='pinned' />");
original.wrap("<div class='scrollable' />");

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');
}

});
Expand Down

0 comments on commit cfe0ab8

Please sign in to comment.