summaryrefslogtreecommitdiff
path: root/httemplate/elements/printtofit.js
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/elements/printtofit.js')
-rw-r--r--httemplate/elements/printtofit.js26
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"
+});