Sha256: 8fda57d7f16f84fecfbe15879ae08875bca543ef040a4c7ebcd16195fde211e5

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 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).on("redraw",function(){switched=false;updateTables();}); // An event to listen for
  $(window).on("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

6 entries across 6 versions & 4 rubygems

Version Path
ish_lib-0.0.8 vendor/assets/themeforest/alpona/html/js/responsive-tables.js
ish_lib-0.0.3 vendor/assets/themeforest/alpona/html/js/responsive-tables.js
self_systeem-0.1.0 test/dummy_app/app/assets/javascripts/responsive-tables.js
exo_cms-0.0.3 app/assets/javascripts/exo/admin/responsive-tables.js
exo_cms-0.0.1 app/assets/javascripts/exo/admin/responsive-tables.js
furatto-0.0.1 vendor/assets/javascripts/responsive-tables.js