/** * stacktable.js * Author & copyright (c) 2012: John Polacek * CardTable by: Justin McNally (2015) * Dual MIT & GPL license * * Page: https://johnpolacek.github.com/stacktable.js * Repo: https://github.com/johnpolacek/stacktable.js/ * * jQuery plugin for stacking tables on small screens * Requires jQuery version 1.7 or above * */ !function(t){t.fn.cardtable=function(a){var s,d=this,e={headIndex:0},l=t.extend({},e,a) return s=a&&a.headIndex?a.headIndex:0,d.each(function(){var a=t(this) if(!a.hasClass("stacktable")){var s=t(this).prop("class"),d=t("
") "undefined"!=typeof l.myClass&&d.addClass(l.myClass) var e,n,i,h,r,c="" a.addClass("stacktable large-only"),e=a.find("caption").clone(),n=a.find("tr").eq(0),a.siblings().filter(".small-only").remove(),a.find("tbody tr").each(function(){i="",h="",r=t(this).prop("class"),t(this).find("td,th").each(function(a){""!==t(this).html()&&(h+='',h+=n.find("td,th").eq(a).html()?''+n.find("td,th").eq(a).html()+"":'',h+=''+t(this).html()+"",h+="")}),c+=''+i+h+"
"}),a.find("tfoot tr td").each(function(a,d){""!==t.trim(t(d).text())&&(c+='
'+t(d).html()+"
")}),d.prepend(e),d.append(t(c)),a.before(d)}})},t.fn.stacktable=function(a){var s,d=this,e={headIndex:0},l=t.extend({},e,a) return s=a&&a.headIndex?a.headIndex:0,d.each(function(){var a=t(this).prop("class"),d=t('
') "undefined"!=typeof l.myClass&&d.addClass(l.myClass) var e,n,i,h,r,c,o="" e=t(this),e.addClass("stacktable large-only"),n=e.find("caption").clone(),i=e.find("tr").eq(0),e.find("tr").each(function(a){h="",r="",c=t(this).prop("class"),0===a?o+=''+t(this).find("th,td").eq(s).html()+"":(t(this).find("td,th").each(function(a){a===s?h=''+t(this).html()+"":""!==t(this).html()&&(r+='',r+=i.find("td,th").eq(a).html()?''+i.find("td,th").eq(a).html()+"":'',r+=''+t(this).html()+"",r+="")}),o+=h+r)}),d.prepend(n),d.append(t(o)),e.before(d)})},t.fn.stackcolumns=function(a){var s=this,d={},e=t.extend({},d,a) return s.each(function(){var a=t(this),s=a.find("tr").eq(0).find("td,th").length if(!(3>s)){var d=t('
') "undefined"!=typeof e.myClass&&d.addClass(e.myClass),a.addClass("stacktable large-only") for(var l=t(""),n=1;s>n;)a.find("tr").each(function(a){var s=t("") 0===a&&s.addClass("st-head-row st-head-row-main") var d=t(this).find("td,th").eq(0).clone().addClass("st-key"),e=n if(t(this).find("*[colspan]").length){var i=0 t(this).find("td,th").each(function(){var a=t(this).attr("colspan") return a?(a=parseInt(a,10),e-=a-1,i+a>n&&(e+=i+a-n-1),i+=a):i++,i>n?!1:void 0})}var h=t(this).find("td,th").eq(e).clone().addClass("st-val").removeAttr("colspan") s.append(d,h),l.append(s)}),++n d.append(t(l)),a.before(d)}})}}(jQuery)