2015-10-31 15:08:21 +00:00
/* Widget: print - updated 2/7/2015 (v2.19.0) */
/ *
* 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
/a/i . test ( e . print _rows ) ?
// force show of all rows
h += "tbody tr { display: table-row !important; }" : /f/i . test ( e . print _rows ) && (
// add definition to show all non-filtered rows (cells hidden by the pager)
h += "tbody tr:not(." + ( e . filter _filteredRow || "filtered" ) + ") { 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 or (f)iltered
print _columns : "selected" , // (a)ll 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 ) ;