app/assets/javascripts/datatables/extensions/Buttons/buttons.print.js in jquery-datatables-1.10.13 vs app/assets/javascripts/datatables/extensions/Buttons/buttons.print.js in jquery-datatables-1.10.15
- old
+ new
@@ -38,34 +38,46 @@
var _link = document.createElement( 'a' );
/**
- * Convert a `link` tag's URL from a relative to an absolute address so it will
- * work correctly in the popup window which has no base URL.
+ * Clone link and style tags, taking into account the need to change the source
+ * path.
*
* @param {node} el Element to convert
*/
-var _relToAbs = function( el ) {
+var _styleToAbs = function( el ) {
var url;
var clone = $(el).clone()[0];
var linkHost;
if ( clone.nodeName.toLowerCase() === 'link' ) {
- _link.href = clone.href;
- linkHost = _link.host;
+ clone.href = _relToAbs( clone.href );
+ }
- // IE doesn't have a trailing slash on the host
- // Chrome has it on the pathname
- if ( linkHost.indexOf('/') === -1 && _link.pathname.indexOf('/') !== 0) {
- linkHost += '/';
- }
+ return clone.outerHTML;
+};
- clone.href = _link.protocol+"//"+linkHost+_link.pathname+_link.search;
+/**
+ * Convert a URL from a relative to an absolute address so it will work
+ * correctly in the popup window which has no base URL.
+ *
+ * @param {string} href URL
+ */
+var _relToAbs = function( href ) {
+ // Assign to a link on the original page so the browser will do all the
+ // hard work of figuring out where the file actually is
+ _link.href = href;
+ var linkHost = _link.host;
+
+ // IE doesn't have a trailing slash on the host
+ // Chrome has it on the pathname
+ if ( linkHost.indexOf('/') === -1 && _link.pathname.indexOf('/') !== 0) {
+ linkHost += '/';
}
- return clone.outerHTML;
+ return _link.protocol+"//"+linkHost+_link.pathname+_link.search;
};
DataTable.ext.buttons.print = {
className: 'buttons-print',
@@ -121,11 +133,11 @@
// 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>';
$('style, link').each( function () {
- head += _relToAbs( this );
+ head += _styleToAbs( this );
} );
try {
win.document.head.innerHTML = head; // Work around for Edge
}
@@ -143,9 +155,13 @@
)+
'</div>'+
html;
$(win.document.body).addClass('dt-print-view');
+
+ $('img', win.document.body).each( function ( i, img ) {
+ img.setAttribute( 'src', _relToAbs( img.getAttribute('src') ) );
+ } );
if ( config.customize ) {
config.customize( win );
}