tablesorter/dist/js/widgets/widget-print.min.js
2015-11-02 10:50:31 -06:00

49 lines
3.9 KiB
JavaScript

/* Widget: print - updated 11/2/2015 (v2.24.1) */
/*
* Requires tablesorter v2.8+ and jQuery 1.2.6+
*/
/*jshint browser:true, jquery:true, unused:false */
/*global jQuery: false */
!function(a){"use strict";var b=a.tablesorter,c=b.printTable={event:"printTable",basicStyle:"table, tr, td, th { border : solid 1px black; border-collapse : collapse; } td, th { padding: 2px; }",popupStyle:"width=500,height=300",init:function(a){a.$table.unbind(c.event).bind(c.event,function(){
// explicitly use table.config.widgetOptions because we want
// the most up-to-date values; not the 'wo' from initialization
c.process(a,a.widgetOptions)})},process:function(d,e){var f,g=a("<div/>").append(d.$table.clone()),h=c.basicStyle+"table { width: 100%; }."+(b.css.filterRow||"tablesorter-filter-row")+
// hide filtered rows
", ."+(e.filter_filteredRow||"filtered")+" { display: none; }."+(b.css.header||"tablesorter-header")+" { background-image: none !important; }";
// replace content with data-attribute content
g.find("["+e.print_dataAttrib+"]").each(function(){f=a(this),f.text(f.attr(e.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
/^f/i.test(e.print_rows)?h+="tbody tr:not(."+(e.filter_filteredRow||"filtered")+") { display: table-row !important; }":/^a/i.test(e.print_rows)?
// default force show of all rows
h+="tbody tr { display: table-row !important; }":/^[.#:\[]/.test(e.print_rows)&&(
// look for '.' (class selector), '#' (id selector),
// ':' (basic filters, e.g. ':not()') or '[' (attribute selector start)
h+="tbody tr"+e.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
/s/i.test(e.print_columns)&&d.selector&&d.widgets.indexOf("columnSelector")>=0?
// show selected (visible) columns; make a copy of the columnSelector widget css (not media queries)
h+=e.columnSelector_mediaquery&&d.selector.auto?"":d.selector.$style.text():/a/i.test(e.print_columns)&&(
// force show all cells
h+="td, th { display: table-cell !important; }"),h+=e.print_extraCSS,a.isFunction(e.print_callback)?e.print_callback(d,g,h):c.printOutput(d,g.html(),h)},// end process
printOutput:function(a,b,d){var e=a.widgetOptions,f=window.open("",e.print_title,c.popupStyle),g=e.print_title||a.$table.find("caption").text()||a.$table[0].id||document.title||"table";
// use timeout to allow browser to build DOM before printing
// Print preview in Chrome doesn't work without this code
return f.document.write("<html><head><title>"+g+"</title>"+(e.print_styleSheet?'<link rel="stylesheet" href="'+e.print_styleSheet+'">':"")+"<style>"+d+"</style></head><body>"+b+"</body></html>"),f.document.close(),setTimeout(function(){f.print(),f.close()},10),!0},remove:function(a){a.$table.off(c.event)}};b.addWidget({id:"print",options:{print_title:"",// this option > caption > table id > 'table'
print_dataAttrib:"data-name",// header attrib containing modified header name
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)
print_extraCSS:"",// add any extra css definitions for the popup window here
print_styleSheet:"",// add the url of your print stylesheet
// 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(a,b,d){c.init(d)},remove:function(a,b){c.remove(b)}})}(jQuery);