1const phoenix = {}; 2(function($) { 3 $(document).ready(function() { 4 phoenix.fn.onReady(); 5 }); 6 phoenix.fn = { 7 onReady: function () { 8 this.bindEvents(); 9 if (window.phoenix.config.tablePressShowAllBtn === 'true') { 10 setTimeout(function() { 11 phoenix.fn.checkTablePagination(); // Really hate to do this, but I have no way of knowing when pagination is fired. 12 }, 1250); // Moving this up 13 } 14 }, 15 checkTableSize(tableId) { 16 const selectBoxSelected = $(tableId + ' :selected').text(); 17 const tableInfo = $(tableId + ' .dataTables_info').text(); 18 19 if (tableInfo !== '') { 20 let rowCount = Number(tableInfo.split(' ').slice(-2, -1)[0]); 21 return rowCount > Number(selectBoxSelected); 22 } else { 23 return false 24 } 25 }, 26 checkTablePagination() { 27 const self = this; 28 const responsiveTables = $('.phoenix-tablepress-wrapper'); 29 30 if (responsiveTables.length >= 1) { 31 runConfig(responsiveTables); 32 } 33 34 function runConfig(tables) { 35 tables.each(function(key, index) { 36 let tableId = '#' + $(index).attr('id'); 37 let tableSelect = $(tableId).find('select'); 38 let tableOptions = $(tableId).find('select option'); // Used to make sure -1 is in the select 39 let pluginEnabled = false; 40 $(tableOptions).each(function(){ // https://stackoverflow.com/questions/2248976/check-if-value-is-in-select-list-with-jquery 41 if (this.value === '-1') { 42 pluginEnabled = true; 43 return false; 44 } 45 }); 46 47 // Checking to make sure the tableSelect box is enabled & plugin is enabled that injects -1 48 if (tableSelect.length >= 1 && pluginEnabled) { 49 let tableIdInt = tableId.split('-')[1]; 50 let hideSelectors = [ 51 tableId + ' select[name="tablepress-' + tableIdInt + '_length"]', 52 tableId + ' select[name="tablepress-' + tableIdInt + '_length"] + label', 53 tableId + ' nav[aria-label="pagination"]', 54 ]; 55 $(hideSelectors.join(', ')).hide(); // Hiding select & filter box 56 if (window.phoenix.config.tablePressShowAllBtnRowFix === 'true') { // Check if tableSize is the same size as table select 57 if (self.checkTableSize(tableId)) { 58 self.insertShowAllBtn(tableId); // Inserting show all button 59 } 60 } else { 61 self.insertShowAllBtn(tableId); // Inserting show all button 62 } 63 } 64 }); 65 } 66 67 68 }, 69 insertShowAllBtn: function(table) { 70 // When a Fixed column is selected on Tablepress settings, 3 tables are rendered (header, body, footer) 71 // tableFixedColumnSelector will grab the body table. 72 // The default behavior is to render one table per wrapper. 73 const tableFixedColumnSelector = '#' + $(table).attr('id') + ' .dataTables_scrollBody table'; 74 const tableDefaultSelector = '#' + $(table).attr('id') + ' table'; 75 76 var targetTable = $(tableFixedColumnSelector) ; 77 78 if(targetTable.length === 0){ 79 targetTable = $(tableDefaultSelector); 80 } 81 82 var DTtable = new DataTable(targetTable); 83 var rowCount = DTtable.rows().count(); 84 85 $(table).append( 86 '<div class="table-show-all-button" tableid="'+ table +'">' + 87 '<a class="button">Show All Rows</a>' + 88 '</div>' 89 ); 90 let tableSelect = $(table).find('select'); 91 if (window.innerWidth > 1024) { 92 let btn = $(table + ' .table-show-all-button a.button'); 93 // toggle button twice so that it shows 10 rows instead of 5 94 btn.click(); 95 btn.click(); 96 tableSelect.val('10').change(); 97 if (rowCount <= 10) { 98 $(table + ' .table-show-all-button').hide(); 99 } 100 } else { 101 tableSelect.val('5').change(); 102 if (rowCount <= 5) { 103 $(table + ' .table-show-all-button').hide(); 104 } 105 } 106 }, 107 tablePressShowAll: function(btn, tableId) { 108 let tableSelect = $(tableId).find('select'); 109 110 if (tableSelect.val() !== '-1') { 111 tableSelect.val('-1').change(); 112 $(btn).text('Collapse') // Updates btn copy 113 } else { 114 if (window.innerWidth > 1024) { 115 tableSelect.val('10').change(); 116 } else { 117 tableSelect.val('5').change(); 118 } 119 // tableSelect.prop('selectedIndex', 0).change(); 120 $(btn).text('Show All Rows') // Updates btn copy 121 } 122 }, 123 bindEvents: function() { 124 this.doBind( 'global' ); 125 }, 126 doBind: function( key ) { 127 for (let i = 0; i < phoenix.eventBinds[ key ].length; i++ ) { 128 let bind = phoenix.eventBinds[ key ][ i ]; 129 $( bind.handler || document ).on( bind.event, bind.selector, bind.fn ); 130 } 131 } 132 } 133})(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.