PageSourceSearch

https://www.alpagocansiglio.eu/wp-content/themes/uncode/library/js/ai-uncode.js?ver=792896646

js alpagocansiglio.eu collected 2026-10-06 20:29:33 UTC 5,820 bytes, 161 lines download raw bytes

1(function(w) {
2	"use strict";
3	var uncode = 'uncodeAI',
4		path = ';path=',
5		doc = document,
6		winWidth = w.innerWidth,
7		screenWidth = screen.width,
8		screenHeight = screen.height,
9		cookies = {},
10		cssBreakpoint,
11		cookieRecorded = false,
12		looped = false,
13		cookiesEnable = navigator.cookieEnabled;
14
15	/**
16	 * Extract the uncode cookie values
17	 *
18	 * @return {Object}				uncode cookie values
19	 */
20	var getuncodeCookies = function() {
21		for (var index = 0, cookieParts = doc.cookie.split(';'), cookiePattern = /^\suncodeAI\.([^=]+)=(.*?)\s*$/, cookies = {}, cookie; index < cookieParts.length; ++index) {
22			if (cookie = cookieParts[index].match(cookiePattern)) {
23				cookies[cookie[1]] = cookie[2];
24			}
25		}
26		return cookies;
27	}
28	/**
29	 * Measure the window width in em
30	 *
31	 * @return {Number}				Window width in em
32	 */
33	var measureWindowEmWidth = function(precision, f) {
34		precision = Math.max(parseFloat(precision || 1, 10), .01);
35		var docElement = doc.documentElement,
36			createBlock = function() {
37				var block = doc.createElement('div'),
38					blockStyles = {
39						'width': '1px',
40						'height': '1px',
41						'display': 'inline-block'
42					};
43				for (var property in blockStyles) {
44					block.style[property] = blockStyles[property];
45				}
46				return block;
47			},
48			blockRow = doc.createElement('div'),
49			block = blockRow.appendChild(createBlock());
50		blockRow.appendChild(createBlock());
51		docElement.appendChild(blockRow);
52		var blockHeight = blockRow.clientHeight,
53			ems = Math.floor(winWidth / blockHeight),
54			delta = ems / 2,
55			iteration = 0,
56			iterations = [ems];
57		// Iteratetively resize the measurement block until the breakpoint is found (taking the given precision into account)
58		while ((iteration++ < 1000) && ((Math.abs(delta) > precision) || (blockRow.clientHeight > blockHeight))) {
59			ems += delta;
60			block.style.width = ems + 'em';
61			delta /= ((blockRow.clientHeight > blockHeight) ? 1 : -1) * ((delta > 0) ? -2 : 2);
62			iterations.push(ems);
63		}
64		// Remove the measurement elements
65		docElement.removeChild(blockRow);
66		return ems;
67	}
68	/**
69	 * Extract the image breakpoints
70	 *
71	 * @param {String} str		Serialized breakpoints list
72	 * @return {Array}			Ordered breakpoints list
73	 */
74	var getBreakpoints = function(str, emf) {
75		// Split the breakpoint list and run through all breakpoints
76		for (var index = 0, rawBreakpoints = (str || '').split(','), breakpointPattern = /(\d+(?:\.\d+)?)(px)?/i, breakpoints = [], match; index < rawBreakpoints.length; ++index) {
77			// If this is a valid breakpoint definition (may have a "px" unit)
78			if (match = rawBreakpoints[index].match(breakpointPattern)) {
79				breakpoints.push(parseFloat(match[1], 10));
80			}
81		}
82		// Sort the breakpoints in ascending order
83		return breakpoints.sort(function(a, b) {
84			return a - b;
85		});
86	}
87	/**
88	 * Return the device pixel ratio
89	 *
90	 * @return {Number}			Device pixel ratio
91	 */
92	var getDevicePixelRatio = function() {
93		var ratio = ('devicePixelRatio' in w) ? w.devicePixelRatio : ((('deviceXDPI' in w) && ('logicalXDPI' in w)) ? (w.deviceXDPI / w.logicalXDPI) : 1);
94		return ratio;
95	}
96	/**
97	 * Round a floating point value to a certain precision
98	 *
99	 * @param {Number}			Floating point value
100	 * @param {Number}			Precision
101	 * @param {Number}			Rounded floating point value
102	 */
103	var roundToPrecision = function(em, precision) {
104		return precision * Math.round(10 * em / precision) / 10;
105	}
106	if (cookiesEnable) cookies = getuncodeCookies();
107	if (cookies.images !== undefined) cookieRecorded = true;
108	// Run through all document JavaScripts and find the uncode script (must reference a script file with ID attribute = "uncodeAI")
109	for (var index = 0, scripts = doc.getElementsByTagName('script'); index < scripts.length; ++index) {
110		if (scripts[index].id == uncode) {
111			var pixelRatio = getDevicePixelRatio();
112			var imgBreakpoint = '2880';
113			var limitDensity = scripts[index].getAttribute('data-limit-density');
114			var secureFlag = location.protocol === 'https:' ? ';secure' : '';
115
116			pixelRatio = limitDensity && pixelRatio > 2 ? 2 : pixelRatio;
117
118			path = path + scripts[index].getAttribute('data-home');
119			if (scripts[index].getAttribute('data-async') == 'true') cookiesEnable = false;
120			// Set the general screen size cookie
121			if (cookiesEnable) doc.cookie = uncode + '.screen=' + screenWidth + path + secureFlag; // + 'x' + screenHeight + '@' + pixelRatio + path;
122			w.uncodeScreen = screenWidth;
123			// Set the image engine cookie (if enabled)
124			if (!scripts[index].getAttribute('data-disable-images')) {
125				var breakpoints = getBreakpoints(scripts[index].getAttribute('data-breakpoints-images'));
126				var useOrientationWidth = scripts[index].getAttribute('data-use-orientation-width');
127				var maximum = useOrientationWidth ? screenWidth : Math.max(screenWidth, screenHeight);
128				var nextBreakpoint = null;
129
130				maximum = pixelRatio > 1 ? (maximum * pixelRatio) : maximum;
131
132				do {
133					if (maximum > (nextBreakpoint = breakpoints.pop())) {
134						break;
135					}
136
137					imgBreakpoint = nextBreakpoint;
138				} while (breakpoints.length);
139			}
140
141			if (cookiesEnable) {
142				doc.cookie = uncode + '.images=' + imgBreakpoint + path + secureFlag;
143			}
144
145			w.uncodeImages = imgBreakpoint;
146
147			// Determine the uncode cookie values
148			if (cookiesEnable) {
149				cookies = getuncodeCookies();
150				cssBreakpoint = cookies.css || '-';
151				if ((!('css' in cookies) || !cookies.css || (cookies.css == '-')) && !scripts[index].getAttribute('data-disable-css')) {
152					var emRatio = winWidth / measureWindowEmWidth(parseFloat(scripts[index].getAttribute('data-em-precision') || .5, 10) / 100);
153					cssBreakpoint = screenWidth + 'x' + screenHeight + '@' + (Math.round(emRatio * 10) / 10);
154				}
155				doc.cookie = uncode + '.css=' + cssBreakpoint + path + secureFlag;
156			}
157			break;
158		}
159	}
160
161})(this);

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.