-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.fs.stacker.min.js
9 lines (8 loc) · 3.09 KB
/
jquery.fs.stacker.min.js
1
2
3
4
5
6
7
8
9
/*
* Stacker v0.0.1 - 2015-04-04
* A jQuery plugin for responsive tables that retain column headers. Part of the Formstone Library.
* http://classic.formstone.it/selecter/
*
* Copyright 2015 Matt Hisamoto; MIT Licensed
*/
!function(a,b){"use strict";function c(b){b=a.extend({},h,b||{}),null===g&&(g=a("body"));for(var c=a(this),e=0,f=c.length;f>e;e++)d(c.eq(e),b);return c}function d(c,d){if(c.is("table")){d=a.extend({},d,c.data("stacker-options"));var f=[],g=c.find("caption"),h=c.find("thead"),i=h.find("th"),j=!1,k=c.find("tbody > tr"),l=0;h.length?i.length||(j=h.find("td"),i=j):(i=k.eq(0).find("td"),l=1),i.each(function(b){f.push(a(this).html())});var m,n="";n+="<table ",c.attr("id")&&(n+='id="stacker-'+c.attr("id")+'" '),n+='class="stacker stacker-table',d.customClass&&(n+=" "+d.customClass),d.preserveClasses&&c.attr("class")&&(n+=" "+c.attr("class")),n+='">',g.length&&(n+="<caption",d.preserveClasses&&g.attr("class")&&(n+=' class="'+g.attr("class")+'"'),n+=">"+g.html()+"</caption>"),n+="<tbody>";for(var o=l,p=k.length;p>o;o++){var q=k.eq(o),r=q.find("td");n+="<tr><td><table>",n+="<thead>";var s=!1;f[l]&&""!==f[l]&&(s=!0),s&&(n+="<th",d.preserveClasses&&r.eq(l).attr("class")&&(n+=' class="'+r.eq(l).attr("class")+'"'),n+=">",n+=f[0],n+="</th>"),n+="<th",s||(n+=' colspan="2"'),d.preserveClasses&&r.eq(l).attr("class")&&(n+=' class="'+r.eq(l).attr("class")+'"'),n+=">",n+=r.eq(0).html(),n+="</th></thead>",n+="<tbody>";for(var t=1,u=r.length;u>t;t++){n+="<tr>";var v=!1;f[t]&&""!==f[t]&&(v=!0),v&&(n+="<td",d.preserveClasses&&r.eq(t).attr("class")&&(n+=' class="'+r.eq(t).attr("class")+'"'),n+=">",n+=f[t],n+="</td>"),n+="<td",v||(n+=' colspan="2"'),d.preserveClasses&&r.eq(t).attr("class")&&(n+=' class="'+r.eq(t).attr("class")+'"'),n+=">",n+=r.eq(t).html(),n+="</td></tr>"}n+="</tbody></table></td></tr>"}n+="</tbody></table>",m=a(n),c.addClass("stacker stacker-original").after(m);var w=a.extend(!0,{$table:c,$stackerTable:m},d);w.$table.data("stacker",w),void 0!==b.matchMedia&&(w.mediaQuery=b.matchMedia("(max-width:"+(w.maxWidth===1/0?"100000px":w.maxWidth)+")"),w.mediaQuery.addListener(function(){e.apply(w.$table)}),e.apply(w.$table))}}function e(){var b=a(this).data("stacker");b.mediaQuery.matches?i.enable.apply(b.$table):i.disable.apply(b.$table)}var f=b.navigator.userAgent||b.navigator.vendor||b.opera,g=(/Firefox/i.test(f),/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(f),null),h={callback:a.noop,customClass:"",maxWidth:"740px",preserveClasses:!1},i={defaults:function(b){return h=a.extend(h,b||{}),"object"==typeof this?a(this):!0},disable:function(){return a(this).each(function(b,c){var d=a(c).data("stacker");d&&(d.$table.addClass("enabled"),d.$stackerTable.removeClass("enabled"))})},enable:function(){return a(this).each(function(b,c){var d=a(c).data("stacker");d&&(d.$table.removeClass("enabled"),d.$stackerTable.addClass("enabled"))})}};a.fn.stacker=function(a){return i[a]?i[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?this:c.apply(this,arguments)},a.stacker=function(a){"defaults"===a&&i.defaults.apply(this,Array.prototype.slice.call(arguments,1))}}(jQuery,window);