X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fprinttofit.js;fp=httemplate%2Felements%2Fprinttofit.js;h=66257fca81c0fcd603f506c9e6c0f58aac267261;hb=e215fc213a1eb9a3365cecf5ce82f1a58f154cd6;hp=0000000000000000000000000000000000000000;hpb=bf79875847923d0f33a2136d703dd7d9fb8c188a;p=freeside.git diff --git a/httemplate/elements/printtofit.js b/httemplate/elements/printtofit.js new file mode 100644 index 000000000..66257fca8 --- /dev/null +++ b/httemplate/elements/printtofit.js @@ -0,0 +1,26 @@ +$().ready(function() { + var beforePrint = function() { + if ($('body').width() > 0) { + // 7.5 inches * 96 DPI; maybe make the width a user pref? + var maxwidth = 7.5 * 96; + $('body').css('zoom', maxwidth / $('body').width()); + } + }; + var afterPrint = function() { + $('body').css('zoom', 1); + } + + if (window.matchMedia) { // chrome, most importantly; also IE10? + window.matchMedia('print').addListener( + function(mq) { + mq.matches ? beforePrint() : afterPrint(); + } + ); + } else { // other IE + $(window).on('beforeprint', beforePrint); + $(window).on('afterprint', afterPrint); + } + // got nothing for firefox + // https://bugzilla.mozilla.org/show_bug.cgi?id=774398 + // but firefox already has "shrink to fit" +});