1(function ($) { 2 $.fn.stackedRows = function(options) { 3 4 var settings = $.extend({ 5 classPrefix: "sr", 6 firstRowHeader : true, 7 showLabels : true, 8 altRowStyle : true 9 }, options); 10 11 12 var obj = { 13 colNames : Array(), 14 numRows : 0, 15 tableTypes : Array('withTbody', 'noTbody'), 16 tableType : '', 17 cols : '', 18 body : '', 19 findCols : function(curTable){ 20 var tableType = 1; 21 if(curTable.find('thead > tr > th').length > 0){ 22 obj.cols = curTable.find('thead > tr > th'); 23 curTable.find('thead > tr').addClass(settings.classPrefix +'-header'); 24 tableType = obj.tableTypes[0]; 25 }else if(curTable.find('thead > tr > td').length > 0){ 26 obj.cols = curTable.find('thead > tr > td'); 27 curTable.find('thead > tr').addClass(settings.classPrefix +'-header'); 28 tableType = obj.tableTypes[0]; 29 }else if(curTable.find('tbody > tr > th').length > 0){ 30 obj.cols = curTable.find('tbody > tr > th'); 31 curTable.find('tbody > tr:first-child').addClass(settings.classPrefix +'-header'); 32 tableType = obj.tableTypes[1]; 33 }else{ 34 obj.cols = curTable.find('tr:first-child > td'); 35 curTable.find('tr:first-child').addClass(settings.classPrefix +'-header'); 36 tableType = obj.tableTypes[1]; 37 } 38 obj.tableType = tableType; 39 }, 40 findBody : function(curTable){ 41 var body = ''; 42 switch(obj.tableType){ 43 case 'withTbody': 44 body = curTable.find('tbody tr'); 45 break; 46 case 'noTbody': 47 if(settings.firstRowHeader == true){ 48 body = curTable.find('tr:not(:first-child)'); 49 }else{ 50 body = curTable.find('tr'); 51 } 52 break; 53 } 54 obj.body = body; 55 } 56 }; 57 58 59 this.each(function(x){ //selector passed to plugin 60 61 var curTable = $(this); 62 curTable.css({"width":"100%"}); 63 64 obj.findCols(curTable); 65 obj.findBody(curTable); 66 obj.cols.each(function(){ 67 obj.colNames.push($(this).html()); 68 }); 69 obj.body.each(function(q){ 70 var curRow = 'row-'+q; 71 obj.numRows++; 72 obj[curRow] = Array(); 73 $(this).addClass(settings.classPrefix + '-' + curRow + ' '+ settings.classPrefix +'-hide'); 74 $(this).find('td').each(function(){ 75 var contents = $(this).html(); 76 obj[curRow].push(contents.trim()); 77 }); 78 }); 79 80 //build output from array 81 82 for(var y = 0; y < obj.numRows; y++){ 83 var html = ''; 84 var curRow = 'row-'+y; 85 var outRow = obj[curRow]; 86 if(typeof outRow !== 'undefined'){ 87 var altRowClass = (y%2 != 0) && settings.altRowStyle == true ? 'even' : ''; 88 var lastRowClass = ((y+1) == obj.numRows) ? settings.classPrefix + '-tr-last' : ''; 89 html += '<tr class="'+ settings.classPrefix +'-table-tr '; 90 html += altRowClass +' '+ settings.classPrefix + '-table-tr-'+ curRow + ' '; 91 html += lastRowClass +'">' 92 html += '<td colspan="'+obj.colNames.length+'">'; 93 html += '<div class="' + settings.classPrefix + '-table-div">'; 94 for(var k=0;k<outRow.length;k++){ 95 var blankValueClass = outRow[k] == '' || outRow[k] == ' ' ? 'blankValue' : ''; 96 var blankLabelClass = obj.colNames[k] == '' || obj.colNames[k] == ' ' ? 'blankLabel' : '' 97 html += '<div class="' + settings.classPrefix + '-table-record-div '+ blankValueClass + ' ' + blankLabelClass +'">'; 98 /*label*/ 99 var label = obj.colNames[k]; 100 var labelClass = settings.showLabels == false ? 'hidden' : ''; 101 if(settings.firstRowHeader == true) { 102 html += '<label class="'+labelClass+'">'+label+'</label>'; 103 } 104 /*end label*/ 105 html += '<p>'+outRow[k]+'</p>'; 106 html += '</div>'; 107 } 108 html += '</div></td></tr>'; 109 curTable.find('tr.'+ settings.classPrefix + '-' +curRow).after(html); 110 } 111 } 112 obj.colNames = Array(); 113 obj.numRows = 0; 114 }); 115 116 }; 117}( 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.