4.x style
[freeside.git] / httemplate / elements / printtofit.js
1 $().ready(function() {
2   var beforePrint = function() {
3     if ($('body').width() > 0) {
4       // 7.5 inches * 96 DPI; maybe make the width a user pref?
5       var maxwidth = 7.5 * 96;
6       $('body').css('zoom', maxwidth / $('body').width());
7     }
8   };
9   var afterPrint = function() {
10     $('body').css('zoom', 1);
11   }
12
13   if (window.matchMedia) { // chrome, most importantly; also IE10?
14     window.matchMedia('print').addListener(
15       function(mq) {
16         mq.matches ?  beforePrint() : afterPrint();
17       }
18     );
19   } else { // other IE
20     $(window).on('beforeprint', beforePrint);
21     $(window).on('afterprint', afterPrint);
22   }
23   // got nothing for firefox
24   // https://bugzilla.mozilla.org/show_bug.cgi?id=774398
25   // but firefox already has "shrink to fit"
26 });