tablesorter/dist/js/widgets/widget-print.min.js

1 line
1.8 KiB
JavaScript

!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; }",init:function(a){a.$table.unbind(c.event).bind(c.event,function(){c.process(a,a.widgetOptions)})},process:function(b,d){var e,f=a("<div/>").append(b.$table.clone()),g=c.basicStyle+"table { width: 100% }.tablesorter-filter-row { display: none }.tablesorter-header { background-image: none !important; }";f.find("["+d.print_dataAttrib+"]").each(function(){e=a(this),e.text(e.attr(d.print_dataAttrib))}),/a/i.test(d.print_rows)?g+="tbody tr { display: table-row !important; }":/f/i.test(d.print_rows)&&(g+="tbody tr:not(."+(d.filter_filteredRow||"filtered")+") { display: table-row !important; }"),/s/i.test(d.print_columns)&&b.selector&&b.widgets.indexOf("columnSelector")>=0?g+=d.columnSelector_mediaquery&&b.selector.auto?"":b.selector.$style.text():/a/i.test(d.print_columns)&&(g+="td, th { display: table-cell !important; }"),g+=d.print_extraCSS,a.isFunction(d.print_callback)?d.print_callback(b,f,g):c.printOutput(b,f.html(),g)},printOutput:function(a,b,c){var d=a.widgetOptions,e=window.open("",d.print_title,"width=500,height=300"),f=d.print_title||a.$table.find("caption").text()||a.$table[0].id||document.title||"table";return e.document.write("<html><head><title>"+f+"</title>"+(d.print_styleSheet?'<link rel="stylesheet" href="'+d.print_styleSheet+'">':"")+"<style>"+c+"</style></head><body>"+b+"</body></html>"),e.document.close(),e.print(),e.close(),!0},remove:function(a){a.$table.off(c.event)}};b.addWidget({id:"print",options:{print_title:"",print_dataAttrib:"data-name",print_rows:"filtered",print_columns:"selected",print_extraCSS:"",print_styleSheet:"",print_callback:null},init:function(a,b,d){c.init(d)},remove:function(a,b){c.remove(b)}})}(jQuery);