| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
;(function($) { |
| 7 |
'use strict'; |
| 8 |
|
| 9 |
var ts = $.tablesorter, |
| 10 |
|
| 11 |
printTable = ts.printTable = { |
| 12 |
|
| 13 |
event : 'printTable', |
| 14 |
basicStyle : 'table, tr, td, th { border : solid 1px black; border-collapse : collapse; } td, th { padding: 2px; }', |
| 15 |
popupStyle : 'width=500,height=300,scrollbars=1,resizable=1', |
| 16 |
|
| 17 |
init : function(c) { |
| 18 |
c.$table |
| 19 |
.unbind(printTable.event) |
| 20 |
.bind(printTable.event, function() { |
| 21 |
|
| 22 |
|
| 23 |
printTable.process(c, c.widgetOptions); |
| 24 |
return false; |
| 25 |
}); |
| 26 |
}, |
| 27 |
|
| 28 |
process : function(c, wo) { |
| 29 |
var $this, data, |
| 30 |
$table = $('<div/>').append(c.$table.clone()), |
| 31 |
printStyle = printTable.basicStyle + 'table { width: 100%; }' + |
| 32 |
|
| 33 |
'.' + ( ts.css.filterRow || 'tablesorter-filter-row' ) + |
| 34 |
|
| 35 |
', .' + ( wo.filter_filteredRow || 'filtered' ) + ' { display: none; }' + |
| 36 |
|
| 37 |
'.' + ( ts.css.header || 'tablesorter-header' ) + ' { background-image: none !important; }' + |
| 38 |
|
| 39 |
'@media print { .print_widget_hidden { display: none; } }'; |
| 40 |
|
| 41 |
|
| 42 |
$table.find('[' + wo.print_dataAttrib + ']').each(function() { |
| 43 |
$this = $(this); |
| 44 |
$this.text( $this.attr(wo.print_dataAttrib) ); |
| 45 |
}); |
| 46 |
|
| 47 |
|
| 48 |
data = 'data-' + (wo.lazyload_data_attribute || 'original'); |
| 49 |
$table.find('img[' + data + ']').each(function() { |
| 50 |
$this = $(this); |
| 51 |
$this.attr('src', $this.attr(data)); |
| 52 |
}); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
if ( /^f/i.test( wo.print_rows ) ) { |
| 59 |
printStyle += 'tbody tr:not(.' + ( wo.filter_filteredRow || 'filtered' ) + ') { display: table-row !important; }'; |
| 60 |
} else if ( /^a/i.test( wo.print_rows ) ) { |
| 61 |
|
| 62 |
printStyle += 'tbody tr { display: table-row !important; }'; |
| 63 |
} else if ( /^[.#:\[]/.test( wo.print_rows ) ) { |
| 64 |
|
| 65 |
|
| 66 |
printStyle += 'tbody tr' + wo.print_rows + ' { display: table-row !important; }'; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if (/s/i.test(wo.print_columns) && c.selector && ts.hasWidget( c.table, 'columnSelector' )) { |
| 74 |
|
| 75 |
printStyle += wo.columnSelector_mediaquery && c.selector.auto ? '' : c.selector.$style.text(); |
| 76 |
} else if (/a/i.test(wo.print_columns)) { |
| 77 |
|
| 78 |
printStyle += 'td, th { display: table-cell !important; }'; |
| 79 |
} |
| 80 |
|
| 81 |
printStyle += wo.print_extraCSS; |
| 82 |
|
| 83 |
|
| 84 |
if ( $.isFunction(wo.print_callback) ) { |
| 85 |
wo.print_callback( c, $table, printStyle ); |
| 86 |
} else { |
| 87 |
printTable.printOutput(c, $table.html(), printStyle); |
| 88 |
} |
| 89 |
|
| 90 |
}, |
| 91 |
|
| 92 |
printOutput : function(c, data, style) { |
| 93 |
var wo = c.widgetOptions, |
| 94 |
lang = ts.language, |
| 95 |
generator = window.open( '', wo.print_title, printTable.popupStyle ), |
| 96 |
t = wo.print_title || c.$table.find('caption').text() || c.$table[0].id || document.title || 'table', |
| 97 |
button = wo.print_now ? '' : '<div class="print_widget_hidden"><a href="javascript:window.print();">' + |
| 98 |
'<button type="button">' + lang.button_print + '</button></a> <a href="javascript:window.close();">' + |
| 99 |
'<button type="button">' + lang.button_close + '</button></a><hr></div>'; |
| 100 |
generator.document.write( |
| 101 |
'<html><head><title>' + t + '</title>' + |
| 102 |
( wo.print_styleSheet ? '<link rel="stylesheet" href="' + wo.print_styleSheet + '">' : '' ) + |
| 103 |
'<style>' + style + '</style>' + |
| 104 |
'</head><body>' + button + data + '</body></html>' |
| 105 |
); |
| 106 |
generator.document.close(); |
| 107 |
|
| 108 |
|
| 109 |
if ( wo.print_now ) { |
| 110 |
setTimeout( function() { |
| 111 |
generator.print(); |
| 112 |
generator.close(); |
| 113 |
}, 10 ); |
| 114 |
} |
| 115 |
return true; |
| 116 |
}, |
| 117 |
|
| 118 |
remove : function(c) { |
| 119 |
c.$table.off(printTable.event); |
| 120 |
} |
| 121 |
|
| 122 |
}; |
| 123 |
|
| 124 |
ts.language.button_close = 'Close'; |
| 125 |
ts.language.button_print = 'Print'; |
| 126 |
|
| 127 |
ts.addWidget({ |
| 128 |
id: 'print', |
| 129 |
options: { |
| 130 |
print_title : '', |
| 131 |
print_dataAttrib : 'data-name', |
| 132 |
print_rows : 'filtered', |
| 133 |
print_columns : 'selected', |
| 134 |
print_extraCSS : '', |
| 135 |
print_styleSheet : '', |
| 136 |
print_now : true, |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
print_callback : null |
| 144 |
}, |
| 145 |
init: function(table, thisWidget, c) { |
| 146 |
printTable.init(c); |
| 147 |
}, |
| 148 |
remove: function(table, c) { |
| 149 |
printTable.remove(c); |
| 150 |
} |
| 151 |
|
| 152 |
}); |
| 153 |
|
| 154 |
})(jQuery); |