diff options
| author | Ivan Kohler <ivan@freeside.biz> | 2016-07-20 13:02:15 -0700 |
|---|---|---|
| committer | Ivan Kohler <ivan@freeside.biz> | 2016-07-20 13:02:15 -0700 |
| commit | c22d84e565ab16db142395dce2e8621624eff140 (patch) | |
| tree | 3670e2bc0bf200910c3af24e5459e8b6966a992b /httemplate/elements/printtofit.js | |
| parent | e9a7ae3aadab31f34c6bacb2376f817ecd4d7d8d (diff) | |
| parent | f235a64b4e96e8d613fb3ecdd3acc7f65f9f291d (diff) | |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/elements/printtofit.js')
| -rw-r--r-- | httemplate/elements/printtofit.js | 26 |
1 files changed, 26 insertions, 0 deletions
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" +}); |
