3 var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
4 var beforePrint = function() {
5 if ($('body').width() > 0) {
6 // 7.5 inches * 96 DPI; maybe make the width a user pref?
7 var maxwidth = 7.5 * 96;
8 $('body').css('zoom', maxwidth / $('body').width());
10 // Chrome doesn't respect page-break-* styles on table rows/cells,
11 // so wrap the contents of table cells with a block element
12 // ref. Chromium bug #99124, #87828, #59193
13 // should be fixed with Chrome 53
14 var nosplits = $('.nosplitrows td');
15 if (nosplits.length > 0) {
16 nosplits.wrapInner('<div class="nosplit autowrap" />');
21 var afterPrint = function() {
22 $('body').css('zoom', 1);
23 // get the direct children of the wrapper divs.
24 var nosplits = $('div.autowrap >');
25 if (nosplits.length > 0) {
30 if (window.matchMedia) { // chrome, most importantly; also IE10?
31 window.matchMedia('print').addListener(
33 mq.matches ? beforePrint() : afterPrint();
37 $(window).on('beforeprint', beforePrint);
38 $(window).on('afterprint', afterPrint);
40 // got nothing for firefox
41 // https://bugzilla.mozilla.org/show_bug.cgi?id=774398
42 // but firefox already has "shrink to fit"