PageSourceSearch

https://www.savannahtoyota.com/app/themes/dv-framework/media/js/da-gform-loader.js?v=1.786.483

js savannahtoyota.com collected 2026-10-08 23:28:08 UTC 3,865 bytes, 104 lines download raw bytes

1/**
2 * @DealerAlchemist shared Gravity Forms AJAX loader — daGformLoad
3 *
4 * The one place the get_gform fetch flow lives: reset GF's stuck submit flag, request
5 * the rendered form, inject it so its init scripts execute, re-arm the anti-spam
6 * honeypot, and announce the render. Consolidates the copies that had grown in
7 * dv-modal-disclaimer.js, da-modal.js (DAPopUp) and da-gform-hydrate.js — the latter
8 * two now delegate here. dv-modal-disclaimer.js keeps its inline copies on purpose:
9 * its contract is frozen for the ~20 existing DVPopUp callers.
10 *
11 * @param {HTMLElement}   el     Container whose contents are replaced by the form
12 * @param {number|string} formId Gravity Form id
13 * @param {Object} [opts]
14 * @param {string} [opts.vin]      For forms that prefill vehicle data; omitted from the
15 *                                 request entirely when absent — not all forms take one.
16 * @param {string} [opts.html]     Previously-fetched form HTML: injected directly with no
17 *                                 request. The hydrator uses this so a form the React
18 *                                 bundle wiped comes back without another XHR.
19 * @param {Function} [opts.onLoaded] Called with the HTML after a successful fetch, so
20 *                                 callers can cache it for opts.html next time.
21 * @param {Function} [opts.after]  Called with el after injection and re-init, whether
22 *                                 the HTML came from the network or from opts.html.
23 */
24(function (window, document) {
25	"use strict";
26
27	var AJAX_TIMEOUT_MS = 15000;
28
29	// A caller embedding a form cannot know its surrounding page context, so it cannot
30	// supply context-appropriate error UI — and an unexplained hole in the page is worse
31	// than an honest error. Always show the shopper a minimal, visible error state.
32	function showError(el) {
33		el.innerHTML = '<p class="da-gform-error">Error loading form.</p>';
34	}
35
36	window.daGformLoad = function (el, formId, opts) {
37		var $ = window.jQuery;
38		var id = parseInt(formId, 10);
39
40		opts = opts || {};
41
42		if (!el) return;
43
44		if (!id || !$) {
45			console.warn("da-gform: cannot load form", id || formId, $ ? "" : "(jQuery unavailable)");
46			showError(el);
47			return;
48		}
49
50		// Gravity Forms never clears this flag on submit, so a second load of the same
51		// form would silently refuse to post.
52		window["gf_submitting_" + id] = false;
53
54		function inject(html) {
55			// jQuery .html() executes the init scripts the endpoint prepends; innerHTML would not.
56			$(el).html(html);
57
58			if (typeof window.wpae_reinitalize_after_form_load === "function") {
59				window.wpae_reinitalize_after_form_load();
60			} else if (typeof window.wpa_add_honeypot_field === "function") {
61				window.wpa_add_honeypot_field();
62			}
63
64			$(document).trigger("gform_post_render", [ id, 1 ]);
65
66			if (opts.after) opts.after(el);
67		}
68
69		if (opts.html) {
70			inject(opts.html);
71			return;
72		}
73
74		el.innerHTML = '<div class="dv-form-loading" style="text-align:center;padding:20px;">'
75			+ '<i class="fas fa-spinner fa-spin"></i> Loading Form...</div>';
76
77		var data = { action: "get_gform", form_id: id, referrer_url: window.location.href };
78
79		if (opts.vin) data.vin = opts.vin;
80
81		$.ajax({
82			url: "/wp/wp-admin/admin-ajax.php",
83			type: "POST",
84			timeout: AJAX_TIMEOUT_MS,
85			data: data,
86			success: function (response) {
87				if (!response || !response.success || !response.data || !response.data.html) {
88					console.warn("da-gform: could not load form " + id,
89						(response && response.data && response.data.message) || "");
90					showError(el);
91					return;
92				}
93
94				if (opts.onLoaded) opts.onLoaded(response.data.html);
95
96				inject(response.data.html);
97			},
98			error: function (xhr, status) {
99				console.warn("da-gform: could not load form " + id, status || "");
100				showError(el);
101			}
102		});
103	};
104})(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.