From e215fc213a1eb9a3365cecf5ce82f1a58f154cd6 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sat, 9 Jul 2016 10:32:46 -0700 Subject: [PATCH] optionally scale to the page width when printing, #71301 --- httemplate/elements/header-full.html | 3 +++ httemplate/elements/header-popup.html | 3 +++ httemplate/elements/printtofit.js | 26 ++++++++++++++++++++++++++ httemplate/pref/pref-process.html | 1 + httemplate/pref/pref.html | 9 +++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 httemplate/elements/printtofit.js diff --git a/httemplate/elements/header-full.html b/httemplate/elements/header-full.html index db38eafba..07595a539 100644 --- a/httemplate/elements/header-full.html +++ b/httemplate/elements/header-full.html @@ -47,6 +47,9 @@ Example: +% if ( $FS::CurrentUser::CurrentUser->option('printtofit') ) { + +% } % } <% include('init_overlib.html') |n %> <% include('rs_init_object.html') |n %> diff --git a/httemplate/elements/header-popup.html b/httemplate/elements/header-popup.html index 17593693e..6c0f80b37 100644 --- a/httemplate/elements/header-popup.html +++ b/httemplate/elements/header-popup.html @@ -30,6 +30,9 @@ Example: % unless ( $no_jquery ) { +% if ( $FS::CurrentUser::CurrentUser->option('printtofit') ) { + +% } % } <% $head |n %> 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" +}); diff --git a/httemplate/pref/pref-process.html b/httemplate/pref/pref-process.html index f03a8dfa3..b622efc15 100644 --- a/httemplate/pref/pref-process.html +++ b/httemplate/pref/pref-process.html @@ -55,6 +55,7 @@ unless ( $error ) { # if ($access_user) { disable_html_editor disable_enter_submit_onetimecharge enable_mask_clipboard_hack dashboard_customers customer_view_emails + printtofit email_address snom-ip snom-username snom-password vonage-fromnumber vonage-username vonage-password diff --git a/httemplate/pref/pref.html b/httemplate/pref/pref.html index 50d6e8d23..c6bcf6f66 100644 --- a/httemplate/pref/pref.html +++ b/httemplate/pref/pref.html @@ -130,6 +130,13 @@ Interface + Scale documents to fit on a letter-size page + + option('printtofit') ? 'CHECKED' : '' %>> + + + + How many recently-modified customers displayed on dashboard @@ -143,8 +150,6 @@ Interface - -
-- 2.11.0