|
31 | 31 | if(typeof window === "undefined" || window.navigator === undefined || window.navigator.userAgent === undefined){ return false; }
|
32 | 32 |
|
33 | 33 | let pdfobjectversion = "2.3";
|
34 |
| - let nav = window.navigator; |
| 34 | + let win = window; |
| 35 | + let nav = win.navigator; |
35 | 36 | let ua = nav.userAgent;
|
36 | 37 |
|
37 | 38 | //Fallback validation when navigator.pdfViewerEnabled is not supported
|
38 | 39 | let isModernBrowser = function (){
|
39 | 40 |
|
40 | 41 | /*
|
41 | 42 | userAgent sniffing is not the ideal path, but most browsers revoked the ability to check navigator.mimeTypes
|
42 |
| - for security purposes. Browsers have begun implementing navigator.pdfViewerEnabled, but older versions do not |
43 |
| - have navigator.pdfViewerEnabled or the ability to check navigator.mimeTypes. We're left with basic browser |
| 43 | + for security purposes. As of 2023, browsers have begun implementing navigator.pdfViewerEnabled, but older versions |
| 44 | + do not have navigator.pdfViewerEnabled or the ability to check navigator.mimeTypes. We're left with basic browser |
44 | 45 | sniffing and assumptions of PDF support based on browser vendor.
|
45 | 46 | */
|
46 | 47 |
|
47 | 48 | //Chromium has provided native PDF support since 2011.
|
48 | 49 | //Most modern browsers use Chromium under the hood: Google Chrome, Microsoft Edge, Opera, Brave, Vivaldi, Arc, and more.
|
49 |
| - let isChromium = (window.chrome !== undefined); |
| 50 | + let isChromium = (win.chrome !== undefined); |
50 | 51 |
|
51 | 52 | //Safari on macOS has provided native PDF support since 2009.
|
52 | 53 | //This code snippet also detects the DuckDuckGo browser, which uses Safari/Webkit under the hood.
|
53 |
| - let isSafari = (window.safari !== undefined || (nav.vendor !== undefined && /Apple/.test(nav.vendor) && /Safari/.test(ua))); |
| 54 | + let isSafari = (win.safari !== undefined || (nav.vendor !== undefined && /Apple/.test(nav.vendor) && /Safari/.test(ua))); |
54 | 55 |
|
55 | 56 | //Firefox has provided PDF support via PDFJS since 2013.
|
56 |
| - let isFirefox = (window.Mozilla !== undefined || /irefox/.test(ua)); |
| 57 | + let isFirefox = (win.Mozilla !== undefined || /irefox/.test(ua)); |
57 | 58 |
|
58 | 59 | return isChromium || isSafari || isFirefox;
|
59 | 60 |
|
|
76 | 77 | return !!ax; //convert resulting object to boolean
|
77 | 78 | };
|
78 | 79 |
|
79 |
| - let hasActiveXPDFPlugin = function (){ return ("ActiveXObject" in window) && (validateAX("AcroPDF.PDF") || validateAX("PDF.PdfCtrl")) }; |
| 80 | + let hasActiveXPDFPlugin = function (){ return ("ActiveXObject" in win) && (validateAX("AcroPDF.PDF") || validateAX("PDF.PdfCtrl")) }; |
80 | 81 |
|
81 | 82 | let checkSupport = function (){
|
82 | 83 |
|
|
87 | 88 |
|
88 | 89 | //As of June 2023, no mobile browsers properly support inline PDFs. If mobile, just say no.
|
89 | 90 | if(isMobileDevice){ return false; }
|
90 |
| - |
91 |
| - //Modern browsers began supporting navigation.pdfViewerEnabled in late 2022 and early 2023. |
| 91 | + |
| 92 | + //Modern browsers began supporting navigator.pdfViewerEnabled in late 2022 and early 2023. |
92 | 93 | let supportsPDFVE = (nav.pdfViewerEnabled === "boolean");
|
93 | 94 |
|
94 | 95 | //If browser supports nav.pdfViewerEnabled and is explicitly saying PDFs are NOT supported (e.g. PDFJS disabled by user in Firefox), respect it.
|
|
157 | 158 | //Is CSS selector
|
158 | 159 | targetNode = document.querySelector(targetSelector);
|
159 | 160 |
|
160 |
| - } else if (window.jQuery !== undefined && targetSelector instanceof jQuery && targetSelector.length) { |
| 161 | + } else if (win.jQuery !== undefined && targetSelector instanceof jQuery && targetSelector.length) { |
161 | 162 |
|
162 | 163 | //Is jQuery element. Extract HTML node
|
163 | 164 | targetNode = targetSelector.get(0);
|
|
0 commit comments