PageSourceSearch

https://greenberetfoundation.org/wp-content/themes/greenberetfoundation/js/gbf-lightbox-fallback.js?ver=1.0.4

js greenberetfoundation.org collected 2026-10-02 02:40:31 UTC 4,745 bytes, 195 lines download raw bytes

1(function () {
2	'use strict';
3
4	function activeWebflowLightbox() {
5		return document.querySelector('.w-lightbox-backdrop:not(.w-lightbox-hide)');
6	}
7
8	function activeFallbackLightbox() {
9		return document.querySelector('.gbf-video-lightbox.is-open');
10	}
11
12	function getVideoItem(link) {
13		var jsonNode = link.querySelector('.w-json');
14		var config;
15
16		if (!jsonNode) {
17			return null;
18		}
19
20		try {
21			config = JSON.parse(jsonNode.textContent || jsonNode.innerText || '{}');
22		} catch (error) {
23			return null;
24		}
25
26		if (config && config.items && config.items.length) {
27			return config.items[0];
28		}
29
30		if (config && config.embed) {
31			return config.embed;
32		}
33
34		return null;
35	}
36
37	function youtubeEmbedFromUrl(url) {
38		var parsed;
39		var videoId = '';
40		var pathParts;
41
42		if (!url) {
43			return '';
44		}
45
46		if (/^[A-Za-z0-9_-]{11}$/.test(url)) {
47			return 'https://www.youtube.com/embed/' + encodeURIComponent(url) + '?autoplay=1&rel=0';
48		}
49
50		try {
51			parsed = new URL(url, window.location.href);
52		} catch (error) {
53			return '';
54		}
55
56		if (parsed.hostname.indexOf('youtu.be') !== -1) {
57			videoId = parsed.pathname.replace('/', '').split('/')[0];
58		} else {
59			pathParts = parsed.pathname.split('/').filter(Boolean);
60			videoId = parsed.searchParams.get('v') || '';
61
62			if (!videoId && (pathParts[0] === 'embed' || pathParts[0] === 'shorts')) {
63				videoId = pathParts[1] || '';
64			}
65		}
66
67		if (!videoId) {
68			return '';
69		}
70
71		return 'https://www.youtube.com/embed/' + encodeURIComponent(videoId) + '?autoplay=1&rel=0';
72	}
73
74	function scheduleFallback(link) {
75		window.setTimeout(function () {
76			openFallback(link);
77		}, 300);
78	}
79
80	function videoHtml(item) {
81		var wrapper = document.createElement('div');
82		var iframe = null;
83		var embedUrl = '';
84
85		if (item.html) {
86			wrapper.innerHTML = item.html;
87			iframe = wrapper.querySelector('iframe');
88		}
89
90		if (!iframe) {
91			embedUrl = youtubeEmbedFromUrl(item.originalUrl || item.url);
92			if (!embedUrl) {
93				return '';
94			}
95
96			iframe = document.createElement('iframe');
97			iframe.setAttribute('src', embedUrl);
98			iframe.setAttribute('frameborder', '0');
99			iframe.setAttribute('allow', 'autoplay; fullscreen');
100			iframe.setAttribute('allowfullscreen', 'true');
101		}
102
103		if (!iframe.getAttribute('allow')) {
104			iframe.setAttribute('allow', 'autoplay; fullscreen');
105		}
106
107		iframe.setAttribute('title', iframe.getAttribute('title') || 'Video player');
108		return iframe.outerHTML;
109	}
110
111	function closeFallback() {
112		var lightbox = activeFallbackLightbox();
113
114		if (!lightbox) {
115			return;
116		}
117
118		document.documentElement.classList.remove('gbf-video-lightbox-active');
119		lightbox.remove();
120	}
121
122	function openFallback(link) {
123		var item = getVideoItem(link);
124		var html = item ? videoHtml(item) : '';
125		var lightbox;
126		var dialog;
127		var closeButton;
128
129		if (!html || activeWebflowLightbox() || activeFallbackLightbox()) {
130			return;
131		}
132
133		lightbox = document.createElement('div');
134		lightbox.className = 'gbf-video-lightbox is-open';
135		lightbox.setAttribute('role', 'dialog');
136		lightbox.setAttribute('aria-modal', 'true');
137		lightbox.setAttribute('aria-label', 'Video');
138
139		dialog = document.createElement('div');
140		dialog.className = 'gbf-video-lightbox__dialog';
141		dialog.innerHTML = html;
142
143		closeButton = document.createElement('button');
144		closeButton.className = 'gbf-video-lightbox__close';
145		closeButton.type = 'button';
146		closeButton.setAttribute('aria-label', 'Close video');
147		closeButton.innerHTML = '×';
148
149		lightbox.appendChild(closeButton);
150		lightbox.appendChild(dialog);
151		document.body.appendChild(lightbox);
152		document.documentElement.classList.add('gbf-video-lightbox-active');
153		closeButton.focus();
154	}
155
156	function handlePlayActivation(event) {
157		var play = event.target.closest('.play');
158		var playContainer = event.target.closest('.playcontainer, .playcontainersub');
159		var link = play ? play.querySelector('a.w-lightbox') : null;
160
161		if (!link && playContainer) {
162			play = playContainer.querySelector('.play');
163			link = play ? play.querySelector('a.w-lightbox') : null;
164		}
165
166		if (!link) {
167			return;
168		}
169
170		if (event.type === 'click' && link.contains(event.target)) {
171			event.preventDefault();
172		}
173
174		scheduleFallback(link);
175	}
176
177	document.addEventListener('click', handlePlayActivation);
178	document.addEventListener('pointerup', handlePlayActivation);
179	document.addEventListener('touchend', handlePlayActivation);
180
181	document.addEventListener('click', function (event) {
182		if (
183			event.target.matches('.gbf-video-lightbox, .gbf-video-lightbox__close') ||
184			event.target.closest('.gbf-video-lightbox__close')
185		) {
186			closeFallback();
187		}
188	});
189
190	document.addEventListener('keydown', function (event) {
191		if (event.key === 'Escape') {
192			closeFallback();
193		}
194	});
195}());

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.