diff options
author | Mark Wells <mark@freeside.biz> | 2016-07-09 10:32:46 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2016-07-09 10:33:10 -0700 |
commit | 408574c3f92b84f422f9a95dd0ab904d9c23ece6 (patch) | |
tree | 6060971bab1acae2a16bea9772b71d637b2b7fa0 /httemplate/elements | |
parent | db1221a82f407c9ebc782ff03e9cf61115eef8cb (diff) |
optionally scale to the page width when printing, #71301
Diffstat (limited to 'httemplate/elements')
-rw-r--r-- | httemplate/elements/header-full.html | 3 | ||||
-rw-r--r-- | httemplate/elements/header-popup.html | 3 | ||||
-rw-r--r-- | httemplate/elements/printtofit.js | 26 |
3 files changed, 32 insertions, 0 deletions
diff --git a/httemplate/elements/header-full.html b/httemplate/elements/header-full.html index 611da10dc..2e1047486 100644 --- a/httemplate/elements/header-full.html +++ b/httemplate/elements/header-full.html @@ -47,6 +47,9 @@ Example: <link rel="stylesheet" href="<% $fsurl %>elements/jquery-ui.min.css"> <SCRIPT SRC="<% $fsurl %>elements/jquery.js"></SCRIPT> <SCRIPT SRC="<% $fsurl %>elements/jquery-ui.min.js"></SCRIPT> +% if ( $FS::CurrentUser::CurrentUser->option('printtofit') ) { + <SCRIPT SRC="<% $fsurl %>elements/printtofit.js"></SCRIPT> +% } % } <% include('init_overlib.html') |n %> diff --git a/httemplate/elements/header-popup.html b/httemplate/elements/header-popup.html index f1ac86cd5..04709ce53 100644 --- a/httemplate/elements/header-popup.html +++ b/httemplate/elements/header-popup.html @@ -30,6 +30,9 @@ Example: <META HTTP-Equiv="Expires" Content="0"> % unless ( $no_jquery ) { <SCRIPT SRC="<% $fsurl %>elements/jquery.js"></SCRIPT> +% if ( $FS::CurrentUser::CurrentUser->option('printtofit') ) { + <SCRIPT SRC="<% $fsurl %>elements/printtofit.js"></SCRIPT> +% } % } <% $head |n %> </HEAD> 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" +}); |