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