PageSourceSearch

https://encyclopediaofarkansas.net/wp-content/plugins/gwreloadform/scripts/gp-reload-form.js?ver=2.1.8

js encyclopediaofarkansas.net collected 2026-09-24 08:43:29 UTC 4,518 bytes, 133 lines download raw bytes

1/**
2 * GP Reload Form Front-end JS
3 */
4( function( $ ) {
5
6	window.gwrf = window.GPReloadForm = function( args ) {
7
8		var self = this;
9
10		self.formId         = args.formId;
11		self.spinnerUrl     = args.spinnerUrl;
12		self.refreshTime    = args.refreshTime;
13		self.refreshTimeout = null;
14
15		// if we've already done the init for this form, don't do it again on subsequent gform_post_render calls
16		if ( window[ 'gwrf_' + args.formId ] ) {
17			return window[ 'gwrf_' + args.formId ];
18		}
19
20		self.formWrapper = $( '#gform_wrapper_' + self.formId );
21		self.staticElem  = self.formWrapper.parent().add('#gf-cache-buster-form-container-' + self.formId).first();
22
23		var clonedElem = $( '<div>' ).append( self.formWrapper.clone() );
24		clonedElem.find( '.ginput_counter' ).remove();
25
26		self.formHtml           = clonedElem.html();//.replace( /gform_post_render/g, 'XYZ' ); //$( '<div />' ).append( self.formWrapper.clone() ).html();
27		self.spinnerInitialized = false;
28
29		// Make sure we initialize multiple forms sharing the same wrapper
30		if ( self.staticElem.data( 'gwrf_' + self.formId ) ) {
31			return self.staticElem.data( 'gwrf_' + self.formId );
32		}
33		self.init = function() {
34
35			$( document ).bind( 'gform_confirmation_loaded', function( event, formId ) {
36				if ( formId != self.formId ) {
37					return;
38				}
39
40				if (window['RELOAD_FORM_MARKUP_' + formId]) {
41					self.formHtml = window['RELOAD_FORM_MARKUP_' + formId]
42						/**
43						 * See note in GP_Reload_Form::append_form_markup() regarding the Gravity Forms confirmation
44						 * and why we need to escape/unescape this string.
45						 */
46						.replace(/gformGP_RELOAD_FORM_ESCAPEDRedirect\(\){/g, 'gformRedirect(){');
47				}
48
49				if ( self.refreshTime <= 0 || self.staticElem.find( '.form_saved_message' ).length > 0 ) {
50					return;
51				}
52
53				self.refreshTimeout = setTimeout( function() {
54					self.reloadForm();
55				}, self.refreshTime * 1000 );
56
57			} );
58
59			self.staticElem.on( 'click', 'a.gws-reload-form', function( event ) {
60				event.preventDefault();
61				// Ensure we're calling the correct `reloadForm()`
62				var linkFormId = parseInt( event.currentTarget.getAttribute( 'data-formId' ) );
63				if ( self.formId !== linkFormId ) { // This was meant for a different form, re-direct call
64					return window[ 'gwrf_' + linkFormId ].reloadForm();
65				}
66				self.reloadForm();
67			} );
68
69			self.staticElem.data( 'gwrf_' + self.formId, self );
70
71		};
72
73		self.reloadForm = function() {
74
75			if ( self.refreshTimeout ) {
76				clearTimeout( self.refreshTimeout );
77			}
78
79			var $replacingElem = self.staticElem.find( '#gform_confirmation_wrapper_' + self.formId + ', .gform_confirmation_message_' + self.formId + ', #gform_wrapper_' + self.formId );
80			/**
81			 * Filter which element will be replaced with the original form markup.
82			 *
83			 * @param {jQuery}       $replacingElem The element to be replaced with the original form markup.
84			 * @param int            formId         The ID of the current form.
85			 * @param {GPReloadForm} gprf           The current instance of GPReloadForm.
86			 *
87			 * @since 2.0.1
88			 *
89			 * @type {jQuery}
90			 */
91			$replacingElem = gform.applyFilters( 'gprf_replacing_elem', $replacingElem, self.formId, self );
92			$replacingElem.replaceWith( self.formHtml );
93
94			window[ 'gf_submitting_' + self.formId ] = false;
95			gformInitSpinner( self.formId, self.spinnerUrl );
96
97			self.clearGPNFEntries();
98
99			$( document ).trigger( 'gform_post_render', [ parseInt( self.formId ), 1 ] );
100
101			if ( window['gformInitDatepicker'] ) {
102				gformInitDatepicker();
103			}
104
105		};
106
107		/**
108		 * Nested Forms tries to persist entries when a form is reloaded via AJAX to support multi-page forms using
109		 * AJAX.
110		 *
111		 * This is problematic when Reload Forms reloads the form with AJAX, so we need to handle clearing out the entries
112		 * ourselves.
113		 *
114		 * It's also worth noting that this will always happen regardless of "Preserve values from previous submission"
115		 * being checked or not due to the nature of the previously submitted child entries being attached to the
116		 * previously submitted parent entry.
117		 */
118		self.clearGPNFEntries = function () {
119			self.formWrapper.find( '.gpnf-nested-entries-container' ).each( function () {
120				var formFieldId = $( this ).siblings( 'input[type="hidden"][data-bind]' ).prop( 'id' ).replace( 'input_' + self.formId + '_', '' );
121				var gpnf = window[ 'GPNestedForms_' + self.formId + '_' + formFieldId ];
122
123				if ( gpnf ) {
124					gpnf.entries = [];
125				}
126			} );
127		}
128
129		self.init();
130
131	};
132
133} )( jQuery );

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.