PageSourceSearch

https://inbase.cz/en/wp-content/themes/inbase/js/ib-cf7-loading.js?ver=1783505764

js inbase.cz collected 2026-10-08 21:33:30 UTC 2,925 bytes, 73 lines download raw bytes

1/* InBase — CF7 submit loading state. Vanilla JS, ES5-compatible.
2 *
3 * Replaces the third-party CF7 spinner plugin. While a Contact Form 7
4 * form is submitting (AJAX round-trip), the submit button is disabled
5 * and relabelled ("Odesílám…" / "Odosielam…" / "Sending…") so the user
6 * sees something is happening and can't fire duplicate submissions by
7 * clicking repeatedly. The spinner itself is CF7's own .wpcf7-spinner
8 * element, restyled in style.css (section "CF7 SUBMIT LOADING STATE").
9 *
10 * Hooks: wpcf7beforesubmit (CF7 5.2+) starts the state; wpcf7submit
11 * fires on every completed round-trip (sent / invalid / spam / failed)
12 * and restores it. A 30 s timeout is the safety net for the one case
13 * CF7 emits no completion event (network drop), so the form never
14 * stays locked.
15 */
16(function () {
17	// Each language runs as its own site, so <html lang> (set by
18	// language_attributes() in header.php) is authoritative.
19	var lang = (document.documentElement.getAttribute('lang') || 'cs').toLowerCase().slice(0, 2);
20	if (lang === 'cz') { lang = 'cs'; }
21	var LABELS = { cs: 'Odesílám…', sk: 'Odosielam…', en: 'Sending…' };
22	var label = LABELS[lang] || LABELS.cs;
23
24	// CF7 DOM events fire on the div.wpcf7 wrapper — dig out the form.
25	function formOf(event) {
26		var t = event.target;
27		if (!t) { return null; }
28		if (t.tagName === 'FORM') { return t; }
29		return t.querySelector ? t.querySelector('form.wpcf7-form') : null;
30	}
31
32	function start(form) {
33		if (!form || form.getAttribute('data-ib-loading') === '1') { return; }
34		form.setAttribute('data-ib-loading', '1');
35
36		var btn = form.querySelector('.wpcf7-submit');
37		if (btn) {
38			// Freeze the current width so the loading label doesn't make
39			// the button jump.
40			btn.style.minWidth = btn.offsetWidth + 'px';
41			btn.setAttribute('data-ib-label', btn.tagName === 'INPUT' ? btn.value : btn.textContent);
42			if (btn.tagName === 'INPUT') { btn.value = label; } else { btn.textContent = label; }
43			btn.disabled = true;
44			btn.setAttribute('aria-busy', 'true');
45		}
46
47		form._ibCf7Timer = window.setTimeout(function () { stop(form); }, 30000);
48	}
49
50	function stop(form) {
51		if (!form || form.getAttribute('data-ib-loading') !== '1') { return; }
52		form.removeAttribute('data-ib-loading');
53		if (form._ibCf7Timer) {
54			window.clearTimeout(form._ibCf7Timer);
55			form._ibCf7Timer = null;
56		}
57
58		var btn = form.querySelector('.wpcf7-submit');
59		if (btn) {
60			var orig = btn.getAttribute('data-ib-label');
61			if (orig !== null) {
62				if (btn.tagName === 'INPUT') { btn.value = orig; } else { btn.textContent = orig; }
63				btn.removeAttribute('data-ib-label');
64			}
65			btn.style.minWidth = '';
66			btn.disabled = false;
67			btn.removeAttribute('aria-busy');
68		}
69	}
70
71	document.addEventListener('wpcf7beforesubmit', function (e) { start(formOf(e)); }, false);
72	document.addEventListener('wpcf7submit', function (e) { stop(formOf(e)); }, false);
73})();

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.