1/* 2 * jQuery FlexTable v1.1.2 3 * https://github.com/covistefan/flextable/ 4 * 5 * Copyright 2018 COVI.DE (https://www.covi.de) 6 * Lastchange 2018-04-10 7 * Free to use under the GPLv2 and later license. 8 * http://www.gnu.org/licenses/gpl-2.0.html 9 * 10 * Contributing author: Stefan Händler (https://github.com/covistefan/) 11 * 12 */ 13 14var $ = jQuery.noConflict(); 15 16function flexTable(tableData, dataOptions) { 17 18 var docalc = false; 19 var owidth = Math.ceil(tableData.outerWidth()); 20 var wwidth = $(window).innerWidth(); if (dataOptions.debug && dataOptions.bt=='window') { console.log('t_' + owidth + '::w_' + wwidth); } 21 var pwidth = tableData.parent().innerWidth(); if (dataOptions.debug && dataOptions.bt=='parent') { console.log('t_' + owidth + '::p_' + pwidth); } 22 23 // remove older instances of list 24 $('#flextable-' + tableData.attr('id')).remove(); 25 26 if (dataOptions.bt=='parent' && pwidth<owidth) { 27 docalc = true; 28 tableData.css('display', 'none'); 29 } 30 else if (dataOptions.bt=='window' && (wwidth<dataOptions.bw || wwidth<owidth)) { 31 docalc = true; 32 tableData.css('display', 'none'); 33 } 34 else { 35 docalc = false; 36 tableData.css('display', dataOptions.display); 37 } 38 39 if (docalc) { 40 41 var headData = new Array(); 42 // finding all header cells 43 tableData.find('th').each (function() { 44 $(this).parent().attr('flextable', 'header') 45 headData.push(this.innerHTML); 46 }); 47 // counting header cells 48 var headCount = headData.length; 49 // if no heading cells were found 50 if (headCount==0) { 51 // search for defined heading cells 52 if (dataOptions.hcell!=''){ 53 tableData.find('td' + dataOptions.hcell).parent().attr('flextable', 'header'); 54 tableData.find('td' + dataOptions.hcell).each (function() { 55 headData.push(this.innerHTML); 56 // adding attr to holding element to prevent later data usage 57 }); 58 } 59 // search for element holding heading cells 60 else if (dataOptions.hparent!='') { 61 tableData.find(dataOptions.hparent).children().each (function() { 62 // adding header data to array 63 headData.push(this.innerHTML); 64 // adding attr to holding element to prevent later data usage 65 tableData.find(dataOptions.hparent).attr('flextable', 'header'); 66 }); 67 } 68 } 69 // recounting header cells 70 var headCount = headData.length; 71 if (dataOptions.debug) { console.log('header cell count: ' + headCount); } 72 73 // running all rows (except the marked header cells 74 cellData = new Array(); cellClass = new Array(); var cr = 0; 75 tableData.find('tr').each (function(r) { 76 if ($(this).attr('flextable')!='header') { 77 cellData[cr] = new Array(); 78 cellClass[cr] = new Array(); 79 $(this).children('td').each (function(c) { 80 cellData[cr].push(this.innerHTML); 81 cellClass[cr].push(this.className); 82 }); 83 cr++; 84 } 85 }); 86 87 // building final list 88 var ul = $("<ul>"); 89 ul.attr('class', tableData.attr('class')); 90 ul.addClass('flextable-list'); 91 ul.attr('id', 'flextable-'+tableData.attr('id')); 92 for (var r = 0; r<cellData.length; r++) { 93 for (var c = 0; c<cellData[r].length; c++) { 94 if (dataOptions.header=='after') { 95 var li = "<li class='flextable-data'>" + cellData[r][c] + "</li><li class='flextable-head'>" + headData[c] + "</li>"; 96 if (dataOptions.combine) { li = "<li class='flextable-row'><ul class='flextable-set'>" + li + "</ul></li>"; } 97 ul.append(li); 98 } 99 else if (dataOptions.header=='none') { 100 ul.append("<li class='flextable-data'>" + cellData[r][c] + "</li>"); 101 } 102 else { 103 var li = "<li class='flextable-head'>" + headData[c] + "</li><li class='flextable-data " + cellClass[r][c] + "'>" + cellData[r][c] + "</li>"; 104 if (dataOptions.combine) { li = "<li class='flextable-row'><ul class='flextable-set'>" + li + "</ul></li>"; } 105 ul.append(li); 106 } 107 } 108 ul.append("<li class='flextable-spacer'></li>"); 109 } 110 // inserting ul after table in DOM 111 tableData.after(ul); 112 } 113} 114 115(function($) { 116 $.fn.flextable = function(options) { 117 var opts = $.extend({}, $.fn.flextable.defaults, options); 118 if (opts.debug) { console.log('debug mode'); } 119 return this.each(function() { 120 var $this = $(this); 121 $this.each(function(index){ 122 opts.display = $(this).css('display'); 123 if (opts.cm=='auto' || opts.cm=='resize') { 124 var width = $(window).width(); 125 $(window).on('resize', function() { 126 if ($(window).width()!=width) { 127 flexTable($this, opts); 128 } 129 }); 130 } 131 flexTable($this, opts); 132 }); 133 }); 134} 135 136$.fn.flextable.defaults = { 137 debug: false, // debug mode 138 bt: 'parent', // BreakType 'parent' » parent element width, 'window' » based on window width 139 bw: 768, // BreakWidth int » only with bt: 'window', if window width is lower then bw 140 cm: 'auto', // CalcMode 'auto' » on load and on resize, 'load' » only on load 141 hparent: '', // selector of parent holding header cells to get tablehead if not defined by thead » used if thead not found AND hcell is empty 142 hcell: '', // selector of cells to get tablehead if not defined by thead » used if thead not found 143 header: 'before', // showing tablehead information 'before' » add li with header data before data cell, 'after' » add li with header data after data cell, 'none' » ignore header data 144 combine: false // display data as simple list, true » create a '<li><ul><li header></li><li data></li></ul></li>' set if header is included 145 }; 146})(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.