Mercurial > hg > orthanc-stone
annotate Applications/StoneWebViewer/Resources/Graveyard/print-2.js @ 1801:64dad1d7aca4
renamed subclass
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 13:23:59 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
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 |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1660
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * 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
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * 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
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * 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
|
18 * 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
|
19 **/ |
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 |
1660
05b55b89a134
use local copy of open-sans, remove ua-parser
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1654
diff
changeset
|
22 // 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
|
23 |
1654
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 function beforePrint(event) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 var body = $('body'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 body.addClass('print'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 // 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
|
29 // 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
|
30 // 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
|
31 // 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
|
32 var uaParser = new UAParser(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 //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
|
37 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 if (isFirefox || isIE || isEdge) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 if (0) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 // This is Letter |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 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
|
42 body.css('height', '11in'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } else { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 // This is A4 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 body.css('width', '210mm'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 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
|
47 } |
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 $('#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
|
51 if ($(canvas).is(':visible')) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 $(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
|
53 $(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
|
54 } |
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 stone.FitForPrint(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 }; |
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 function afterPrint() { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 var body = $('body'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 body.removeClass('print'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 body.css('width', '100%'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 body.css('height', '100%'); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 $('#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
|
67 $('#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
|
68 |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 stone.FitForPrint(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
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 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
|
74 beforePrint(event); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 }); |
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 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
|
79 if (mql.matches) { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 // webkit equivalent of onbeforeprint |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 beforePrint(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
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 window.addEventListener('afterprint', function() { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 afterPrint(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 }); |
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 /*vm.cancelPrintMode = function() { |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 afterPrint(); |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 } |
39137da83b0b
fix print.js, no need for ua-parser.js anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 */ |