PageSourceSearch

https://voceatimisului.ro/wp-content/plugins/foobox-image-lightbox-premium/assets/js/foobox.auto-link.js

js voceatimisului.ro collected 2026-10-02 13:16:53 UTC 4,631 bytes, 181 lines download raw bytes

1(function (window, document) {
2	'use strict';
3
4	window.FOOBOX_AUTO_LINK_IMAGES = function ($) {
5		if (!$ && window.jQuery) {
6			$ = window.jQuery;
7		}
8		if (!$) {
9			return;
10		}
11
12		var imageSelector = 'img[class*=wp-image-]';
13		var excludedSelector = '.nofoobox, .nolightbox';
14		var imageExtensionRegex = /\.(?:jpe?g|png|gif|webp|bmp|svg)$/i;
15		var thumbnailSizeRegex = /-\d+x\d+(?=\.(?:jpe?g|png|gif|webp|bmp|svg)$)/i;
16
17		function splitUrl(url) {
18			var parts = { base: url, query: '', hash: '' };
19			var hashIndex = parts.base.indexOf('#');
20			if (hashIndex !== -1) {
21				parts.hash = parts.base.substring(hashIndex);
22				parts.base = parts.base.substring(0, hashIndex);
23			}
24			var queryIndex = parts.base.indexOf('?');
25			if (queryIndex !== -1) {
26				parts.query = parts.base.substring(queryIndex);
27				parts.base = parts.base.substring(0, queryIndex);
28			}
29			return parts;
30		}
31
32		function isUsableImageUrl(url) {
33			if (typeof url !== 'string' || url.length === 0) {
34				return false;
35			}
36			url = url.replace(/^\s+|\s+$/g, '');
37			if (url.indexOf('data:') === 0 || url.indexOf('blob:') === 0) {
38				return false;
39			}
40			return imageExtensionRegex.test(splitUrl(url).base);
41		}
42
43		function absoluteUrl(url) {
44			var anchor = document.createElement('a');
45			anchor.href = url;
46			return anchor.href;
47		}
48
49		function comparableUrl(url) {
50			var anchor = document.createElement('a');
51			anchor.href = url;
52			return anchor.protocol + '//' + anchor.host + anchor.pathname;
53		}
54
55		function sameUrl(urlA, urlB) {
56			return comparableUrl(urlA) === comparableUrl(urlB);
57		}
58
59		function getFirstUsableAttribute($img, attributes) {
60			var value, i;
61			for (i = 0; i < attributes.length; i++) {
62				value = $img.attr(attributes[i]);
63				if (isUsableImageUrl(value)) {
64					return absoluteUrl(value);
65				}
66			}
67			return '';
68		}
69
70		function getSourceUrl($img) {
71			var img = $img.get(0);
72			var candidates = [
73				$img.attr('src'),
74				$img.attr('data-src'),
75				$img.attr('data-lazy-src'),
76				$img.attr('data-original'),
77				img ? img.currentSrc : ''
78			];
79			var i;
80			for (i = 0; i < candidates.length; i++) {
81				if (isUsableImageUrl(candidates[i])) {
82					return absoluteUrl(candidates[i]);
83				}
84			}
85			return '';
86		}
87
88		function getLargestSrcsetUrl(srcset) {
89			if (typeof srcset !== 'string' || srcset.length === 0) {
90				return '';
91			}
92			var candidates = srcset.split(',');
93			var bestUrl = '';
94			var bestWidth = 0;
95			var i, candidate, parts, url, descriptor, width;
96			for (i = 0; i < candidates.length; i++) {
97				candidate = candidates[i].replace(/^\s+|\s+$/g, '');
98				parts = candidate.split(/\s+/);
99				url = parts[0];
100				descriptor = parts.length > 1 ? parts[1] : '';
101				width = /w$/.test(descriptor) ? parseInt(descriptor, 10) : 0;
102				if (width > bestWidth && isUsableImageUrl(url)) {
103					bestUrl = absoluteUrl(url);
104					bestWidth = width;
105				}
106			}
107			return bestUrl;
108		}
109
110		function inferFullSizeUrl(url) {
111			if (!isUsableImageUrl(url)) {
112				return '';
113			}
114			var parts = splitUrl(url);
115			var inferred = parts.base.replace(thumbnailSizeRegex, '');
116			if (inferred === parts.base) {
117				return '';
118			}
119			return absoluteUrl(inferred + parts.query + parts.hash);
120		}
121
122		function getFullSizeUrl($img) {
123			var sourceUrl = getSourceUrl($img);
124			var explicitUrl = getFirstUsableAttribute($img, [
125				'data-full-url',
126				'data-full',
127				'data-orig-file',
128				'data-large-file'
129			]);
130			var srcsetUrl = getLargestSrcsetUrl($img.attr('srcset') || $img.attr('data-srcset'));
131			var inferredUrl = inferFullSizeUrl(sourceUrl);
132
133			if (explicitUrl && (!sourceUrl || !sameUrl(explicitUrl, sourceUrl))) {
134				return explicitUrl;
135			}
136			if (srcsetUrl && (!sourceUrl || !sameUrl(srcsetUrl, sourceUrl))) {
137				return srcsetUrl;
138			}
139			if (inferredUrl && (!sourceUrl || !sameUrl(inferredUrl, sourceUrl))) {
140				return inferredUrl;
141			}
142
143			return '';
144		}
145
146		$(imageSelector).each(function () {
147			var $img = $(this);
148			var $target;
149			var href;
150			var title;
151
152			if ($img.hasClass('size-full') || $img.closest('a, button, .fbx-link').length) {
153				return;
154			}
155			if ($img.is(excludedSelector) || $img.closest(excludedSelector).length) {
156				return;
157			}
158
159			href = getFullSizeUrl($img);
160			if (!href) {
161				return;
162			}
163
164			$target = $img.parent('picture');
165			if (!$target.length) {
166				$target = $img;
167			}
168			if ($target.parent('a, button').length) {
169				return;
170			}
171
172			title = $img.attr('title') || $img.attr('alt') || '';
173			$target.wrap($('<a/>', {
174				'class': 'foobox foobox-auto-link',
175				'href': href,
176				'title': title,
177				'data-foobox-auto-link': '1'
178			}));
179		});
180	};
181})(window, document);

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.