vendor: 7,785 bytes, lines 1-203
1/** 2 * stacktable.js 3 * Author & copyright (c) 2012: John Polacek 4 * CardTable by: Justin McNally (2015) 5 * Dual MIT & GPL license 6 * 7 * Page: http://johnpolacek.github.com/stacktable.js 8 * Repo: https://github.com/johnpolacek/stacktable.js/ 9 * 10 * jQuery plugin for stacking tables on small screens 11 * Requires jQuery version 1.7 or above 12 * 13 */ 14;(function($) { 15 $.fn.cardtable = function(options) { 16 var $tables = this, 17 defaults = {headIndex:0}, 18 settings = $.extend({}, defaults, options), 19 headIndex; 20 21 // checking the "headIndex" option presence... or defaults it to 0 22 if(options && options.headIndex) 23 headIndex = options.headIndex; 24 else 25 headIndex = 0; 26 27 return $tables.each(function() { 28 var $table = $(this); 29 if ($table.hasClass('stacktable')) { 30 return; 31 } 32 var table_css = $(this).prop('class'); 33 var $stacktable = $('<div></div>'); 34 if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass); 35 var markup = ''; 36 var $caption, $topRow, headMarkup, bodyMarkup, tr_class; 37 38 $table.addClass('stacktable large-only'); 39 $caption = $table.find("caption").clone(); 40 $topRow = $table.find('tr').eq(0); 41 42 // avoid duplication when paginating 43 $table.siblings().filter('.small-only').remove(); 44 45 // using rowIndex and cellIndex in order to reduce ambiguity 46 $table.find('tbody tr').each(function() { 47 48 // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records 49 headMarkup = ''; 50 bodyMarkup = ''; 51 tr_class = $(this).prop('class'); 52 // for the first row, "headIndex" cell is the head of the table 53 // for the other rows, put the "headIndex" cell as the head for that row 54 // then iterate through the key/values 55 $(this).find('td,th').each(function(cellIndex) { 56 if ($(this).html() !== ''){ 57 bodyMarkup += '<tr class="' + tr_class +'">'; 58 if ($topRow.find('td,th').eq(cellIndex).html()){ 59 bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; 60 } else { 61 bodyMarkup += '<td class="st-key"></td>'; 62 } 63 bodyMarkup += '<td class="st-val '+$(this).prop('class') +'">'+$(this).html()+'</td>'; 64 bodyMarkup += '</tr>'; 65 } 66 }); 67 68 markup += '<table class=" '+ table_css +' stacktable small-only"><tbody>' + headMarkup + bodyMarkup + '</tbody></table>'; 69 }); 70 71 $table.find('tfoot tr td').each(function(rowIndex,value) { 72 if ($.trim($(value).text()) !== '') { 73 markup += '<table class="'+ table_css + ' stacktable small-only"><tbody><tr><td>' + $(value).html() + '</td></tr></tbody></table>'; 74 } 75 }); 76 77 $stacktable.prepend($caption); 78 $stacktable.append($(markup)); 79 $table.before($stacktable); 80 }); 81 }; 82 83 $.fn.stacktable = function(options) { 84 var $tables = this, 85 defaults = {headIndex:0}, 86 settings = $.extend({}, defaults, options), 87 headIndex; 88 89 // checking the "headIndex" option presence... or defaults it to 0 90 if(options && options.headIndex) 91 headIndex = options.headIndex; 92 else 93 headIndex = 0; 94 95 return $tables.each(function() { 96 var table_css = $(this).prop('class'); 97 var $stacktable = $('<table class="'+ table_css +' stacktable small-only"><tbody></tbody></table>'); 98 if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass); 99 var markup = ''; 100 var $table, $caption, $topRow, headMarkup, bodyMarkup, tr_class; 101 102 $table = $(this); 103 $table.addClass('stacktable large-only'); 104 $caption = $table.find("caption").clone(); 105 $topRow = $table.find('tr').eq(0); 106 107 // using rowIndex and cellIndex in order to reduce ambiguity 108 $table.find('tr').each(function(rowIndex) { 109 110 // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records 111 headMarkup = ''; 112 bodyMarkup = ''; 113 tr_class = $(this).prop('class'); 114 // for the first row, "headIndex" cell is the head of the table 115 if (rowIndex === 0) { 116 // the main heading goes into the markup variable 117 markup += '<tr class=" '+tr_class +' "><th class="st-head-row st-head-row-main" colspan="2">'+$(this).find('th,td').eq(headIndex).html()+'</th></tr>'; 118 } 119 else { 120 // for the other rows, put the "headIndex" cell as the head for that row 121 // then iterate through the key/values 122 $(this).find('td,th').each(function(cellIndex) { 123 if (cellIndex === headIndex) { 124 headMarkup = '<tr class="'+ tr_class+'"><th class="st-head-row" colspan="2">'+$(this).html()+'</th></tr>'; 125 } else { 126 if ($(this).html() !== ''){ 127 bodyMarkup += '<tr class="' + tr_class +'">'; 128 if ($topRow.find('td,th').eq(cellIndex).html()){ 129 bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; 130 } else { 131 bodyMarkup += '<td class="st-key"></td>'; 132 } 133 bodyMarkup += '<td class="st-val '+$(this).prop('class') +'">'+$(this).html()+'</td>'; 134 bodyMarkup += '</tr>'; 135 } 136 } 137 }); 138 139 markup += headMarkup + bodyMarkup; 140 } 141 }); 142 143 $stacktable.prepend($caption); 144 $stacktable.append($(markup)); 145 $table.before($stacktable); 146 }); 147 }; 148 149 $.fn.stackcolumns = function(options) { 150 var $tables = this, 151 defaults = {}, 152 settings = $.extend({}, defaults, options); 153 154 return $tables.each(function() { 155 var $table = $(this); 156 var num_cols = $table.find('tr').eq(0).find('td,th').length; //first table <tr> must not contain colspans, or add sum(colspan-1) here. 157 if(num_cols<3) //stackcolumns has no effect on tables with less than 3 columns 158 return; 159 160 var $stackcolumns = $('<table class="stacktable small-only"></table>'); 161 if (typeof settings.myClass !== 'undefined') $stackcolumns.addClass(settings.myClass); 162 $table.addClass('stacktable large-only'); 163 var tb = $('<tbody></tbody>'); 164 var col_i = 1; //col index starts at 0 -> start copy at second column. 165 166 while (col_i < num_cols) { 167 $table.find('tr').each(function(index) { 168 var tem = $('<tr></tr>'); // todo opt. copy styles of $this; todo check if parent is thead or tfoot to handle accordingly 169 if(index === 0) tem.addClass("st-head-row st-head-row-main"); 170 var first = $(this).find('td,th').eq(0).clone().addClass("st-key"); 171 var target = col_i; 172 // if colspan apply, recompute target for second cell. 173 if ($(this).find("*[colspan]").length) { 174 var i =0; 175 $(this).find('td,th').each(function() { 176 var cs = $(this).attr("colspan"); 177 if (cs) { 178 cs = parseInt(cs, 10); 179 target -= cs-1; 180 if ((i+cs) > (col_i)) //out of current bounds 181 target += i + cs - col_i -1; 182 i += cs; 183 } 184 else 185 i++; 186 187 if (i > col_i) 188 return false; //target is set; break. 189 }); 190 } 191 var second = $(this).find('td,th').eq(target).clone().addClass("st-val").removeAttr("colspan"); 192 tem.append(first, second); 193 tb.append(tem); 194 }); 195 ++col_i; 196 } 197 198 $stackcolumns.append($(tb)); 199 $table.before($stackcolumns); 200 }); 201 }; 202 203}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.