app/assets/javascripts/datatables/extensions/Buttons/buttons.print.js in jquery-datatables-1.10.15 vs app/assets/javascripts/datatables/extensions/Buttons/buttons.print.js in jquery-datatables-1.10.16
- old
+ new
@@ -85,11 +85,15 @@
text: function ( dt ) {
return dt.i18n( 'buttons.print', 'Print' );
},
action: function ( e, dt, button, config ) {
- var data = dt.buttons.exportData( config.exportOptions );
+ var data = dt.buttons.exportData(
+ $.extend( {decodeEntities: false}, config.exportOptions ) // XSS protection
+ );
+ var exportInfo = dt.buttons.exportInfo( config );
+
var addRow = function ( d, tag ) {
var str = '<tr>';
for ( var i=0, ien=d.length ; i<ien ; i++ ) {
str += '<'+tag+'>'+d[i]+'</'+tag+'>';
@@ -112,30 +116,21 @@
html += '</tbody>';
if ( config.footer && data.footer ) {
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';
}
+ html += '</table>';
// Open a new window for the printable table
var win = window.open( '', '' );
- var title = config.title;
-
- if ( typeof title === 'function' ) {
- title = title();
- }
-
- if ( title.indexOf( '*' ) !== -1 ) {
- title= title.replace( '*', $('title').text() );
- }
-
win.document.close();
// Inject the title and also a copy of the style and link tags from this
// document so the table can retain its base styling. Note that we have
// to use string manipulation as IE won't allow elements to be created
// in the host document and then appended to the new window.
- var head = '<title>'+title+'</title>';
+ var head = '<title>'+exportInfo.title+'</title>';
$('style, link').each( function () {
head += _styleToAbs( this );
} );
try {
@@ -145,18 +140,14 @@
$(win.document.head).html( head ); // Old IE
}
// Inject the table and other surrounding information
win.document.body.innerHTML =
- '<h1>'+title+'</h1>'+
- '<div>'+
- (typeof config.message === 'function' ?
- config.message( dt, button, config ) :
- config.message
- )+
- '</div>'+
- html;
+ '<h1>'+exportInfo.title+'</h1>'+
+ '<div>'+(exportInfo.messageTop || '')+'</div>'+
+ html+
+ '<div>'+(exportInfo.messageBottom || '')+'</div>';
$(win.document.body).addClass('dt-print-view');
$('img', win.document.body).each( function ( i, img ) {
img.setAttribute( 'src', _relToAbs( img.getAttribute('src') ) );
@@ -164,20 +155,23 @@
if ( config.customize ) {
config.customize( win );
}
+ // Allow stylesheets time to load
setTimeout( function () {
if ( config.autoPrint ) {
win.print(); // blocking - so close will not
win.close(); // execute until this is done
}
- }, 250 );
+ }, 1000 );
},
title: '*',
- message: '',
+ messageTop: '*',
+
+ messageBottom: '*',
exportOptions: {},
header: true,