summaryrefslogtreecommitdiff
path: root/httemplate/elements/printtofit.js
blob: 66257fca81c0fcd603f506c9e6c0f58aac267261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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"
});