Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/Resources/Graveyard/print-2.js @ 1654:39137da83b0b
fix print.js, no need for ua-parser.js anymore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Nov 2020 09:32:40 +0100 |
parents | |
children | 05b55b89a134 |
comparison
equal
deleted
inserted
replaced
1653:2e3b2ed239b9 | 1654:39137da83b0b |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 function beforePrint(event) { | |
23 var body = $('body'); | |
24 body.addClass('print'); | |
25 | |
26 // because firefox does not support/executes codes after the cloned document as been rendered | |
27 // https://bugzilla.mozilla.org/show_bug.cgi?format=default&id=1048317 | |
28 // we cannot calculate using the good body size for the clone document | |
29 // so we have to hardcode the body width (meaning we can only renders in A4 in firefox); | |
30 var uaParser = new UAParser(); | |
31 var isFirefox = (uaParser.getBrowser().name === 'Firefox'); | |
32 var isIE = (uaParser.getBrowser().name === 'IE'); | |
33 var isEdge = (uaParser.getBrowser().name === 'Edge'); | |
34 //console.log('ua parser', uaParser.getBrowser()); | |
35 | |
36 if (isFirefox || isIE || isEdge) { | |
37 if (0) { | |
38 // This is Letter | |
39 body.css('width', '8.5in'); | |
40 body.css('height', '11in'); | |
41 } else { | |
42 // This is A4 | |
43 body.css('width', '210mm'); | |
44 body.css('height', '296mm'); // If using "297mm", Firefox creates a second blank page | |
45 } | |
46 } | |
47 | |
48 $('#viewport canvas').each(function(key, canvas) { | |
49 if ($(canvas).is(':visible')) { | |
50 $(canvas).width($(canvas).parent().width()); | |
51 $(canvas).height($(canvas).parent().height()); | |
52 } | |
53 }); | |
54 | |
55 stone.FitForPrint(); | |
56 }; | |
57 | |
58 | |
59 function afterPrint() { | |
60 var body = $('body'); | |
61 body.removeClass('print'); | |
62 body.css('width', '100%'); | |
63 body.css('height', '100%'); | |
64 $('#viewport canvas').css('width', '100%'); | |
65 $('#viewport canvas').css('height', '100%'); | |
66 | |
67 stone.FitForPrint(); | |
68 } | |
69 | |
70 | |
71 window.addEventListener('beforeprint', function(event) { | |
72 beforePrint(event); | |
73 }); | |
74 | |
75 | |
76 window.matchMedia('print').addListener(function(mql) { | |
77 if (mql.matches) { | |
78 // webkit equivalent of onbeforeprint | |
79 beforePrint(); | |
80 } | |
81 }); | |
82 | |
83 | |
84 window.addEventListener('afterprint', function() { | |
85 afterPrint(); | |
86 }); | |
87 | |
88 | |
89 /*vm.cancelPrintMode = function() { | |
90 afterPrint(); | |
91 } | |
92 */ |