vendor: 7,679 bytes, lines 1-200
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 // using rowIndex and cellIndex in order to reduce ambiguity 43 $table.find('tbody tr').each(function() { 44 45 // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records 46 headMarkup = ''; 47 bodyMarkup = ''; 48 tr_class = $(this).prop('class'); 49 // for the first row, "headIndex" cell is the head of the table 50 // for the other rows, put the "headIndex" cell as the head for that row 51 // then iterate through the key/values 52 $(this).find('td,th').each(function(cellIndex) { 53 if ($(this).html() !== ''){ 54 bodyMarkup += '<tr class="' + tr_class +'">'; 55 if ($topRow.find('td,th').eq(cellIndex).html()){ 56 bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; 57 } else { 58 bodyMarkup += '<td class="st-key"></td>'; 59 } 60 bodyMarkup += '<td class="st-val '+$(this).prop('class') +'">'+$(this).html()+'</td>'; 61 bodyMarkup += '</tr>'; 62 } 63 }); 64 65 markup += '<table class=" '+ table_css +' stacktable small-only"><tbody>' + headMarkup + bodyMarkup + '</tbody></table>'; 66 }); 67 68 $table.find('tfoot tr td').each(function(rowIndex,value) { 69 if ($.trim($(value).text()) !== '') { 70 markup += '<table class="'+ table_css + ' stacktable small-only"><tbody><tr><td>' + $(value).html() + '</td></tr></tbody></table>'; 71 } 72 }); 73 74 $stacktable.prepend($caption); 75 $stacktable.append($(markup)); 76 $table.before($stacktable); 77 }); 78 }; 79 80 $.fn.stacktable = function(options) { 81 var $tables = this, 82 defaults = {headIndex:0}, 83 settings = $.extend({}, defaults, options), 84 headIndex; 85 86 // checking the "headIndex" option presence... or defaults it to 0 87 if(options && options.headIndex) 88 headIndex = options.headIndex; 89 else 90 headIndex = 0; 91 92 return $tables.each(function() { 93 var table_css = $(this).prop('class'); 94 var $stacktable = $('<table class="'+ table_css +' stacktable small-only"><tbody></tbody></table>'); 95 if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass); 96 var markup = ''; 97 var $table, $caption, $topRow, headMarkup, bodyMarkup, tr_class; 98 99 $table = $(this); 100 $table.addClass('stacktable large-only'); 101 $caption = $table.find("caption").clone(); 102 $topRow = $table.find('tr').eq(0); 103 104 // using rowIndex and cellIndex in order to reduce ambiguity 105 $table.find('tr').each(function(rowIndex) { 106 107 // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records 108 headMarkup = ''; 109 bodyMarkup = ''; 110 tr_class = $(this).prop('class'); 111 // for the first row, "headIndex" cell is the head of the table 112 if (rowIndex === 0) { 113 // the main heading goes into the markup variable 114 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>'; 115 } 116 else { 117 // for the other rows, put the "headIndex" cell as the head for that row 118 // then iterate through the key/values 119 $(this).find('td,th').each(function(cellIndex) { 120 if (cellIndex === headIndex) { 121 headMarkup = '<tr class="'+ tr_class+'"><th class="st-head-row" colspan="2">'+$(this).html()+'</th></tr>'; 122 } else { 123 if ($(this).html() !== ''){ 124 bodyMarkup += '<tr class="' + tr_class +'">'; 125 if ($topRow.find('td,th').eq(cellIndex).html()){ 126 bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; 127 } else { 128 bodyMarkup += '<td class="st-key"></td>'; 129 } 130 bodyMarkup += '<td class="st-val '+$(this).prop('class') +'">'+$(this).html()+'</td>'; 131 bodyMarkup += '</tr>'; 132 } 133 } 134 }); 135 136 markup += headMarkup + bodyMarkup; 137 } 138 }); 139 140 $stacktable.prepend($caption); 141 $stacktable.append($(markup)); 142 $table.before($stacktable); 143 }); 144 }; 145 146 $.fn.stackcolumns = function(options) { 147 var $tables = this, 148 defaults = {}, 149 settings = $.extend({}, defaults, options); 150 151 return $tables.each(function() { 152 var $table = $(this); 153 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. 154 if(num_cols<3) //stackcolumns has no effect on tables with less than 3 columns 155 return; 156 157 var $stackcolumns = $('<table class="stacktable small-only"></table>'); 158 if (typeof settings.myClass !== 'undefined') $stackcolumns.addClass(settings.myClass); 159 $table.addClass('stacktable large-only'); 160 var tb = $('<tbody></tbody>'); 161 var col_i = 1; //col index starts at 0 -> start copy at second column. 162 163 while (col_i < num_cols) { 164 $table.find('tr').each(function(index) { 165 var tem = $('<tr></tr>'); // todo opt. copy styles of $this; todo check if parent is thead or tfoot to handle accordingly 166 if(index === 0) tem.addClass("st-head-row st-head-row-main"); 167 var first = $(this).find('td,th').eq(0).clone().addClass("st-key"); 168 var target = col_i; 169 // if colspan apply, recompute target for second cell. 170 if ($(this).find("*[colspan]").length) { 171 var i =0; 172 $(this).find('td,th').each(function() { 173 var cs = $(this).attr("colspan"); 174 if (cs) { 175 cs = parseInt(cs, 10); 176 target -= cs-1; 177 if ((i+cs) > (col_i)) //out of current bounds 178 target += i + cs - col_i -1; 179 i += cs; 180 } 181 else 182 i++; 183 184 if (i > col_i) 185 return false; //target is set; break. 186 }); 187 } 188 var second = $(this).find('td,th').eq(target).clone().addClass("st-val").removeAttr("colspan"); 189 tem.append(first, second); 190 tb.append(tem); 191 }); 192 ++col_i; 193 } 194 195 $stackcolumns.append($(tb)); 196 $table.before($stackcolumns); 197 }); 198 }; 199 200}(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.