1/* ------------------------------------------------------------------------ 2 Class: freezeHeader 3 Use:freeze header row in html table 4 Example 1: $('#tableid').freezeHeader(); 5 Example 2: $("#tableid").freezeHeader({ 'height': '300px' }); 6 Example 3: $("table").freezeHeader(); 7 Example 4: $(".table2").freezeHeader(); 8 Example 5: $("#tableid").freezeHeader({ 'offset': '50px' }); 9 Author(s): Laerte Mercier Junior, Larry A. Hendrix 10 Version: 1.0.7 11 -------------------------------------------------------------------------*/ 12(function ($) { 13 var TABLE_ID = 0; 14 $.fn.freezeHeader = function (params) { 15 16 function freezeHeader(elem) { 17 var idObj = elem.attr('id') || ('tbl-' + (++TABLE_ID)); 18 var $floatingSuspensionCondition = $(elem).parents(".container").find(".floating-table-condition-search") || $("#"+idObj).parents(".container").find(".floating-table-condition-search") || null; 19 if (elem.length > 0 && elem[0].tagName.toLowerCase() == "table") { 20 21 var obj = { 22 id: idObj, 23 grid: elem, 24 container: null, 25 header: null, 26 divScroll: null, 27 openDivScroll: null, 28 closeDivScroll: null, 29 scroller: null, 30 // æ¬æµ®æ¡ 31 floatingLen:$floatingSuspensionCondition.length || 0, 32 floatingHeight:$floatingSuspensionCondition.outerHeight() || 0, 33 $floatingSuspensionCondition:$floatingSuspensionCondition, 34 }; 35 36 if (params && params.height !== undefined) { 37 obj.divScroll = '<div id="hdScroll' + obj.id + '" style="height: ' + params.height + '; overflow-y: scroll;">'; 38 obj.closeDivScroll = '</div>'; 39 } 40 41 obj.header = obj.grid.find('thead'); 42 43 if (params && params.height !== undefined) { 44 if ($('#hdScroll' + obj.id).length == 0) { 45 obj.grid.wrapAll(obj.divScroll); 46 } 47 } 48 49 obj.scroller = params && params.height !== undefined 50 ? $('#hdScroll' + obj.id) 51 : $(window); 52 53 if (params && params.scrollListenerEl !== undefined) { 54 obj.scroller = params.scrollListenerEl; 55 } 56 obj.scroller.on('scroll', function () { 57 if ($('#hd' + obj.id).length == 0) { 58 obj.grid.before('<div id="hd' + obj.id + '"></div>'); 59 } 60 61 obj.container = $('#hd' + obj.id); 62 let offsetTop = obj.floatingLen?obj.$floatingSuspensionCondition.offset():obj.header.offset(); 63 if ( offsetTop != null) { 64 obj.container.css("z-index", ('auto' === obj.header.css('z-index') ? 0 : obj.header.css('z-index')) + 2); 65 if(obj.floatingLen){ 66 let widthTb =0 67 if(obj.$floatingSuspensionCondition[0].className.indexOf('reverse-module-table-condition-search') != -1){ 68 // åæ¥æ¨¡åtableåºå®å¤´é¨å®½åº¦å¤ç 69 widthTb = $('.card-body').width() 70 }else{ 71 widthTb = obj.header.outerWidth() + 1; 72 } 73 // let widthTb = obj.header.outerWidth() + 1; 74 // obj.$floatingSuspensionCondition.css("position", "fixed"); 75 // obj.$floatingSuspensionCondition.outerWidth(widthTb +'px'); 76 } 77 if (limiteAlcancado(obj, params)) { 78 if (!obj.container.prop('data-copied-header')) { 79 cloneHeaderRow(obj); 80 obj.container.prop('data-copied-header', true); 81 } 82 } else { 83 if (($(document).scrollTop() > offsetTop.top)) { 84 obj.container.css("visibility", "hidden"); 85 // obj.container.css("position", "absolute"); 86 // obj.container.css("top", (obj.grid.find("tr:last").offset().top - obj.header.height()) + "px"); 87 } else { 88 obj.container.css("visibility", "hidden"); 89 obj.container.css("top", "0px"); 90 obj.container.width(0); 91 obj.$floatingSuspensionCondition.css("position", "static"); 92 obj.$floatingSuspensionCondition.width('auto'); 93 } 94 obj.container.prop('data-copied-header', false); 95 } 96 } 97 }); 98 } 99 } 100 101 function limiteAlcancado(obj, params) { 102 if (params && (params.height !== undefined || params.scrollListenerEl !== undefined)) { 103 return (obj.header.offset().top <= obj.scroller.offset().top); 104 } 105 else { 106 return ($(document).scrollTop() > obj.header.offset().top && $(document).scrollTop() < (obj.grid.height() - obj.header.height() - obj.grid.find("tr:last").height()) + obj.header.offset().top); 107 } 108 } 109 110 function cloneHeaderRow(obj) { 111 obj.container.html(''); 112 obj.container.val(''); 113 var tabela = $('<table style="margin: 0 0;"></table>'); 114 var atributos = obj.grid.prop("attributes"); 115 116 $.each(atributos, function () { 117 if (this.name != "id") { 118 tabela.attr(this.name, this.value); 119 } 120 }); 121 122 tabela.append('<thead>' + obj.header.html() + '</thead>'); 123 124 // 忥åå§ thead ä¸ select çå½åå¼å°å éä½ï¼.html() ä¸ä¿ç JS 设置çéä¸ç¶æï¼ 125 obj.header.find('select').each(function(i) { 126 tabela.find('select').eq(i).val($(this).val()); 127 }); 128 129 obj.container.append(tabela); 130 obj.container.width(obj.header.width() + 1); 131 obj.container.height(obj.header.height); 132 obj.container.find('th').each(function (index) { 133 var cellWidth = obj.grid.find('th').eq(index).css('width'); 134 $(this).css('width', cellWidth); 135 }); 136 137 obj.container.css("visibility", "visible"); 138 let currentClient = $('#current-client').val(); 139 let amz= $('#amz123').val(),miner=$('#is-miner').val(); 140 if (params && params.height !== undefined) { 141 142 if(params.offset !== undefined){ 143 obj.container.css("top", obj.scroller.offset().top + (params.offset.replace("px","") * 1) + "px"); 144 } 145 else 146 { 147 obj.container.css("top", obj.scroller.offset().top + "px"); 148 } 149 obj.container.css("position", "absolute"); 150 151 } else if (params && params.scrollListenerEl!== undefined) { 152 153 obj.container.css("top", obj.scroller.find("thead > tr").innerHeight() + "px"); 154 obj.container.css("position", "absolute"); 155 obj.container.css("z-index", "2"); 156 } else if (params && params.offset !== undefined) { 157 158 obj.container.css("top", params.offset); 159 obj.container.css("position", "fixed"); 160 } else { 161 // console.log(amz,'amz'); 162 // if(!currentClient && amz && miner){ 163 // obj.container.css("top", "0px"); 164 // }else{ 165 // obj.container.css("top",obj.floatingHeight+'px'); 166 // } 167 obj.container.css("top",'0px'); 168 obj.container.css("position", "fixed"); 169 } 170 171 if (tips_popover && obj.container) { 172 obj.container.find('[data-tips]').each(tips_popover); 173 } 174 if($('.checkbox-products-top10').length){ 175 $('.custom-checkbox').on('click','.checkbox-products-top10',function(){ 176 let isChecked = $('.custom-checkbox .checkbox-products-top10').prop('checked'); 177 let endIndex = isChecked?9:2; 178 $('input[name=itemImageRange]').val(endIndex); 179 localStorage.setItem("products-top-ten",endIndex); 180 $('#form-condition-search').submit(); 181 }) 182 } 183 } 184 185 return this.each(function (i, e) { 186 freezeHeader($(e)); 187 }); 188 189 }; 190})(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.