PageSourceSearch

https://www.arabbarometer.org/wp-content/themes/gridlove/assets/js/ofi.js?ver=2.3.1

js arabbarometer.org collected 2026-10-01 10:29:56 UTC 6,859 bytes, 231 lines download raw bytes

vendor: 4,390 bytes, lines 1-138
1/*! npm.im/object-fit-images 3.1.0 */
2var objectFitImages = (function () {
3'use strict';
4
5var OFI = 'bfred-it:object-fit-images';
6var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g;
7var testImg = new Image();
8var supportsObjectFit = 'object-fit' in testImg.style;
9var supportsObjectPosition = 'object-position' in testImg.style;
10var supportsOFI = 'background-size' in testImg.style;
11var supportsCurrentSrc = typeof testImg.currentSrc === 'string';
12var nativeGetAttribute = testImg.getAttribute;
13var nativeSetAttribute = testImg.setAttribute;
14var autoModeEnabled = false;
15
16function createPlaceholder(w, h) {
17	return ("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='" + w + "' height='" + h + "'%3E%3C/svg%3E");
18}
19
20function polyfillCurrentSrc(el) {
21	if (el.srcset && !supportsCurrentSrc && window.picturefill) {
22		var pf = window.picturefill._;
23		// parse srcset with picturefill where currentSrc isn't available
24		if (!el[pf.ns] || !el[pf.ns].evaled) {
25			// force synchronous srcset parsing
26			pf.fillImg(el, {reselect: true});
27		}
28
29		if (!el[pf.ns].curSrc) {
30			// force picturefill to parse srcset
31			el[pf.ns].supported = false;
32			pf.fillImg(el, {reselect: true});
33		}
34
35		// retrieve parsed currentSrc, if any
36		el.currentSrc = el[pf.ns].curSrc || el.src;
37	}
38}
39
40function getStyle(el) {
41	var style = getComputedStyle(el).fontFamily;
42	var parsed;
43	var props = {};
44	while ((parsed = propRegex.exec(style)) !== null) {
45		props[parsed[1]] = parsed[2];
46	}
47	return props;
48}
49
50function setPlaceholder(img, width, height) {
51	// Default: fill width, no height
52	var placeholder = createPlaceholder(width || 1, height || 0);
53
54	// Only set placeholder if it's different
55	if (nativeGetAttribute.call(img, 'src') !== placeholder) {
56		nativeSetAttribute.call(img, 'src', placeholder);
57	}
58}
59
60function onImageReady(img, callback) {
61	// naturalWidth is only available when the image headers are loaded,
62	// this loop will poll it every 100ms.
63	if (img.naturalWidth) {
64		callback(img);
65	} else {
66		setTimeout(onImageReady, 100, img, callback);
67	}
68}
69
70function fixOne(el) {
71	var style = getStyle(el);
72	var ofi = el[OFI];
73	style['object-fit'] = style['object-fit'] || 'fill'; // default value
74
75	// Avoid running where unnecessary, unless OFI had already done its deed
76	if (!ofi.img) {
77		// fill is the default behavior so no action is necessary
78		if (style['object-fit'] === 'fill') {
79			return;
80		}
81
82		// Where object-fit is supported and object-position isn't (Safari < 10)
83		if (
84			!ofi.skipTest && // unless user wants to apply regardless of browser support
85			supportsObjectFit && // if browser already supports object-fit
86			!style['object-position'] // unless object-position is used
87		) {
88			return;
89		}
90	}
91
92	// keep a clone in memory while resetting the original to a blank
93	if (!ofi.img) {
94		ofi.img = new Image(el.width, el.height);
95		ofi.img.srcset = nativeGetAttribute.call(el, "data-ofi-srcset") || el.srcset;
96		ofi.img.src = nativeGetAttribute.call(el, "data-ofi-src") || el.src;
97
98		// preserve for any future cloneNode calls
99		// https://github.com/bfred-it/object-fit-images/issues/53
100		nativeSetAttribute.call(el, "data-ofi-src", el.src);
101		if (el.srcset) {
102			nativeSetAttribute.call(el, "data-ofi-srcset", el.srcset);
103		}
104
105		setPlaceholder(el, el.naturalWidth || el.width, el.naturalHeight || el.height);
106
107		// remove srcset because it overrides src
108		if (el.srcset) {
109			el.srcset = '';
110		}
111		try {
112			keepSrcUsable(el);
113		} catch (err) {
114			if (window.console) {
115				console.log('http://bit.ly/ofi-old-browser');
116			}
117		}
118	}
119
120	polyfillCurrentSrc(ofi.img);
121
122	el.style.backgroundImage = "url(" + ((ofi.img.currentSrc || ofi.img.src).replace('(', '%28').replace(')', '%29')) + ")";
123	el.style.backgroundPosition = style['object-position'] || 'center';
124	el.style.backgroundRepeat = 'no-repeat';
125
126	if (/scale-down/.test(style['object-fit'])) {
127		onImageReady(ofi.img, function () {
128			if (ofi.img.naturalWidth > el.width || ofi.img.naturalHeight > el.height) {
129				el.style.backgroundSize = 'contain';
130			} else {
131				el.style.backgroundSize = 'auto';
132			}
133		});
134	} else {
135		el.style.backgroundSize = style['object-fit'].replace('none', 'auto').replace('fill', '100% 100%');
136	}
137
138	onImageReady(ofi.img, function (img) {
vendor: 1,495 bytes, lines 139-188
139		setPlaceholder(el, img.naturalWidth, img.naturalHeight);
140	});
141}
142
143function keepSrcUsable(el) {
144	var descriptors = {
145		get: function get(prop) {
146			return el[OFI].img[prop ? prop : 'src'];
147		},
148		set: function set(value, prop) {
149			el[OFI].img[prop ? prop : 'src'] = value;
150			nativeSetAttribute.call(el, ("data-ofi-" + prop), value); // preserve for any future cloneNode
151			fixOne(el);
152			return value;
153		}
154	};
155	Object.defineProperty(el, 'src', descriptors);
156	Object.defineProperty(el, 'currentSrc', {
157		get: function () { return descriptors.get('currentSrc'); }
158	});
159	Object.defineProperty(el, 'srcset', {
160		get: function () { return descriptors.get('srcset'); },
161		set: function (ss) { return descriptors.set(ss, 'srcset'); }
162	});
163}
164
165function hijackAttributes() {
166	function getOfiImageMaybe(el, name) {
167		return el[OFI] && el[OFI].img && (name === 'src' || name === 'srcset') ? el[OFI].img : el;
168	}
169	if (!supportsObjectPosition) {
170		HTMLImageElement.prototype.getAttribute = function (name) {
171			return nativeGetAttribute.call(getOfiImageMaybe(this, name), name);
172		};
173
174		HTMLImageElement.prototype.setAttribute = function (name, value) {
175			return nativeSetAttribute.call(getOfiImageMaybe(this, name), name, String(value));
176		};
177	}
178}
179
180function fix(imgs, opts) {
181	var startAutoMode = !autoModeEnabled && !imgs;
182	opts = opts || {};
183	imgs = imgs || 'img';
184
185	if ((supportsObjectPosition && !opts.skipTest) || !supportsOFI) {
186		return false;
187	}
188
vendor: 974 bytes, lines 189-231
189	// use imgs as a selector or just select all images
190	if (typeof imgs === 'string') {
191		imgs = document.querySelectorAll(imgs);
192	} else if (!('length' in imgs)) {
193		imgs = [imgs];
194	}
195
196	// apply fix to all
197	for (var i = 0; i < imgs.length; i++) {
198		imgs[i][OFI] = imgs[i][OFI] || {
199			skipTest: opts.skipTest
200		};
201		fixOne(imgs[i]);
202	}
203
204	if (startAutoMode) {
205		document.body.addEventListener('load', function (e) {
206			if (e.target.tagName === 'IMG') {
207				fix(e.target, {
208					skipTest: opts.skipTest
209				});
210			}
211		}, true);
212		autoModeEnabled = true;
213		imgs = 'img'; // reset to a generic selector for watchMQ
214	}
215
216	// if requested, watch media queries for object-fit change
217	if (opts.watchMQ) {
218		window.addEventListener('resize', fix.bind(null, imgs, {
219			skipTest: opts.skipTest
220		}));
221	}
222}
223
224fix.supportsObjectFit = supportsObjectFit;
225fix.supportsObjectPosition = supportsObjectPosition;
226
227hijackAttributes();
228
229return fix;
230
231}());

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.