From 85a87a81a9ff95ef538712ace5e5ccf1909d2e2e Mon Sep 17 00:00:00 2001 From: tell-k Date: Tue, 22 Jan 2019 16:59:15 +0000 Subject: [PATCH] cmd/present: fix CSS when printing slides The existing CSS style was causing slides to not align with page boundaries when printing slides. The cause of that is the CSS transform property that is applied to automatically scale size of slides. This change clears the transform property just before printing. Fixes golang/go#29480 Change-Id: I6f719ad1b716e9bda8ba83007c3d1d7dece9ce08 GitHub-Last-Rev: d46dfee57601b2e9127c5e8e80e596dc2a2f24fa GitHub-Pull-Request: golang/tools#67 Reviewed-on: https://go-review.googlesource.com/c/155940 Run-TryBot: Dmitri Shuralyov TryBot-Result: Gobot Gobot Reviewed-by: Dmitri Shuralyov --- cmd/present/static/slides.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/present/static/slides.js b/cmd/present/static/slides.js index df10647e..ff08b82f 100644 --- a/cmd/present/static/slides.js +++ b/cmd/present/static/slides.js @@ -442,7 +442,7 @@ function handleBodyKeyDown(event) { }; function scaleSmallViewports() { - var el = document.querySelector('.slides'); + var el = document.querySelector('section.slides'); var transform = ''; var sWidthPx = 1250; var sHeightPx = 750; @@ -468,6 +468,20 @@ function addEventListeners() { scaleSmallViewports(); }, 50); }); + + // Force reset transform property of section.slides when printing page. + // Use both onbeforeprint and matchMedia for compatibility with different browsers. + var beforePrint = function() { + var el = document.querySelector('section.slides'); + el.style.transform = ''; + }; + window.onbeforeprint = beforePrint; + if (window.matchMedia) { + var mediaQueryList = window.matchMedia('print'); + mediaQueryList.addListener(function(mql) { + if (mql.matches) beforePrint(); + }); + } } /* Initialization */