Skip to content

Commit beb35c4

Browse files
committed
Shortcut for window, cleanup
Using variable for window to aid in minification
1 parent 89cb3ae commit beb35c4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pdfobject.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,30 @@
3131
if(typeof window === "undefined" || window.navigator === undefined || window.navigator.userAgent === undefined){ return false; }
3232

3333
let pdfobjectversion = "2.3";
34-
let nav = window.navigator;
34+
let win = window;
35+
let nav = win.navigator;
3536
let ua = nav.userAgent;
3637

3738
//Fallback validation when navigator.pdfViewerEnabled is not supported
3839
let isModernBrowser = function (){
3940

4041
/*
4142
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
4445
sniffing and assumptions of PDF support based on browser vendor.
4546
*/
4647

4748
//Chromium has provided native PDF support since 2011.
4849
//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);
5051

5152
//Safari on macOS has provided native PDF support since 2009.
5253
//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)));
5455

5556
//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));
5758

5859
return isChromium || isSafari || isFirefox;
5960

@@ -76,7 +77,7 @@
7677
return !!ax; //convert resulting object to boolean
7778
};
7879

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")) };
8081

8182
let checkSupport = function (){
8283

@@ -87,8 +88,8 @@
8788

8889
//As of June 2023, no mobile browsers properly support inline PDFs. If mobile, just say no.
8990
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.
9293
let supportsPDFVE = (nav.pdfViewerEnabled === "boolean");
9394

9495
//If browser supports nav.pdfViewerEnabled and is explicitly saying PDFs are NOT supported (e.g. PDFJS disabled by user in Firefox), respect it.
@@ -157,7 +158,7 @@
157158
//Is CSS selector
158159
targetNode = document.querySelector(targetSelector);
159160

160-
} else if (window.jQuery !== undefined && targetSelector instanceof jQuery && targetSelector.length) {
161+
} else if (win.jQuery !== undefined && targetSelector instanceof jQuery && targetSelector.length) {
161162

162163
//Is jQuery element. Extract HTML node
163164
targetNode = targetSelector.get(0);

0 commit comments

Comments
 (0)