PageSourceSearch

https://www.textilia.dk/wp-content/plugins/ewww-image-optimizer/includes/lazysizes-post.js?ver=880

js textilia.dk collected 2026-10-08 12:39:34 UTC 22,937 bytes, 632 lines download raw bytes

1(function(window, factory) {
2	var globalInstall = function(){
3		factory(window.lazySizes);
4		window.removeEventListener('lazyunveilread', globalInstall, true);
5	};
6
7	factory = factory.bind(null, window, window.document);
8
9	if(typeof module == 'object' && module.exports){
10		factory(require('lazysizes'));
11	} else if (typeof define == 'function' && define.amd) {
12		define(['lazysizes'], factory);
13	} else if(window.lazySizes) {
14		globalInstall();
15	} else {
16		window.addEventListener('lazyunveilread', globalInstall, true);
17	}
18}(window, function(window, document, lazySizes) {
19	/*jshint eqnull:true */
20	'use strict';
21	var regBgUrlEscape;
22	var autosizedElems = [];
23
24	if(document.addEventListener){
25		regBgUrlEscape = /\(|\)|\s|'/;
26
27		addEventListener('lazybeforeunveil', function(e){
28			if(e.detail.instance != lazySizes){return;}
29
30			var bg, bgWebP,swisLazyId;
31			if(!e.defaultPrevented) {
32
33				if(e.target.preload == 'none'){
34					e.target.preload = 'auto';
35				}
36
37				// handle data-back (so as not to conflict with the stock data-bg)
38				bg = e.target.dataset.back;
39				if (bg) {
40					if(ewww_webp_supported) {
41						console.log('checking for data-back-webp');
42						bgWebP = e.target.dataset.backWebp;
43						if (bgWebP) {
44							console.log('replacing data-back with data-back-webp');
45							bg = bgWebP;
46						}
47					}
48					bg = constrainBg(bg,e.target);
49					if ( e.target.style.backgroundImage && -1 === e.target.style.backgroundImage.search(/^initial/) ) {
50						// Convert JSON for multiple URLs.
51						if ( 0 === bg.search(/\[/) ) {
52							console.log('multiple URLs to append');
53							bg = JSON.parse(bg);
54							bg.forEach(
55								function(bg_url){
56									bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
57								}
58							);
59							bg = 'url("' + bg.join('"), url("') + '"';
60							var new_bg = e.target.style.backgroundImage + ', ' + bg;
61							console.log('setting .backgroundImage: ' + new_bg );
62							e.target.style.backgroundImage = new_bg;
63						} else {
64							console.log( 'appending bg url: ' + e.target.style.backgroundImage + ', url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')' );
65							e.target.style.backgroundImage = e.target.style.backgroundImage + ', url("' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + '")';
66						}
67					} else {
68						// Convert JSON for multiple URLs.
69						if ( 0 === bg.search(/\[/) ) {
70							console.log('multiple URLs to insert');
71							bg = JSON.parse(bg);
72							bg.forEach(
73								function(bg_url){
74									bg_url = (regBgUrlEscape.test(bg_url) ? JSON.stringify(bg_url) : bg_url );
75								}
76							);
77							bg = 'url("' + bg.join('"), url("') + '"';
78							console.log('setting .backgroundImage: ' + bg );
79							e.target.style.backgroundImage = bg;
80						} else {
81							console.log('setting .backgroundImage: ' + 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')');
82							e.target.style.backgroundImage = 'url(' + (regBgUrlEscape.test(bg) ? JSON.stringify(bg) : bg ) + ')';
83						}
84					}
85				}
86				// Handle CSS images from SWIS.
87				swisLazyId = e.target.dataset.swisLazyId;
88				if (swisLazyId && swisLazyId in swis_lazy_css_images) {
89					console.log('fetching CSS images for swisLazyId ' + swisLazyId);
90					var css_images = swis_lazy_css_images[swisLazyId];
91					var swisStyle  = document.querySelector('style#swis-lazy-css-styles');
92					css_images.forEach(
93						function(css_image){
94							if (!css_image.url) {
95								return;
96							}
97							if(ewww_webp_supported && css_image.webp_url) {
98								console.log('webp supported, using webp url for css image');
99								css_image.url = css_image.webp_url;
100							}
101							css_image.url = constrainBg(css_image.url,e.target);
102							console.log('processing CSS image: ' + css_image.url + ' with hash ' + css_image.hash);
103							var cssRule = css_image.selector + ' {--swis-bg-' + css_image.hash + ': url(' + css_image.url + '); }';
104							swisStyle.sheet.insertRule(cssRule);
105						}
106					);
107				}
108			}
109		}, false);
110	}
111
112	var constrainBg = function(bg,target){
113		if ( 0 === bg.search(/\[/) ) {
114			console.log('multiple URLs, not autoscaling background image');
115			return bg;
116		}
117		if (!shouldAutoScale(target)){
118			console.log('not autoscaling background image');
119			return bg;
120		}
121		var dPR = getdPR();
122		if ( dPR < eio_lazy_vars.bg_min_dpr ) {
123			dPR = eio_lazy_vars.bg_min_dpr;
124		}
125		var targetWidth  = Math.round(target.offsetWidth * dPR);
126		var targetHeight = Math.round(target.offsetHeight * dPR);
127		var bgType       = 'bg';
128		if (lazySizes.hC(target,'wp-block-cover')||lazySizes.hC(target,'wp-block-cover__image-background')){
129			console.log('found wp-block-cover with data-back');
130			if (lazySizes.hC(target,'has-parallax')) {
131				console.log('also has-parallax with data-back');
132				targetWidth  = Math.round(window.screen.width * dPR);
133				targetHeight = Math.round(window.screen.height * dPR);
134			} else if (targetHeight<300) {
135				targetHeight = 430;
136			}
137			bgType = 'bg-cover';
138		} else if (lazySizes.hC(target,'cover-image')){
139			console.log('found .cover-image with data-back');
140			bgType = 'bg-cover';
141		} else if (lazySizes.hC(target,'elementor-bg')){
142			console.log('found elementor-bg with data-back');
143			bgType = 'bg-cover';
144		} else if (lazySizes.hC(target,'et_parallax_bg')){
145			console.log('found et_parallax_bg with data-back');
146			bgType = 'bg-cover';
147		} else if (lazySizes.hC(target,'bg-image-crop')){
148			bgType = 'bg-cover';
149			console.log('found bg-image-crop with data-back');
150		} else {
151			console.log('found other data-back');
152		}
153		var imgAspect = getAspectRatio(target);
154		if ('bg' == bgType && targetHeight > 1 && targetWidth > 1 && imgAspect > 0) {
155			var minimum_width  = Math.ceil(targetHeight * imgAspect);
156			var minimum_height = Math.ceil(targetWidth / imgAspect);
157			console.log('minimum_width = ' + minimum_width + ', targetWidth = ' + targetWidth);
158			console.log('minimum_height = ' + minimum_height + ', targetHeight = ' + targetHeight);
159			if (targetWidth+2 < minimum_width) {
160				targetWidth = minimum_width;
161			}
162			if (targetHeight+2 < minimum_height) {
163				targetHeight = minimum_height;
164			}
165			var realDims = getRealDimensionsFromImg(target);
166			if (Math.abs(realDims.w - targetWidth) < 5 || Math.abs(realDims.h - targetHeight) < 5) {
167				console.log('real dimensions within 5px of target sizes, no scaling');
168				return bg;
169			}
170		}
171		bg = constrainSrc(bg,targetWidth,targetHeight,bgType);
172		return bg;
173	};
174
175	var shouldAutoScale = function(target){
176		if (eio_lazy_vars.skip_autoscale == 1) {
177			console.log('autoscale disabled globally');
178			return false;
179		}
180		var currentNode = target;
181		for (var i = 0; i <= 7; i++) {
182			if (currentNode.hasAttributes()) {
183				var attrs = currentNode.attributes
184				var regNoScale = /skip-autoscale/;
185				for (var i = attrs.length - 1; i >= 0; i--) {
186					if (regNoScale.test(attrs[i].name)) {
187						console.log('autoscale disabled by attr');
188						return false;
189					}
190					if (regNoScale.test(attrs[i].value)) {
191						console.log('autoscale disabled by attr value');
192						return false;
193					}
194				}
195			}
196			if (currentNode.parentNode && currentNode.parentNode.nodeType === 1 && currentNode.parentNode.hasAttributes) {
197				currentNode = currentNode.parentNode;
198			} else {
199				break;
200			}
201		}
202		return true;
203	};
204
205	var constrainSrc = function(url,objectWidth,objectHeight,objectType,upScale = false){
206		if (url===null){
207			return url;
208		}
209		console.log('constrain ' + url + ' to ' + objectWidth + 'x' + objectHeight + ' with type ' + objectType);
210		var regW      = /w=(\d+)/;
211		var regFit    = /fit=(\d+),(\d+)/;
212		var regResize = /resize=(\d+),(\d+)/;
213		var regSVG    = /\.svg(\?.+)?$/;
214		var decUrl = decodeURIComponent(url);
215		if (regSVG.exec(decUrl)){
216			return url;
217		}
218		console.log('domain to test: ' + eio_lazy_vars.exactdn_domain);
219		if (url.search('\\?') > 0 && url.search(eio_lazy_vars.exactdn_domain) > 0){
220			console.log('domain matches URL with a ?');
221			var resultResize = regResize.exec(decUrl);
222			if(resultResize && (objectWidth < resultResize[1] || upScale)){
223				if('img-w'===objectType){
224					console.log('resize param found, replacing in ' + objectType);
225					return decUrl.replace(regResize, 'w=' + objectWidth );
226				}
227				if('img-h'===objectType){
228					console.log('resize param found, replacing in ' + objectType);
229					return decUrl.replace(regResize, 'h=' + objectHeight );
230				}
231				console.log('resize param found, replacing');
232				return decUrl.replace(regResize, 'resize=' + objectWidth + ',' + objectHeight);
233			}
234			var resultW = regW.exec(url);
235			if(resultW && (objectWidth <= resultW[1] || upScale)){
236				if('img-h'===objectType){
237					console.log('w param found, replacing in ' + objectType);
238					return decUrl.replace(regW, 'h=' + objectHeight );
239				}
240				if('bg-cover'===objectType || 'img-crop'===objectType){
241					var diff = Math.abs(resultW[1] - objectWidth);
242					if ( diff > 20 || objectHeight < 1080 ) {
243						console.log('w param found, replacing in ' + objectType);
244						return url.replace(regW, 'resize=' + objectWidth + ',' + objectHeight );
245					}
246					console.log('w param found, but only ' + diff + ' pixels off, ignoring');
247					return url;
248				}
249				console.log('w param found, replacing');
250				return url.replace(regW, 'w=' + objectWidth);
251			}
252			var resultFit = regFit.exec(decUrl);
253			if(resultFit && (objectWidth < resultFit[1] || upScale)){
254				if('bg-cover'===objectType || 'img-crop'===objectType){
255					var wDiff = Math.abs(resultFit[1] - objectWidth);
256					var hDiff = Math.abs(resultFit[2] - objectHeight);
257					if ( wDiff > 20 || hDiff > 20 ) {
258						console.log('fit param found, replacing in ' + objectType);
259						return url.replace(regW, 'resize=' + objectWidth + ',' + objectHeight );
260					}
261					console.log('fit param found, but only w' + wDiff + '/h' + hDiff + ' pixels off, ignoring');
262					return url;
263				}
264				if('img-w'===objectType){
265					console.log('fit param found, replacing in ' + objectType);
266					return decUrl.replace(regFit, 'w=' + objectWidth );
267				}
268				if('img-h'===objectType){
269					console.log('fit param found, replacing in ' + objectType);
270					return decUrl.replace(regFit, 'h=' + objectHeight );
271				}
272				console.log('fit param found, replacing');
273				return decUrl.replace(regFit, 'fit=' + objectWidth + ',' + objectHeight);
274			}
275	        if(!resultW && !resultFit && !resultResize){
276				console.log('no param found, appending');
277				if('img'===objectType){
278					console.log('for ' + objectType);
279					return url + '&fit=' + objectWidth + ',' + objectHeight;
280				}
281				if('bg-cover'===objectType || 'img-crop'===objectType){
282					console.log('for ' + objectType);
283					return url + '&resize=' + objectWidth + ',' + objectHeight;
284				}
285				if('img-h'===objectType || objectHeight>objectWidth){
286					console.log('img-h or fallback height>width, using h param');
287					return url + '&h=' + objectHeight;
288				}
289				console.log('fallback using w param');
290				return url + '&w=' + objectWidth;
291			}
292		}
293		if (url.search('\\?') == -1 && url.search(eio_lazy_vars.exactdn_domain) > 0){
294			console.log('domain matches URL without a ?, appending query string');
295			if('img'===objectType){
296				console.log('for ' + objectType);
297				return url + '?fit=' + objectWidth + ',' + objectHeight;
298			}
299			if('bg-cover'===objectType || 'img-crop'===objectType){
300				console.log('for ' + objectType);
301				return url + '?resize=' + objectWidth + ',' + objectHeight;
302			}
303			if('img-h'===objectType || objectHeight>objectWidth){
304				console.log('img-h or fallback height>width, using h param');
305				return url + '?h=' + objectHeight;
306			}
307			console.log('fallback using w param');
308			return url + '?w=' + objectWidth;
309		}
310		console.log('boo, just using same url');
311		return url;
312	};
313
314	var getImgType = function(elem){
315		if ( lazySizes.hC(elem,'et_pb_jt_filterable_grid_item_image') || lazySizes.hC(elem,'ss-foreground-image') || lazySizes.hC(elem,'img-crop') ) {
316			console.log('img that needs a hard crop');
317			return 'img-crop';
318		} else if (
319			lazySizes.hC(elem,'object-cover') &&
320			( lazySizes.hC(elem,'object-top') || lazySizes.hC(elem,'object-bottom') )
321		) {
322			console.log('cover img that needs a width scale');
323			return 'img-w';
324		} else if (
325			lazySizes.hC(elem,'object-cover') &&
326			( lazySizes.hC(elem,'object-left') || lazySizes.hC(elem,'object-right') )
327		) {
328			console.log('cover img that needs a height scale');
329			return 'img-h';
330		} else if ( lazySizes.hC(elem,'ct-image') && lazySizes.hC(elem,'object-cover') ) {
331			console.log('Oxygen cover img that needs a hard crop');
332			return 'img-crop';
333		} else if ( ! elem.getAttribute('data-srcset') && ! elem.srcset && elem.offsetHeight > elem.offsetWidth && getAspectRatio(elem) > 1 ) {
334			console.log('non-srcset img with portrait display, landscape in real life');
335			return 'img-crop';
336		}
337		console.log('plain old img, constraining');
338		return 'img';
339	};
340
341	var getDimensionsFromURL = function(url){
342		var regDims = /-(\d+)x(\d+)\./;
343		var resultDims = regDims.exec(url);
344		if (resultDims && resultDims[1] > 1 && resultDims[2] > 1) {
345			return {w:resultDims[1],h:resultDims[2]};
346		}
347		return {w:0,h:0};
348	};
349
350	var getRealDimensionsFromImg = function(img){
351		var realWidth = img.dataset.eioRwidth;
352		var realHeight = img.dataset.eioRheight;
353		if (realWidth > 1 && realHeight > 1) {
354			return {w:realWidth,h:realHeight};
355		}
356		return {w:0,h:0};
357	};
358
359	var getSrcsetDims = function(img) {
360		var srcSet;
361		if (img.srcset){
362			srcSet = img.srcset.split(',');
363		} else {
364			var srcSetAttr = img.getAttribute('data-srcset');
365			if (srcSetAttr){
366				srcSet = srcSetAttr.split(','); 
367			}
368		}
369		if (srcSet){
370			var i = 0;
371			var len = srcSet.length;
372			if (len){
373				for (; i < len; i++){
374					var src = srcSet[i].trim().split(' ');
375					if (src[0].length) {
376						var nextDims = getDimensionsFromURL(src[0]);
377						if (nextDims.w && nextDims.h){
378							var srcSetDims = nextDims;
379						}
380					}
381				}
382				if (srcSetDims.w && srcSetDims.h){
383					return srcSetDims;
384				}
385			}
386		}
387		return {w:0,h:0};
388	}
389
390	var getAspectRatio = function(img){
391		var width = img.getAttribute('width');
392		var height = img.getAttribute('height');
393		if (width > 1 && height > 1){
394			console.log('found dims ' + width + 'x' + height + ', returning ' + width/height);
395			return width / height;
396		}
397		var src = false;
398		if (img.src && img.src.search('http') > -1) {
399			src = img.src;
400		}
401		if (!src) {
402			src = img.getAttribute('data-src');
403		}
404		if (src){
405			var urlDims = getDimensionsFromURL(src);
406			if (urlDims.w && urlDims.h) {
407				console.log('found dims from URL: ' + urlDims.w + 'x' + urlDims.h);
408				return urlDims.w / urlDims.h;
409			}
410		}
411		var realDims = getRealDimensionsFromImg(img);
412		if (realDims.w && realDims.h){
413			console.log('found dims from eio-attrs: ' + realDims.w + 'x' + realDims.h);
414			return realDims.w / realDims.h;
415		}
416		var srcSetDims = getSrcsetDims(img);
417		if (srcSetDims.w && srcSetDims.h){
418			console.log('largest found dims from srcset: ' + srcSetDims.w + 'x' + srcSetDims.h);
419			return srcSetDims.w / srcSetDims.h;
420		}
421		return 0;
422	}
423
424	var updateImgElem = function(target,upScale=false){
425		var dPR = getdPR();
426		var targetWidth = Math.round(target.offsetWidth * dPR);
427		var targetHeight = Math.round(target.offsetHeight * dPR);
428
429		var src = target.getAttribute('data-src');
430		var webpsrc = target.getAttribute('data-src-webp');
431		if(ewww_webp_supported && webpsrc && -1 == src.search('webp=1') && !upScale){
432			console.log('using data-src-webp');
433			src = webpsrc;
434		}
435		if (!shouldAutoScale(target)){
436			return;
437		}
438		var imgType = getImgType(target);
439		var newSrc  = constrainSrc(src,targetWidth,targetHeight,imgType,upScale);
440		if (newSrc && src != newSrc){
441			console.log('new src: ' + newSrc);
442			if (upScale){
443				target.setAttribute('src', newSrc);
444			}
445			target.setAttribute('data-src', newSrc);
446		}
447	};
448
449	var getdPR = function() {
450		if (eio_lazy_vars.use_dpr && window.devicePixelRatio > 1) {
451			return window.devicePixelRatio;
452		}
453		return 1;
454	}
455
456	document.addEventListener('lazybeforesizes', function(e){
457		var src = e.target.getAttribute('data-src');
458		var maxWidth = e.target.dataset.maxWidth > 10 ? e.target.dataset.maxWidth : 9999;
459		console.log('auto-sizing ' + src + ' to ' + e.detail.width + ' but no more than ' + maxWidth);
460		if (e.detail.width > maxWidth) {
461			e.detail.width = maxWidth;
462		}
463		var imgAspect = getAspectRatio(e.target);
464		if (e.target.clientHeight > 1 && imgAspect) {
465			var minimum_width = Math.min(Math.ceil(imgAspect * e.target.clientHeight), maxWidth);
466			console.log('minimum_width = ' + minimum_width);
467			if (e.detail.width+2 < minimum_width) {
468				e.detail.width = minimum_width;
469			}
470		}
471		// If this is the first time around for this image...
472		if (e.target._lazysizesWidth === undefined) {
473			/*if (!eio_lazy_vars.use_dpr && window.devicePixelRatio > 1) {
474				console.log('use_dpr is disabled, reversing auto-sizes by dpr ' + window.devicePixelRatio);
475				e.detail.width = Math.ceil(e.detail.width / window.devicePixelRatio);
476			}*/
477			return;
478		}
479		console.log('previous width was ' + e.target._lazysizesWidth);
480		/*if (!eio_lazy_vars.use_dpr && window.devicePixelRatio > 1) {
481			console.log('use_dpr is disabled, reversing auto-sizes by dpr ' + window.devicePixelRatio);
482			e.detail.width = Math.ceil(e.detail.width / window.devicePixelRatio);
483		}*/
484		// Don't make sizes smaller than it already is, this can get into a loop of shrinking an image.
485		// At this point, an image has already been loaded, so changing things isn't beneficial.
486		if (e.detail.width < e.target._lazysizesWidth) {
487			console.log('no way! ' + e.detail.width + ' is smaller than ' + e.target._lazysizesWidth);
488			e.detail.width = e.target._lazysizesWidth;
489		}
490	});
491
492	document.addEventListener('lazybeforeunveil', function(e){
493		var target = e.target;
494		console.log('loading an image');
495		console.log(target);
496		var srcset  = target.getAttribute('data-srcset');
497		if (target.naturalWidth && ! srcset) {
498			console.log('natural width of ' + target.getAttribute('src') + ' is ' + target.naturalWidth);
499			console.log('we have an image with no srcset');
500			if ((target.naturalWidth > 1) && (target.naturalHeight > 1)) {
501				// For each image with a natural width which isn't
502				// a 1x1 image, check its size.
503				var dPR = getdPR();
504				var physicalWidth = target.naturalWidth;
505				var physicalHeight = target.naturalHeight;
506				var realDims = getRealDimensionsFromImg(target);
507				if (realDims.w && realDims.w > physicalWidth) {
508					console.log( 'using ' + realDims.w + 'w instead of ' + physicalWidth + 'w and ' + realDims.h + 'h instead of ' + physicalHeight + 'h from data-eio-r*')
509					physicalWidth = realDims.w;
510					physicalHeight = realDims.h;
511				}
512				var wrongWidth = (target.clientWidth && ((target.clientWidth * 1.25 * dPR < physicalWidth) || (target.clientWidth * dPR + 50 < physicalWidth))
512);
513				var wrongHeight = (target.clientHeight && ((target.clientHeight * 1.25 * dPR < physicalHeight) || (target.clientHeight * dPR + 50 < physicalHeight)));
514				console.log('displayed at ' + Math.round(target.clientWidth * dPR) + 'w x ' + Math.round(target.clientHeight * dPR) + 'h, natural/physical is ' +
515				physicalWidth + 'w x ' + physicalHeight + 'h!');
516				console.log('the data-src: ' + target.getAttribute('data-src') );
517				if (wrongWidth || wrongHeight) {
518					updateImgElem(target);
519				}
520			}
521		}
522		if(ewww_webp_supported) {
523			console.log('webp supported');
524			//console.log(srcset);
525			if (srcset) {
526				console.log('srcset available');
527				var webpsrcset = target.getAttribute('data-srcset-webp');
528				if(webpsrcset){
529					console.log('replacing data-srcset with data-srcset-webp');
530					target.setAttribute('data-srcset', webpsrcset);
531				}
532			}
533			var webpsrc = target.getAttribute('data-src-webp');
534			if(!webpsrc){
535				console.log('no data-src-webp attr');
536				return;
537			}
538			console.log('replacing data-src with data-src-webp');
539			target.setAttribute('data-src', webpsrc);
540		}
541	});
542
543	// Based on http://modernjavascript.blogspot.de/2013/08/building-better-debounce.html
544	var debounce = function(func) {
545		var timeout, timestamp;
546		var wait = 99;
547		var run = function(){
548			timeout = null;
549			func();
550		};
551		var later = function() {
552			var last = Date.now() - timestamp;
553
554			if (last < wait) {
555				setTimeout(later, wait - last);
556			} else {
557				(window.requestIdleCallback || run)(run);
558			}
559		};
560
561		return function() {
562			timestamp = Date.now();
563
564			if (!timeout) {
565				timeout = setTimeout(later, wait);
566			}
567		};
568	};
569
570	var recheckLazyElements = function(event = false) {
571		console.log('rechecking elements:');
572		if (event.type) {
573			console.log(event.type);
574			if ('load'===event.type) {
575				lazySizes.autoSizer.checkElems();
576			}
577		}
578		var dPR = getdPR();
579		var autosizedElems = document.getElementsByClassName(lazySizes.cfg.loadedClass);
580		var i;
581		var len = autosizedElems.length;
582		if(len){
583			i = 0;
584
585			for(; i < len; i++){
586				var autosizedElem = autosizedElems[i];
587				if (autosizedElem.src && ! autosizedElem.srcset && autosizedElem.naturalWidth > 1 && autosizedElem.naturalHeight > 1 && autosizedElem.clientWidth > 1 && autosizedElem.clientHeight > 1){
588					console.log(autosizedElem);
589					console.log('natural width of ' + autosizedElem.src + ' is ' + autosizedElem.naturalWidth);
590					// For each image with a natural width which isn't
591					// a 1x1 image, check its size.
592					var physicalWidth  = autosizedElem.naturalWidth;
593					var physicalHeight = autosizedElem.naturalHeight;
594					var maxWidth  = window.innerWidth;
595					var maxHeight = window.innerHeight;
596					var realDims  = getRealDimensionsFromImg(autosizedElem);
597					var urlDims   = getDimensionsFromURL(autosizedElem.src);
598	
599					if (realDims.w) {
600						maxWidth = realDims.w;
601					} else if (urlDims.w) {
602						maxWidth = urlDims.w;
603					}
604					if (realDims.h) {
605						maxHeight = realDims.h;
606					} else if (urlDims.h) {
607						maxHeight = urlDims.h;
608					}
609					console.log( 'max image size is ' + maxWidth + 'w, ' + maxHeight + 'h');
610
611					// For upscaling, the goal is to get to 1x dPR, we won't waste bandwidth on retina/2x images.
612					var desiredWidth  = autosizedElem.clientWidth;
613					var desiredHeight = autosizedElem.clientHeight;
614					var wrongWidth  = (desiredWidth > physicalWidth * 1.1 && maxWidth >= desiredWidth);
615					var wrongHeight = (desiredHeight > physicalHeight * 1.1 && maxHeight >= desiredHeight);
616					console.log('displayed at ' + Math.round(desiredWidth) + 'w x ' + Math.round(desiredHeight) + 'h, natural/physical is ' +
617					physicalWidth + 'w x ' + physicalHeight + 'h');
618					if (wrongWidth || wrongHeight) {
619						console.log('requesting upsize');
620						updateImgElem(autosizedElem,true);
621					}
622				}
623			}
624		}
625	};
626
627	var debouncedRecheckElements = debounce(recheckLazyElements);
628	
629	addEventListener('load', recheckLazyElements);
630	addEventListener('resize', debouncedRecheckElements);
631	setTimeout(recheckLazyElements, 20000);
632}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.