1(function ($) { 2 Drupal.behaviors.datatables = { 3 attach: function (context, settings) { 4 $.each(settings.datatables, function (selector) { 5 $(selector, context).once('datatables', function() { 6 // Check if table contains expandable hidden rows. 7 var settings = Drupal.settings.datatables[selector]; 8 if (settings.bExpandable) { 9 // Insert a "view more" column to the table. 10 var nCloneTh = document.createElement('th'); 11 var nCloneTd = document.createElement('td'); 12 nCloneTd.innerHTML = '<a href="#" class="datatables-expand datatables-closed">Show Details</a>'; 13 14 $(selector + ' thead tr').each( function () { 15 this.insertBefore( nCloneTh, this.childNodes[0] ); 16 }); 17 18 $(selector + ' tbody tr').each( function () { 19 this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] ); 20 }); 21 22 settings.aoColumns.unshift({"bSortable": false}); 23 } 24 25 var datatable = $(selector).dataTable(settings); 26 27 if (settings.bExpandable) { 28 // Add column headers to table settings. 29 var datatables_settings = datatable.fnSettings(); 30 // Add blank column header for show details column. 31 settings.aoColumnHeaders.unshift(''); 32 // Add column headers to table settings. 33 datatables_settings.aoColumnHeaders = settings.aoColumnHeaders; 34 35 /* Add event listener for opening and closing details 36 * Note that the indicator for showing which row is open is not controlled by DataTables, 37 * rather it is done here 38 */ 39 $('td a.datatables-expand', datatable.fnGetNodes() ).each( function () { 40 $(this).click( function () { 41 var row = this.parentNode.parentNode; 42 if (datatable.fnIsOpen(row)) { 43 datatable.fnClose(row); 44 $(this).html('Show Details'); 45 } 46 else { 47 datatable.fnOpen( row, Drupal.theme('datatablesExpandableRow', datatable, row), 'details' ); 48 $(this).html('Hide Details'); 49 } 50 return false; 51 }); 52 }); 53 } 54 }); 55 }); 56 } 57 }; 58 59 /** 60 * Theme an expandable hidden row. 61 * 62 * @param object 63 * The datatable object. 64 * @param array 65 * The row array for which the hidden row is being displayed. 66 * @return 67 * The formatted text (html). 68 */ 69 Drupal.theme.prototype.datatablesExpandableRow = function(datatable, row) { 70 var rowData = datatable.fnGetData(row); 71 var settings = datatable.fnSettings(); 72 73 var output = '<table style="padding-left: 50px">'; 74 $.each(rowData, function(index) { 75 if (!settings.aoColumns[index].bVisible) { 76 output += '<tr><td>' + settings.aoColumnHeaders[index] + '</td><td style="text-align: left">' + this + '</td></tr>'; 77 } 78 }); 79 output += '</table>'; 80 return output; 81 }; 82})(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.