2015-12-13 22:24:42 +00:00
|
|
|
/* Widget: print - updated 12/13/2015 (v2.25.0) *//*
|
2014-06-12 02:41:40 +00:00
|
|
|
* Requires tablesorter v2.8+ and jQuery 1.2.6+
|
2014-05-06 00:46:01 +00:00
|
|
|
*/
|
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
/*global jQuery: false */
|
2016-02-24 16:57:38 +00:00
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'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; }',
|
2015-11-30 13:52:57 +00:00
|
|
|
popupStyle : 'width=500,height=300,scrollbars=1,resizable=1',
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
init : function(c) {
|
|
|
|
c.$table
|
|
|
|
.unbind(printTable.event)
|
2016-02-24 16:57:38 +00:00
|
|
|
.bind(printTable.event, function() {
|
2015-07-23 04:29:51 +00:00
|
|
|
// explicitly use table.config.widgetOptions because we want
|
|
|
|
// the most up-to-date values; not the 'wo' from initialization
|
|
|
|
printTable.process(c, c.widgetOptions);
|
2016-02-24 16:57:38 +00:00
|
|
|
return false;
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
process : function(c, wo) {
|
|
|
|
var $this,
|
|
|
|
$table = $('<div/>').append(c.$table.clone()),
|
2015-10-17 14:36:37 +00:00
|
|
|
printStyle = printTable.basicStyle + 'table { width: 100%; }' +
|
2015-07-23 04:29:51 +00:00
|
|
|
// hide filter row
|
2015-10-17 14:36:37 +00:00
|
|
|
'.' + ( ts.css.filterRow || 'tablesorter-filter-row' ) +
|
|
|
|
// hide filtered rows
|
|
|
|
', .' + ( wo.filter_filteredRow || 'filtered' ) + ' { display: none; }' +
|
2015-07-23 04:29:51 +00:00
|
|
|
// hide sort arrows
|
2015-11-17 19:45:00 +00:00
|
|
|
'.' + ( ts.css.header || 'tablesorter-header' ) + ' { background-image: none !important; }' +
|
|
|
|
|
|
|
|
'@media print { .print_widget_hidden { display: none; } }';
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// replace content with data-attribute content
|
2016-02-24 16:57:38 +00:00
|
|
|
$table.find('[' + wo.print_dataAttrib + ']').each(function() {
|
2015-07-23 04:29:51 +00:00
|
|
|
$this = $(this);
|
|
|
|
$this.text( $this.attr(wo.print_dataAttrib) );
|
2014-05-06 00:46:01 +00:00
|
|
|
});
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// === 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
|
2015-11-01 18:06:39 +00:00
|
|
|
// look for jQuery filter selector in wo.print_rows & use if found
|
|
|
|
if ( /^f/i.test( wo.print_rows ) ) {
|
2015-10-14 17:51:27 +00:00
|
|
|
printStyle += 'tbody tr:not(.' + ( wo.filter_filteredRow || 'filtered' ) + ') { display: table-row !important; }';
|
2015-11-01 18:06:39 +00:00
|
|
|
} 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; }';
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// === 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,
|
2015-11-17 19:45:00 +00:00
|
|
|
lang = ts.language,
|
2015-10-14 17:51:27 +00:00
|
|
|
generator = window.open( '', wo.print_title, printTable.popupStyle ),
|
2015-11-17 19:45:00 +00:00
|
|
|
t = wo.print_title || c.$table.find('caption').text() || c.$table[0].id || document.title || 'table',
|
2015-11-17 20:21:17 +00:00
|
|
|
button = wo.print_now ? '' : '<div class="print_widget_hidden"><a href="javascript:window.print();">' +
|
|
|
|
'<button type="button">' + lang.button_print + '</button></a> <a href="javascript:window.close();">' +
|
|
|
|
'<button type="button">' + lang.button_close + '</button></a><hr></div>';
|
2015-07-23 04:29:51 +00:00
|
|
|
generator.document.write(
|
|
|
|
'<html><head><title>' + t + '</title>' +
|
|
|
|
( wo.print_styleSheet ? '<link rel="stylesheet" href="' + wo.print_styleSheet + '">' : '' ) +
|
|
|
|
'<style>' + style + '</style>' +
|
2015-11-17 19:45:00 +00:00
|
|
|
'</head><body>' + button + data + '</body></html>'
|
2015-07-23 04:29:51 +00:00
|
|
|
);
|
|
|
|
generator.document.close();
|
2015-10-17 14:37:56 +00:00
|
|
|
// use timeout to allow browser to build DOM before printing
|
|
|
|
// Print preview in Chrome doesn't work without this code
|
2015-11-17 19:45:00 +00:00
|
|
|
if ( wo.print_now ) {
|
|
|
|
setTimeout( function() {
|
|
|
|
generator.print();
|
|
|
|
generator.close();
|
|
|
|
}, 10 );
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
remove : function(c) {
|
|
|
|
c.$table.off(printTable.event);
|
2014-05-06 00:46:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
};
|
|
|
|
|
2015-11-17 19:45:00 +00:00
|
|
|
ts.language.button_close = 'Close';
|
|
|
|
ts.language.button_print = 'Print';
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
ts.addWidget({
|
|
|
|
id: 'print',
|
|
|
|
options: {
|
|
|
|
print_title : '', // this option > caption > table id > 'table'
|
|
|
|
print_dataAttrib : 'data-name', // header attrib containing modified header name
|
2015-11-01 18:06:39 +00:00
|
|
|
print_rows : 'filtered', // (a)ll, (v)isible, (f)iltered or custom css selector
|
|
|
|
print_columns : 'selected', // (a)ll, (v)isbible or (s)elected (if columnSelector widget is added)
|
2015-07-23 04:29:51 +00:00
|
|
|
print_extraCSS : '', // add any extra css definitions for the popup window here
|
|
|
|
print_styleSheet : '', // add the url of your print stylesheet
|
2015-11-17 19:45:00 +00:00
|
|
|
print_now : true, // Open the print dialog immediately if true
|
2015-07-23 04:29:51 +00:00
|
|
|
// callback executed when processing completes
|
|
|
|
// to continue printing, use the following function:
|
|
|
|
// function( config, $table, printStyle ) {
|
|
|
|
// // do something to the table or printStyle string
|
|
|
|
// $.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
|
|
|
|
// }
|
|
|
|
print_callback : null
|
|
|
|
},
|
|
|
|
init: function(table, thisWidget, c) {
|
|
|
|
printTable.init(c);
|
|
|
|
},
|
2016-02-24 16:57:38 +00:00
|
|
|
remove: function(table, c) {
|
2015-07-23 04:29:51 +00:00
|
|
|
printTable.remove(c);
|
2014-05-06 15:23:48 +00:00
|
|
|
}
|
2014-05-06 00:46:01 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
2014-05-06 00:46:01 +00:00
|
|
|
|
|
|
|
})(jQuery);
|