/* Widget: print - updated 11/22/2015 (v2.24.6) *//* * Requires tablesorter v2.8+ and jQuery 1.2.6+ */ /*jshint browser:true, jquery:true, unused:false */ /*global jQuery: false */ ;(function($){ 'use strict'; var ts = $.tablesorter, printTable = ts.printTable = { event : 'printTable', basicStyle : 'table, tr, td, th { border : solid 1px black; border-collapse : collapse; } td, th { padding: 2px; }', popupStyle : 'width=500,height=300,scrollbars=1,resizable=1', init : function(c) { c.$table .unbind(printTable.event) .bind(printTable.event, function(){ // explicitly use table.config.widgetOptions because we want // the most up-to-date values; not the 'wo' from initialization printTable.process(c, c.widgetOptions); }); }, process : function(c, wo) { var $this, $table = $('
').append(c.$table.clone()), printStyle = printTable.basicStyle + 'table { width: 100%; }' + // hide filter row '.' + ( ts.css.filterRow || 'tablesorter-filter-row' ) + // hide filtered rows ', .' + ( wo.filter_filteredRow || 'filtered' ) + ' { display: none; }' + // hide sort arrows '.' + ( ts.css.header || 'tablesorter-header' ) + ' { background-image: none !important; }' + '@media print { .print_widget_hidden { display: none; } }'; // replace content with data-attribute content $table.find('[' + wo.print_dataAttrib + ']').each(function(){ $this = $(this); $this.text( $this.attr(wo.print_dataAttrib) ); }); // === rows === // Assume 'visible' means rows hidden by the pager (rows set to 'display:none') // or hidden by a class name which is added to the wo.print_extraCSS definition // look for jQuery filter selector in wo.print_rows & use if found if ( /^f/i.test( wo.print_rows ) ) { printStyle += 'tbody tr:not(.' + ( wo.filter_filteredRow || 'filtered' ) + ') { display: table-row !important; }'; } else if ( /^a/i.test( wo.print_rows ) ) { // default force show of all rows printStyle += 'tbody tr { display: table-row !important; }'; } else if ( /^[.#:\[]/.test( wo.print_rows ) ) { // look for '.' (class selector), '#' (id selector), // ':' (basic filters, e.g. ':not()') or '[' (attribute selector start) printStyle += 'tbody tr' + wo.print_rows + ' { display: table-row !important; }'; } // === columns === // columnSelector -> c.selector.$style // Assume 'visible' means hidden columns have a 'display:none' style, or a class name // add the definition to the wo.print_extraCSS option if (/s/i.test(wo.print_columns) && c.selector && c.widgets.indexOf('columnSelector') >= 0) { // show selected (visible) columns; make a copy of the columnSelector widget css (not media queries) printStyle += wo.columnSelector_mediaquery && c.selector.auto ? '' : c.selector.$style.text(); } else if (/a/i.test(wo.print_columns)) { // force show all cells printStyle += 'td, th { display: table-cell !important; }'; } printStyle += wo.print_extraCSS; // callback function if ( $.isFunction(wo.print_callback) ) { wo.print_callback( c, $table, printStyle ); } else { printTable.printOutput(c, $table.html(), printStyle); } }, // end process printOutput : function(c, data, style) { var wo = c.widgetOptions, lang = ts.language, generator = window.open( '', wo.print_title, printTable.popupStyle ), t = wo.print_title || c.$table.find('caption').text() || c.$table[0].id || document.title || 'table', button = wo.print_now ? '' : ' '; generator.document.write( '