PageSourceSearch

https://futurock.fm/wp-content/themes/ark/assets/scripts/components/custom-contact-form.js?ver=7.1.2

js futurock.fm collected 2026-10-02 08:04:20 UTC 16,452 bytes, 474 lines download raw bytes

1(function($) {
2	$(document).ready(function() {
3		"use strict";
4
5		const arkFormSubmitHandlerEnd = new CustomEvent('arkFormSubmitHandlerEnd', {
6			detail: {},
7			bubbles: false,
8			cancelable: true,
9			composed: false
10		});
11
12		$('.ff-custom-form').each(function(){
13			var $contactForm = $(this);
14
15			// contains translations from element name attr to its real name what will be shown in email
16			var nameToTitleMap = {};
17
18			var rules = {};
19			var messages = {};
20
21            var customFormSettings = JSON.parse($contactForm.attr('data-custom-form-settings'));
22
23            var awaitingResponse = false;
24
25			/*----------------------------------------------------------*/
26			/* INITIALIZING NAMES
27			/*----------------------------------------------------------*/
28
29			$contactForm.find('.ff-form-input-item').each(function( index ) {
30				var $input = $(this);
31				var nameAttr = 'ff-contact-input-' + index;
32				var inputNameInEmail = $input.attr('data-name');
33				var inputType = $input.attr('data-input-type');
34
35				nameToTitleMap[ nameAttr ] = inputNameInEmail;
36
37				switch( inputType ) {
38					case 'text':
39					case 'textarea':
40					case 'select':
41
42						$input.attr('name', nameAttr);
43
44						break;
45
46					case 'checkbox':
47						var $shadowInput = $('<input type="hidden" value="[0]">');
48						$shadowInput.attr('name', nameAttr);
49						$input.before( $shadowInput );
50						$input.attr('name', nameAttr);
51						break;
52
53					case 'radio':
54
55						$input.find('input').attr('name', nameAttr );
56
57						break;
58
59				}
60			});
61
62			/*----------------------------------------------------------*/
63			/* INITIALIZING VALIDATION RULES
64		 	/*----------------------------------------------------------*/
65
66			$contactForm.find('.ff-form-input-item').each(function( index ) {
67				var $input = $(this);
68				var nameAttr = 'ff-contact-input-' + index;
69				var inputType = $input.attr('data-input-type');
70
71				var elementsWithValidationRules = ['text', 'textarea', 'checkbox'];
72				if( elementsWithValidationRules.indexOf( inputType) == -1 ) {
73					return;
74				}
75
76				var validationRulesJSON = $input.attr('data-validation');
77				var validationRules = JSON.parse( validationRulesJSON );
78
79				var message = {};
80				var rule = {};
81
82
83
84				switch( inputType ) {
85					case 'text':
86					case 'textarea':
87						// console.log( validationRules );
88						if( parseInt(validationRules['is-required']) == 1 ) {
89							rule.required = true;
90							message.required = validationRules['is-required-message'];
91						}
92
93						if( parseInt(validationRules['min-length-has']) == 1 ) {
94							rule.minlength = parseInt(validationRules['min-length']);
95							message.minlength = validationRules['min-length-message'];
96						}
97
98						switch( validationRules['validation-type'] ) {
99							case 'email':
100									rule.email = true;
101									message.email = validationRules['validation-message'];
102								break;
103
104							case 'number':
105									rule.number = true;
106									message.number= validationRules['validation-message'];
107								break;
108
109							case 'regex':
110
111									// adding custom method containing the regexp
112									$.validator.addMethod(
113										'regex-'+nameAttr,
114										function(value, element, regexp) {
115											var re = new RegExp( regexp );
116											return this.optional(element) || re.test(value);
117										},
118										validationRules['validation-message']
119									);
120
121									rule['regex-'+nameAttr] = validationRules['validation-type-regex'];
122								break;
123							
124							case 'custom-function':
125								var customFunction = validationRules['validation-type-custom-function'];
126								customFunction = 'customFunction = function(value, $element, $form){ ' + customFunction + '}';
127								customFunction = eval( customFunction );
128
129								$.validator.addMethod(
130									'custom-function-'+nameAttr,
131									function(value, element) {
132										var $form = $(element).parents('form:first');
133										return customFunction( value, $(element), $form );
134									},
135									validationRules['validation-message']
136								);
137
138								rule['custom-function-'+nameAttr] = true;
139
140								break;
141						}
142						break;
143					case 'checkbox':
144
145						if( parseInt(validationRules['checkbox-validation']) == 1 ) {
146							rule.required = true;
147							message.required = validationRules['checkbox-validation-message'];
148						}
149
150
151						break;
152
153				}
154
155				// rules['g-recaptcha-response'].required = true;
156				rules[nameAttr] = rule;
157				messages[nameAttr] = message;
158			});
159
160			var resetContactFormValues = function() {
161				$contactForm.find('.ff-form-input-item').each(function( index ) {
162					var $input = $(this);
163					var nameAttr = 'ff-contact-input-' + index;
164					var inputType = $input.attr('data-input-type');
165
166
167
168					switch( inputType ) {
169						case 'text':
170						case 'textarea':
171							$input.val('');
172							break;
173
174						case 'checkbox':
175
176
177							if( parseInt($input.attr('data-checked')) == 1 ) {
178								$input.attr('checked', 'checked');
179								$input.prop('checked', 'checked');
180							} else {
181								$input.attr('checked', '');
182								$input.prop('checked', '');
183							}
184
185							break;
186
187						case 'select':
188							var originalValue = $input.find('option[selected="selected"]').val();
189							$input.val( originalValue );
190
191							break;
192
193						case 'radio':
194							$input.find('input').prop('checked', false);
195							$input.find('input[data-checked]').prop('checked', true);
196							break;
197
198					}
199
200				});
201			};
202
203			var $nameToTitleMap = $('<input type="hidden" name="ff-name-to-title-map">');
204			$nameToTitleMap.attr('value', JSON.stringify( nameToTitleMap ) );
205			$contactForm.append( $nameToTitleMap );
206
207			var validator = $(this).validate({
208				rules: rules,
209
210				errorPlacement: function (error, element) {
211					if (element.attr('type') == 'checkbox') {
212						error.insertAfter($(element).closest('.ff-form-checkbox-wrapper')).hide().show(150);
213					} else {
214						error.insertAfter($(element)).hide().show(150);
215					}
216				},
217
218				messages: messages,
219
220				submitHandler: function() {
221
222					if ( awaitingResponse ) {
223						// return and await previous submit click response
224						return false;
225					} else {
226						// proceed and await new response
227						awaitingResponse = true;
228					}
229
230                    /*----------------------------------------------------------*/
231                    /* SUBMIT FORM
232                    /*----------------------------------------------------------*/
233
234                    if( customFormSettings['form-action'] == 'submit' ) {
235                        var contactFormValueArray = $contactForm.serializeArray();
236                        var contactFormValue = [];
237                        var oneValue, i;
238
239                        for( i in contactFormValueArray ) {
240                            oneValue = contactFormValueArray[ i ];
241
242                            contactFormValue[ oneValue.name ] = oneValue.value;
243
244                        }
245
246                        var nameToTitle = JSON.parse( contactFormValue['ff-name-to-title-map'] );
247
248                        var $form = $('<form></form>');
249
250                        $form.attr('action', $contactForm.attr('action'));
251                        $form.attr('method', $contactForm.attr('method'));
252
253                        //$form.attr('method', 'post');
254                        $form.css('display', 'none');
255                        for( var key in contactFormValue ) {
256                            oneValue = contactFormValue[ key ];
257
258                            if( key == 'ff-name-to-title-map' ) {
259                                continue;
260                            }
261
262                            var newValue = {};
263                            newValue.value = oneValue;
264                            newValue.name = nameToTitle[ key ];
265
266                            var $input = $('<input>');
267
268                            if( newValue.value == '[0]' || newValue.value == '[1]') {
269                                if( $('input[data-name="' + newValue.name + '"]').attr('type') == 'checkbox' ) {
270                                    newValue.value = newValue.value.replace('[', '').replace(']', '');
271                                }
272                            }
273
274
275                            $input.attr('type', 'hidden');
276                            $input.attr('name', newValue.name);
277                            $input.attr('value', newValue.value);
278
279                            $form.append( $input );
280
281                        }
282
283                        var formUniqueId = $contactForm.attr('data-unique-id');
284                        var $hiddenInput = $('<input>');
285
286                        $hiddenInput.attr('type', 'hidden');
287                        $hiddenInput.attr('name', 'ff-form-unique-id');
288                        $hiddenInput.attr('value', formUniqueId );
289                        $form.append( $hiddenInput );
290                        //$form.append('<input type="hidden" name="ff-form-unique-id" value="' + formUniqueId +)
291
292                        $contactForm.after( $form );
293
294                        $form.submit();
295
296                        return;
297                    }
298                    /*----------------------------------------------------------*/
299                    /* SEND AJAX EMAIL
300                    /*----------------------------------------------------------*/
301                    else if ( customFormSettings['form-action'] == 'email' ) {
302
303                        if($contactForm.attr('data-trigger')){
304                            $('body').trigger($contactForm.attr('data-trigger'), [$contactForm]);
305                            $contactForm.triggerHandler($contactForm.attr('data-trigger'));
306                        }
307
308                        var serializedContent = $contactForm.serialize();
309
310                        var data = {};
311                        data.formInput = serializedContent;
312                        data.contactInfo = $contactForm.find('.ff-contact-info').html();
313
314
315                        frslib.ajax.frameworkRequest('contactform-send-ajax', null, data, function( response ) {
316
317                            awaitingResponse = false; // = response received
318
319                            console.log( response );
320
321                            if( response == 'true' ) {
322
323                                resetContactFormValues();
324
325                                $contactForm.find('.ff-message-send-ok-duplicate').hide(150, function(){ $(this).remove(); });
326
327                                $contactForm.find('.ff-message-send-ok').each(function(){
328                                    var $clonnedMessage = $(this).clone();
329
330                                    $clonnedMessage.removeClass('ff-message-send-ok').addClass('ff-message-send-ok-duplicate');
331                                    $clonnedMessage.removeClass('hidden');
332                                    $clonnedMessage.css('display', 'none');
333
334                                    $(this).after( $clonnedMessage );
335
336                                    $clonnedMessage.toggle(500);
337
338                                    var hideAfter = $(this).attr('data-hide');
339
340                                    if( hideAfter != undefined ) {
341                                        hideAfter = parseInt( hideAfter );
342                                        setTimeout(function(){
343
344                                            $clonnedMessage.hide(500, function(){
345                                                $(this).remove();
346                                            });
347
348                                        }, hideAfter);
349                                    }
350
351                                });
352
353                                if($contactForm.attr('data-trigger')){
354                                    $('body').trigger($contactForm.attr('data-trigger') + '-sent-ok', [$contactForm]);
355                                    $contactForm.triggerHandler($contactForm.attr('data-trigger') + '-sent-ok');
356                                }
357
358
359                                if( customFormSettings['redirect-to-url-ok'] ) {
360                                    window.location = customFormSettings['redirect-to-url-ok'];
361                                }
362
363                            } else {
364
365                                $contactForm.find('.ff-message-send-wrong-duplicate').hide(150, function(){ $(this).remove(); });
366
367                                $contactForm.find('.ff-message-send-wrong').each(function(){
368                                    var $clonnedMessage = $(this).clone();
369
370                                    $clonnedMessage.removeClass('ff-message-send-wrong').addClass('ff-message-send-wrong-duplicate');
371                                    $clonnedMessage.removeClass('hidden');
372                                    $clonnedMessage.css('display', 'none');
373
374                                    $(this).after( $clonnedMessage );
375
376                                    $clonnedMessage.toggle(500);
377
378                                    var hideAfter = $(this).attr('data-hide');
379
380                                    if( hideAfter != undefined ) {
381                                        hideAfter = parseInt( hideAfter );
382                                        setTimeout(function(){
383
384                                            $clonnedMessage.hide(500, function(){
385                                                $(this).remove();
386                                            });
387
388                                        }, hideAfter);
389                                    }
390
391                                });
392
393                                if($contactForm.attr('data-trigger')){
394                                    $('body').trigger($contactForm.attr('data-trigger') + '-sent-wrong', [$contactForm]);
395                                    $contactForm.triggerHandler($contactForm.attr('data-trigger') + '-sent-wrong');
396                                }
397
398                                if( customFormSettings['redirect-to-url-wrong'] ) {
399                                    window.location = customFormSettings['redirect-to-url-wrong'];
400                                }
401                            }
402
403                        });
404
405                    }
406
407
408                    /*----------------------------------------------------------*/
409                    /* AUTO RESPONDERS
410                    /*----------------------------------------------------------*/
411
412                    $contactForm.find('.ff-autoresponder').each(function(){
413                        var code = $(this).html();
414                        var printInConsole = $(this).attr('data-print-console');
415                        var responderName = $(this).attr('data-form-responder-name');
416
417                        var serializedContent = $contactForm.serialize();
418
419                        var data = {};
420                        data.formInput = serializedContent;
421                        data.responderName = responderName;
422                        //data.code =
423                        //data.contactInfo = $contactForm.find('.ff-contact-info').html();
424
425                        frslib.ajax.frameworkRequest('contactform-autoresponder-ajax', null, data, function( response ) {
426                            if( printInConsole ) {
427                                console.log( response );
428                            }
429                        });
430
431                    });
432
433                    /*----------------------------------------------------------*/
434                    /* SUBMIT HANDLER END EVENT
435                    /*----------------------------------------------------------*/
436					$contactForm[0].dispatchEvent( arkFormSubmitHandlerEnd );
437
438				}
439			});
440
441			$contactForm.find('.ffb-contact-button-send').on('click', function(){
442
443				var couldBeSend = true; // field validation will still take place after this so it might not send even when this is true
444				$contactForm.find('.ffb-captcha-wrapper').each(function(){
445					var $captchaWrapper = $(this);
446
447					var $textarea = $(this).find('.g-recaptcha-response');
448					var value = $textarea.val();
449
450					if( value.length == 0 ) {
451						couldBeSend = false;
452
453						$captchaWrapper.find('.ff-contact-form-captcha-error').hide().removeClass('hidden').show(150);
454					} else {
455						couldBeSend = true;
456
457						$captchaWrapper.find('.ff-contact-form-captcha-error').hide(150);
458					}
459
460				});
461
462
463				if( couldBeSend ) {
464					$contactForm.submit();
465				} else {
466					return false;
467				}
468
469			});
470
471
472		});
473	});
474})(window.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.