From a68829184b47f6ede4ec4c993087991b4f683d1f Mon Sep 17 00:00:00 2001 From: Michael Gibson Date: Fri, 21 Feb 2020 08:24:13 -0700 Subject: [PATCH] Fixes for "use strict" mode. In "use strict" mode UPNG was not added to window and also "UZIP is not defined" error was displayed. Fixed these 2 issues in a way that is backwards compatible with IE, Edge, and some mobile devices. --- UPNG.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/UPNG.js b/UPNG.js index a1c0106..8a1fb77 100644 --- a/UPNG.js +++ b/UPNG.js @@ -1,5 +1,10 @@ var UPNG = {}; +if (typeof globalThis === 'object') { + globalThis.UPNG = UPNG; +} else if (typeof window === 'object') { + window.UPNG = UPNG; +}; @@ -786,7 +791,7 @@ UPNG.encode._filterZero = function(img,h,bpp,bpl,data, filter, levelZero) else if(h*bpl>500000 || bpp==1) ftry=[0]; var opts; if(levelZero) opts={level:0}; - var CMPR = (levelZero && UZIP!=null) ? UZIP : pako; + var CMPR = (levelZero && typeof UZIP === 'object' && UZIP!=null) ? UZIP : pako; for(var i=0; i