Sha256: e1239c0680fcc6e3b88ddb5ea978765a968ffc68b18b65cbb9c634de9f6d3c21

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

$(document).ready(function() {
  var switched = false;
  var updateTables = function() {
    if (($(window).width() < 767) && !switched ){
      switched = true;
      $("table.responsive").each(function(i, element) {
        splitTable($(element));
      });
      return true;
    }
    else if (switched && ($(window).width() > 767)) {
      switched = false;
      $("table.responsive").each(function(i, element) {
        unsplitTable($(element));
      });
    }
  };
   
  $(window).load(updateTables);
  $(window).bind("resize", updateTables);
   
	
	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");
		
		original.closest(".table-wrapper").append(copy);
		copy.wrap("<div class='pinned' />");
		original.wrap("<div class='scrollable' />");

    setCellHeights(original, copy);
	}
	
	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_copy.each(function (index) {
      $(this).height(heights[index]);
    });
  }

});

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rbbt-rest-1.2.6 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.5 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.4 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.3 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.2 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.1 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.2.0 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.1.5 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.1.4 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.1.3 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.1.2 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js
rbbt-rest-1.1.0 share/views/public/plugins/zurb-responsive-tables/js/responsive-tables.js