PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | js/formidable.js +123 -511 6.5.35.4 View file →
@@ -10,70 +10,19 @@
10 10
11 11 var action = '';
12 12 var jsErrors = [];
13 13
14 - /**
15 - * Maybe add polyfills.
16 - *
17 - * @since 5.4
18 - */
19 - function maybeAddPolyfills() {
20 - var i;
21 - if ( ! Element.prototype.matches ) {
22 - // IE9 supports matches but as msMatchesSelector instead.
23 - Element.prototype.matches = Element.prototype.msMatchesSelector;
24 - }
14 + function maybeShowLabel() {
15 + /*jshint validthis:true */
16 + var $field = jQuery( this ),
17 + $label = $field.closest( '.frm_inside_container' ).find( '.frm_primary_label' ),
18 + val = $field.val();
25 19
26 - if ( ! Element.prototype.closest ) {
27 - Element.prototype.closest = function( s ) {
28 - var el = this;
29 -
30 - do {
31 - if ( el.matches( s ) ) {
32 - return el;
33 - }
34 - el = el.parentElement || el.parentNode;
35 - } while ( el !== null && el.nodeType === 1 );
36 -
37 - return null;
38 - };
39 - }
40 -
41 - // NodeList.forEach().
42 - if ( window.NodeList && ! NodeList.prototype.forEach ) {
43 - NodeList.prototype.forEach = function( callback, thisArg ) {
44 - thisArg = thisArg || window;
45 - for ( i = 0; i < this.length; i++ ) {
46 - callback.call( thisArg, this[ i ], i, this );
47 - }
48 - };
49 - }
50 - }
51 -
52 - /**
53 - * Triggers custom JS event.
54 - *
55 - * @since 5.5.3
56 - *
57 - * @param {HTMLElement} el The HTML element.
58 - * @param {String} eventName Event name.
59 - * @param {mixed} data The passed data.
60 - */
61 - function triggerCustomEvent( el, eventName, data ) {
62 - var event;
63 -
64 - if ( typeof window.CustomEvent === 'function' ) {
65 - event = new CustomEvent( eventName );
66 - } else if ( document.createEvent ) {
67 - event = document.createEvent( 'HTMLEvents' );
68 - event.initEvent( eventName, false, true );
20 + if ( val !== null && val.length > 0 ) {
21 + $label.addClass( 'frm_visible' );
69 22 } else {
70 - return;
23 + $label.removeClass( 'frm_visible' );
71 24 }
72 -
73 - event.frmData = data;
74 -
75 - el.dispatchEvent( event );
76 25 }
77 26
78 27 /* Get the ID of the field that changed*/
79 28 function getFieldId( field, fullID ) {
@@ -162,9 +111,9 @@
162 111 *
163 112 * @since 2.03.02
164 113 *
165 114 * @param {object} $form
166 - */
115 + */
167 116 function disableSubmitButton( $form ) {
168 117 $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).attr( 'disabled', 'disabled' );
169 118 }
170 119
@@ -173,9 +122,9 @@
173 122 *
174 123 * @since 2.03.02
175 124 *
176 125 * @param {object} $form
177 - */
126 + */
178 127 function enableSubmitButton( $form ) {
179 128 $form.find( 'input[type="submit"], input[type="button"], button[type="submit"]' ).prop( 'disabled', false );
180 129 }
181 130
@@ -201,12 +150,11 @@
201 150 $form.find( 'a.frm_save_draft' ).css( 'pointer-events', '' );
202 151 }
203 152
204 153 function validateForm( object ) {
205 - var errors, r, rl, n, nl, fields, field, requiredFields;
154 + var r, rl, n, nl, fields, field, value, requiredFields,
155 + errors = [];
206 156
207 - errors = [];
208 -
209 157 // Make sure required text field is filled in
210 158 requiredFields = jQuery( object ).find(
211 159 '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea'
212 160 ).filter( ':not(.frm_optional)' );
@@ -223,18 +171,24 @@
223 171 fields = jQuery( object ).find( 'input,select,textarea' );
224 172 if ( fields.length ) {
225 173 for ( n = 0, nl = fields.length; n < nl; n++ ) {
226 174 field = fields[n];
227 - if ( '' === field.value ) {
228 - if ( 'number' === field.type ) {
229 - // A number field will return an empty string when it is invalid.
230 - checkValidity( field, errors );
175 + value = field.value;
176 + if ( value !== '' ) {
177 + if ( field.type === 'hidden' ) {
178 + // don't validate
179 + } else if ( field.type === 'number' ) {
180 + errors = checkNumberField( field, errors );
181 + } else if ( field.type === 'email' ) {
182 + errors = checkEmailField( field, errors );
183 + } else if ( field.type === 'password' ) {
184 + errors = checkPasswordField( field, errors );
185 + } else if ( field.type === 'url' ) {
186 + errors = checkUrlField( field, errors );
187 + } else if ( field.pattern !== null ) {
188 + errors = checkPatternField( field, errors );
231 189 }
232 - continue;
233 190 }
234 -
235 - validateFieldValue( field, errors );
236 - checkValidity( field, errors );
237 191 }
238 192 }
239 193
240 194 errors = validateRecaptcha( object, errors );
@@ -242,33 +196,8 @@
242 196 return errors;
243 197 }
244 198
245 199 /**
246 - * Check the ValidityState interface for the field.
247 - * If it is invalid, show an error for it.
248 - *
249 - * @param {HTMLElement} field
250 - * @param {Array} errors
251 - * @returns
252 - */
253 - function checkValidity( field, errors ) {
254 - var fieldID;
255 - if ( 'object' !== typeof field.validity || false !== field.validity.valid ) {
256 - return;
257 - }
258 -
259 - fieldID = getFieldId( field, true );
260 - if ( 'undefined' === typeof errors[ fieldID ]) {
261 - errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
262 - }
263 -
264 - if ( 'function' === typeof field.reportValidity ) {
265 - // This triggers an error pop up.
266 - field.reportValidity();
267 - }
268 - }
269 -
270 - /**
271 200 * @since 5.0.10
272 201 *
273 202 * @param {object} element
274 203 * @param {string} targetClass
@@ -305,9 +234,19 @@
305 234 errors = checkRequiredField( field, errors );
306 235 }
307 236
308 237 if ( errors.length < 1 ) {
309 - validateFieldValue( field, errors );
238 + if ( field.type === 'email' ) {
239 + errors = checkEmailField( field, errors );
240 + } else if ( field.type === 'password' ) {
241 + errors = checkPasswordField( field, errors );
242 + } else if ( field.type === 'number' ) {
243 + errors = checkNumberField( field, errors );
244 + } else if ( field.type === 'url' ) {
245 + errors = checkUrlField( field, errors );
246 + } else if ( field.pattern !== null ) {
247 + errors = checkPatternField( field, errors );
248 + }
310 249 }
311 250
312 251 removeFieldError( $fieldCont );
313 252 if ( Object.keys( errors ).length > 0 ) {
@@ -316,29 +255,8 @@
316 255 }
317 256 }
318 257 }
319 258
320 - function validateFieldValue( field, errors ) {
321 - if ( field.type === 'hidden' ) {
322 - // don't validate
323 - } else if ( field.type === 'number' ) {
324 - checkNumberField( field, errors );
325 - } else if ( field.type === 'email' ) {
326 - checkEmailField( field, errors );
327 - } else if ( field.type === 'password' ) {
328 - checkPasswordField( field, errors );
329 - } else if ( field.type === 'url' ) {
330 - checkUrlField( field, errors );
331 - } else if ( field.pattern !== null ) {
332 - checkPatternField( field, errors );
333 - }
334 -
335 - triggerCustomEvent( document, 'frm_validate_field_value', {
336 - field: field,
337 - errors: errors
338 - });
339 - }
340 -
341 259 function checkRequiredField( field, errors ) {
342 260 var checkGroup, tempVal, i, placeholder,
343 261 val = '',
344 262 fieldID = '',
@@ -454,8 +372,9 @@
454 372 if ( ! ( fieldID in errors ) ) {
455 373 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
456 374 }
457 375 }
376 + return errors;
458 377 }
459 378
460 379 function checkEmailField( field, errors ) {
461 380 var fieldID = getFieldId( field, true ),
@@ -466,12 +385,14 @@
466 385 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
467 386 }
468 387
469 388 confirmField( field, errors );
389 + return errors;
470 390 }
471 391
472 392 function checkPasswordField( field, errors ) {
473 393 confirmField( field, errors );
394 + return errors;
474 395 }
475 396
476 397 function confirmField( field, errors ) {
477 398 var value, confirmValue, firstField,
@@ -505,8 +426,9 @@
505 426 if ( ! ( fieldID in errors ) ) {
506 427 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
507 428 }
508 429 }
430 + return errors;
509 431 }
510 432
511 433 function checkPatternField( field, errors ) {
512 434 var fieldID,
@@ -521,47 +443,11 @@
521 443 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
522 444 }
523 445 }
524 446 }
447 + return errors;
525 448 }
526 449
527 - /**
528 - * Set color for select placeholders.
529 - *
530 - * @since 6.5.1
531 - */
532 - function setSelectPlaceholderColor() {
533 - var selects = document.querySelectorAll( '.form-field select' ),
534 - styleElement = document.querySelector( '.with_frm_style' ),
535 - textColorDisabled = styleElement ? getComputedStyle( styleElement ).getPropertyValue( '--text-color-disabled' ).trim() : '',
536 - changeSelectColor;
537 -
538 - // Exit if there are no select elements or the textColorDisabled property is missing
539 - if ( ! selects.length || ! textColorDisabled ) {
540 - return;
541 - }
542 -
543 - // Function to change the color of a select element
544 - changeSelectColor = function( select ) {
545 - if ( hasClass( select.options[select.selectedIndex], 'frm-select-placeholder' ) ) {
546 - select.style.setProperty( 'color', textColorDisabled, 'important' );
547 - } else {
548 - select.style.color = '';
549 - }
550 - };
551 -
552 - // Use a loop to iterate through each select element
553 - Array.prototype.forEach.call( selects, function( select ) {
554 - // Apply the color change to each select element
555 - changeSelectColor( select );
556 -
557 - // Add an event listener for future changes
558 - select.addEventListener( 'change', function() {
559 - changeSelectColor( select );
560 - });
561 - });
562 - }
563 -
564 450 function hasInvisibleRecaptcha( object ) {
565 451 var recaptcha, recaptchaID, alreadyChecked;
566 452
567 453 if ( isGoingToPrevPage( object ) ) {
@@ -646,9 +532,9 @@
646 532 return validate;
647 533 }
648 534
649 535 function getFormErrors( object, action ) {
650 - var fieldset, data, success, error, shouldTriggerEvent;
536 + var fieldset, data, success, error;
651 537
652 538 if ( typeof action === 'undefined' ) {
653 539 jQuery( object ).find( 'input[name="frm_action"]' ).val();
654 540 }
@@ -655,21 +541,14 @@
655 541
656 542 fieldset = jQuery( object ).find( '.frm_form_field' );
657 543 fieldset.addClass( 'frm_doing_ajax' );
658 544
659 - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase
660 - shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );
545 + data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce;
661 546
662 547 success = function( response ) {
663 - var defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
664 - $fieldCont, key, inCollapsedSection, frmTrigger, newTab;
665 -
666 - defaultResponse = {
667 - content: '',
668 - errors: {},
669 - pass: false
670 - };
671 -
548 + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
549 + $fieldCont, key, inCollapsedSection, frmTrigger,
550 + defaultResponse = { 'content': '', 'errors': {}, 'pass': false };
672 551 if ( response === null ) {
673 552 response = defaultResponse;
674 553 }
675 554
@@ -680,41 +559,17 @@
680 559 response = defaultResponse;
681 560 }
682 561
683 562 if ( typeof response.redirect !== 'undefined' ) {
684 - if ( shouldTriggerEvent ) {
685 - triggerCustomEvent( object, 'frmSubmitEvent' );
686 - return;
687 - }
688 -
689 563 jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
690 -
691 - if ( ! response.openInNewTab ) {
692 - // We return here because we're redirecting there is no need to update content.
693 - window.location = response.redirect;
694 - return;
695 - }
696 -
697 - // We don't return here because we're opening in a new tab, the old tab will still update.
698 - newTab = window.open( response.redirect, '_blank' );
699 - if ( ! newTab && response.fallbackMsg && response.content ) {
700 - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' );
701 - }
702 - }
703 -
704 - if ( response.content !== '' ) {
564 + window.location = response.redirect;
565 + } else if ( response.content !== '' ) {
705 566 // the form or success message was returned
706 567
707 - if ( shouldTriggerEvent ) {
708 - triggerCustomEvent( object, 'frmSubmitEvent' );
709 - return;
710 - }
711 -
712 568 removeSubmitLoading( jQuery( object ) );
713 - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase
569 + if ( frm_js.offset != -1 ) {
714 570 frmFrontForm.scrollMsg( jQuery( object ), false );
715 571 }
716 -
717 572 formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
718 573 response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
719 574 replaceContent = jQuery( object ).closest( '.frm_forms' );
720 575 removeAddedScripts( replaceContent, formID );
@@ -751,8 +606,9 @@
751 606 delay
752 607 );
753 608 } else if ( Object.keys( response.errors ).length ) {
754 609 // errors were returned
610 +
755 611 removeSubmitLoading( jQuery( object ), 'enable' );
756 612
757 613 //show errors
758 614 contSubmit = true;
@@ -782,9 +638,9 @@
782 638 }
783 639 }
784 640 }
785 641
786 - jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() {
642 + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() {
787 643 var $recaptcha = jQuery( this ),
788 644 recaptchaID = $recaptcha.data( 'rid' );
789 645
790 646 if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
@@ -793,11 +649,8 @@
793 649 } else {
794 650 grecaptcha.reset();
795 651 }
796 652 }
797 - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) {
798 - hcaptcha.reset();
799 - }
800 653 });
801 654
802 655 jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
803 656
@@ -829,9 +682,9 @@
829 682
830 683 function postToAjaxUrl( form, data, success, error ) {
831 684 var ajaxUrl, action, ajaxParams;
832 685
833 - ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase
686 + ajaxUrl = frm_js.ajax_url;
834 687 action = form.getAttribute( 'action' );
835 688
836 689 if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
837 690 ajaxUrl = action.split( '?action=frm_forms_preview' )[0];
@@ -932,22 +785,17 @@
932 785 $fieldCont.append(
933 786 jsErrors[key]
934 787 );
935 788 } else {
936 - roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
789 + roleString = frm_js.include_alert_role ? 'role="alert"' : '';
937 790 $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
938 791 }
939 792
940 793 if ( typeof describedBy === 'undefined' ) {
941 794 describedBy = id;
942 - } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) {
943 - if ( input.data( 'error-first' ) === 0 ) {
944 - describedBy = describedBy + ' ' + id;
945 - } else {
946 - describedBy = id + ' ' + describedBy;
947 - }
795 + } else if ( describedBy.indexOf( id ) === -1 ) {
796 + describedBy = describedBy + ' ' + id;
948 797 }
949 -
950 798 input.attr( 'aria-describedby', describedBy );
951 799 }
952 800 input.attr( 'aria-invalid', true );
953 801
@@ -1080,14 +928,14 @@
1080 928 label.append( '<span class="frm-wait"></span>' );
1081 929
1082 930 jQuery.ajax({
1083 931 type: 'POST',
1084 - url: frm_js.ajax_url, // eslint-disable-line camelcase
932 + url: frm_js.ajax_url,
1085 933 data: {
1086 934 action: 'frm_entries_send_email',
1087 935 entry_id: entryId,
1088 936 form_id: formId,
1089 - nonce: frm_js.nonce // eslint-disable-line camelcase
937 + nonce: frm_js.nonce
1090 938 },
1091 939 success: function( msg ) {
1092 940 var admin = document.getElementById( 'wpbody' );
1093 941 if ( admin === null ) {
@@ -1125,9 +973,32 @@
1125 973 /**********************************************
1126 974 * Fallback functions
1127 975 *********************************************/
1128 976
1129 - function addTrimFallbackForIE() {
977 + function addIndexOfFallbackForIE8() {
978 + var len, from;
979 +
980 + if ( ! Array.prototype.indexOf ) {
981 + Array.prototype.indexOf = function( elt /*, from*/ ) {
982 + len = this.length >>> 0;
983 +
984 + from = Number( arguments[1]) || 0;
985 + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from );
986 + if ( from < 0 ) {
987 + from += len;
988 + }
989 +
990 + for ( ; from < len; from++ ) {
991 + if ( from in this && this[from] === elt ) {
992 + return from;
993 + }
994 + }
995 + return -1;
996 + };
997 + }
998 + }
999 +
1000 + function addTrimFallbackForIE8() {
1130 1001 if ( typeof String.prototype.trim !== 'function' ) {
1131 1002 String.prototype.trim = function() {
1132 1003 return this.replace( /^\s+|\s+$/g, '' );
1133 1004 };
@@ -1133,9 +1004,9 @@
1133 1004 };
1134 1005 }
1135 1006 }
1136 1007
1137 - function addFilterFallbackForIE() {
1008 + function addFilterFallbackForIE8() {
1138 1009 var t, len, res, thisp, i, val;
1139 1010
1140 1011 if ( ! Array.prototype.filter ) {
1141 1012
@@ -1166,8 +1037,26 @@
1166 1037 };
1167 1038 }
1168 1039 }
1169 1040
1041 + function addKeysFallbackForIE8() {
1042 + var keys, i;
1043 +
1044 + if ( ! Object.keys ) {
1045 + Object.keys = function( obj ) {
1046 + keys = [];
1047 +
1048 + for ( i in obj ) {
1049 + if ( obj.hasOwnProperty( i ) ) {
1050 + keys.push( i );
1051 + }
1052 + }
1053 +
1054 + return keys;
1055 + };
1056 + }
1057 + }
1058 +
1170 1059 /**
1171 1060 * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1172 1061 * If this is a match, the User is autofilling the input on a Webkit browser.
1173 1062 * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
@@ -1178,37 +1067,8 @@
1178 1067 this.parentNode.removeChild( this );
1179 1068 }
1180 1069 }
1181 1070
1182 - function maybeMakeHoneypotFieldsUntabbable() {
1183 - document.addEventListener( 'keydown', handleKeyUp );
1184 -
1185 - function handleKeyUp( event ) {
1186 - var code;
1187 -
1188 - if ( 'undefined' !== typeof event.key ) {
1189 - code = event.key;
1190 - } else if ( 'undefined' !== typeof event.keyCode && 9 === event.keyCode ) {
1191 - code = 'Tab';
1192 - }
1193 -
1194 - if ( 'Tab' === code ) {
1195 - makeHoneypotFieldsUntabbable();
1196 - document.removeEventListener( 'keydown', handleKeyUp );
1197 - }
1198 - }
1199 -
1200 - function makeHoneypotFieldsUntabbable() {
1201 - document.querySelectorAll( '.frm_verify' ).forEach(
1202 - function( input ) {
1203 - if ( input.id && 0 === input.id.indexOf( 'frm_email_' ) ) {
1204 - input.setAttribute( 'tabindex', -1 );
1205 - }
1206 - }
1207 - );
1208 - }
1209 - }
1210 -
1211 1071 /**
1212 1072 * Focus on the first sub field when clicking to the primary label of combo field.
1213 1073 *
1214 1074 * @since 4.10.02
@@ -1213,11 +1073,11 @@
1213 1073 *
1214 1074 * @since 4.10.02
1215 1075 */
1216 1076 function changeFocusWhenClickComboFieldLabel() {
1217 - var label;
1077 + let label;
1218 1078
1219 - var comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1079 + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1220 1080 comboInputsContainer.forEach( function( inputsContainer ) {
1221 1081 if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1222 1082 return;
1223 1083 }
@@ -1235,9 +1095,9 @@
1235 1095
1236 1096 function checkForErrorsAndMaybeSetFocus() {
1237 1097 var errors, element, timeoutCallback;
1238 1098
1239 - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase
1099 + if ( ! frm_js.focus_first_error ) {
1240 1100 return;
1241 1101 }
1242 1102
1243 1103 errors = document.querySelectorAll( '.frm_form_field .frm_error' );
@@ -1274,246 +1134,10 @@
1274 1134 }
1275 1135 } while ( element.previousSibling );
1276 1136 }
1277 1137
1278 - /**
1279 - * Checks if is on IE browser.
1280 - *
1281 - * @since 5.4
1282 - *
1283 - * @return {Boolean}
1284 - */
1285 - function isIE() {
1286 - return navigator.userAgent.indexOf( 'MSIE' ) > -1 || navigator.userAgent.indexOf( 'Trident' ) > -1;
1287 - }
1288 -
1289 - /**
1290 - * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
1291 - *
1292 - * @since 5.4
1293 - *
1294 - * @param {String} event Event name.
1295 - * @param {String} selector Selector.
1296 - * @param {Function} handler Handler.
1297 - * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`.
1298 - */
1299 - function documentOn( event, selector, handler, options ) {
1300 - if ( 'undefined' === typeof options ) {
1301 - options = false;
1302 - }
1303 -
1304 - document.addEventListener( event, function( e ) {
1305 - var target;
1306 -
1307 - // loop parent nodes from the target to the delegation node.
1308 - for ( target = e.target; target && target != this; target = target.parentNode ) {
1309 - if ( target && target.matches && target.matches( selector ) ) {
1310 - handler.call( target, e );
1311 - break;
1312 - }
1313 - }
1314 - }, options );
1315 - }
1316 -
1317 - function initFloatingLabels() {
1318 - var checkFloatLabel, checkDropdownLabel, checkPlaceholderIE, runOnLoad, selector, floatClass;
1319 -
1320 - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1321 - floatClass = 'frm_label_float_top';
1322 -
1323 - checkFloatLabel = function( input ) {
1324 - var container, shouldFloatTop, firstOpt;
1325 -
1326 - container = input.closest( '.frm_inside_container' );
1327 - if ( ! container ) {
1328 - return;
1329 - }
1330 -
1331 - shouldFloatTop = input.value || document.activeElement === input;
1332 -
1333 - container.classList.toggle( floatClass, shouldFloatTop );
1334 -
1335 - if ( 'SELECT' === input.tagName ) {
1336 - firstOpt = input.querySelector( 'option:first-child' );
1337 -
1338 - if ( shouldFloatTop ) {
1339 - if ( firstOpt.hasAttribute( 'data-label' ) ) {
1340 - firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
1341 - firstOpt.removeAttribute( 'data-label' );
1342 - }
1343 - } else {
1344 - if ( firstOpt.textContent ) {
1345 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1346 - firstOpt.textContent = '';
1347 - }
1348 - }
1349 - } else if ( isIE() ) {
1350 - checkPlaceholderIE( input );
1351 - }
1352 - };
1353 -
1354 - checkDropdownLabel = function() {
1355 - document.querySelectorAll( '.frm-show-form .frm_inside_container:not(.' + floatClass + ') select' ).forEach( function( input ) {
1356 - var firstOpt = input.querySelector( 'option:first-child' );
1357 -
1358 - if ( firstOpt.textContent ) {
1359 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1360 - firstOpt.textContent = '';
1361 - }
1362 - });
1363 - };
1364 -
1365 - checkPlaceholderIE = function( input ) {
1366 - if ( input.value ) {
1367 - // Don't need to handle this case because placeholder isn't shown.
1368 - return;
1369 - }
1370 -
1371 - if ( document.activeElement === input ) {
1372 - if ( input.hasAttribute( 'data-placeholder' ) ) {
1373 - input.placeholder = input.getAttribute( 'data-placeholder' );
1374 - input.removeAttribute( 'data-placeholder' );
1375 - }
1376 - } else {
1377 - if ( input.placeholder ) {
1378 - input.setAttribute( 'data-placeholder', input.placeholder );
1379 - input.placeholder = '';
1380 - }
1381 - }
1382 - };
1383 -
1384 - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
1385 - documentOn(
1386 - eventName,
1387 - selector,
1388 - function( event ) {
1389 - checkFloatLabel( event.target );
1390 - },
1391 - true
1392 - );
1393 - });
1394 -
1395 - jQuery( document ).on( 'change', selector, function( event ) {
1396 - checkFloatLabel( event.target );
1397 - });
1398 -
1399 - runOnLoad = function( firstLoad ) {
1400 - if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) {
1401 - checkFloatLabel( document.activeElement );
1402 - } else if ( firstLoad ) {
1403 - document.querySelectorAll( '.frm_inside_container' ).forEach(
1404 - function( container ) {
1405 - var input = container.querySelector( 'input, select, textarea' );
1406 - if ( input && '' !== input.value ) {
1407 - checkFloatLabel( input );
1408 - }
1409 - }
1410 - );
1411 - }
1412 -
1413 - checkDropdownLabel();
1414 -
1415 - if ( isIE() ) {
1416 - document.querySelectorAll( selector ).forEach( function( input ) {
1417 - checkPlaceholderIE( input );
1418 - });
1419 - }
1420 - };
1421 -
1422 - runOnLoad( true );
1423 -
1424 - jQuery( document ).on( 'frmPageChanged', function( event ) {
1425 - runOnLoad();
1426 - });
1427 -
1428 - document.addEventListener( 'frm_after_start_over', function( event ) {
1429 - runOnLoad();
1430 - });
1431 - }
1432 -
1433 - function shouldUpdateValidityMessage( target ) {
1434 - if ( 'INPUT' !== target.nodeName ) {
1435 - return false;
1436 - }
1437 -
1438 - if ( ! target.dataset.invmsg ) {
1439 - return false;
1440 - }
1441 -
1442 - if ( 'text' !== target.getAttribute( 'type' ) ) {
1443 - return false;
1444 - }
1445 -
1446 - if ( target.classList.contains( 'frm_verify' ) ) {
1447 - return false;
1448 - }
1449 -
1450 - return true;
1451 - }
1452 -
1453 - function maybeClearCustomValidityMessage( event, field ) {
1454 - var key,
1455 - isInvalid = false;
1456 -
1457 - if ( ! shouldUpdateValidityMessage( field ) ) {
1458 - return;
1459 - }
1460 -
1461 - for ( key in field.validity ) {
1462 - if ( 'customError' === key ) {
1463 - continue;
1464 - }
1465 - if ( 'valid' !== key && field.validity[ key ] === true ) {
1466 - isInvalid = true;
1467 - break;
1468 - }
1469 - };
1470 -
1471 - if ( ! isInvalid ) {
1472 - field.setCustomValidity( '' );
1473 - }
1474 - }
1475 -
1476 - function maybeShowNewTabFallbackMessage() {
1477 - var messageEl;
1478 -
1479 - if ( ! window.frmShowNewTabFallback ) {
1480 - return;
1481 - }
1482 -
1483 - messageEl = document.querySelector( '#frm_form_' + frmShowNewTabFallback.formId + '_container .frm_message' );
1484 - if ( ! messageEl ) {
1485 - return;
1486 - }
1487 -
1488 - messageEl.insertAdjacentHTML( 'beforeend', ' ' + frmShowNewTabFallback.message );
1489 - }
1490 -
1491 - function setCustomValidityMessage() {
1492 - var forms, length, index;
1493 -
1494 - forms = document.getElementsByClassName( 'frm-show-form' );
1495 - length = forms.length;
1496 -
1497 - for ( index = 0; index < length; ++index ) {
1498 - forms[ index ].addEventListener(
1499 - 'invalid',
1500 - function( event ) {
1501 - var target = event.target;
1502 -
1503 - if ( shouldUpdateValidityMessage( target ) ) {
1504 - target.setCustomValidity( target.dataset.invmsg );
1505 - }
1506 - },
1507 - true
1508 - );
1509 - }
1510 - }
1511 -
1512 1138 return {
1513 1139 init: function() {
1514 - maybeAddPolyfills();
1515 -
1516 1140 jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1517 1141 jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
1518 1142
1519 1143 jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
@@ -1528,11 +1152,11 @@
1528 1152
1529 1153 jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail );
1530 1154
1531 1155 jQuery( document ).on( 'change', '.frm-show-form input[name^="item_meta"], .frm-show-form select[name^="item_meta"], .frm-show-form textarea[name^="item_meta"]', frmFrontForm.fieldValueChanged );
1156 + jQuery( document ).on( 'change keyup', '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea', maybeShowLabel );
1532 1157
1533 1158 jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange );
1534 - maybeMakeHoneypotFieldsUntabbable();
1535 1159
1536 1160 jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick );
1537 1161 jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv );
1538 1162
@@ -1540,23 +1164,13 @@
1540 1164
1541 1165 // Focus on the first sub field when clicking to the primary label of combo field.
1542 1166 changeFocusWhenClickComboFieldLabel();
1543 1167
1544 - // Add fallbacks for IE.
1545 - addTrimFallbackForIE(); // Trim only works in IE10+.
1546 - addFilterFallbackForIE(); // Filter is not supported in any version of IE.
1547 -
1548 - initFloatingLabels();
1549 - maybeShowNewTabFallbackMessage();
1550 -
1551 - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
1552 - setCustomValidityMessage();
1553 - jQuery( document ).on( 'frmFieldChanged', maybeClearCustomValidityMessage );
1554 -
1555 - setSelectPlaceholderColor();
1556 -
1557 - // Elementor popup show event. Fix Elementor Popup && FF Captcha field conflicts
1558 - jQuery( document ).on( 'elementor/popup/show', frmRecaptcha );
1168 + // Add fallbacks for the beloved IE8
1169 + addIndexOfFallbackForIE8();
1170 + addTrimFallbackForIE8();
1171 + addFilterFallbackForIE8();
1172 + addKeysFallbackForIE8();
1559 1173 },
1560 1174
1561 1175 getFieldId: function( field, fullID ) {
1562 1176 return getFieldId( field, fullID );
@@ -1739,12 +1353,12 @@
1739 1353 removeSubmitLoading: function( $object, enable, processesRunning ) {
1740 1354 removeSubmitLoading( $object, enable, processesRunning );
1741 1355 },
1742 1356
1743 - scrollToID: function( id ) {
1744 - var object = jQuery( document.getElementById( id ) );
1745 - frmFrontForm.scrollMsg( object, false );
1746 - },
1357 + scrollToID: function( id ) {
1358 + var object = jQuery( document.getElementById( id ) );
1359 + frmFrontForm.scrollMsg( object, false );
1360 + },
1747 1361
1748 1362 scrollMsg: function( id, object, animate ) {
1749 1363 var newPos, m, b, screenTop, screenBottom,
1750 1364 scrollObj = '';
@@ -1760,12 +1374,12 @@
1760 1374 }
1761 1375
1762 1376 jQuery( scrollObj ).trigger( 'focus' );
1763 1377 newPos = scrollObj.offset().top;
1764 - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase
1378 + if ( ! newPos || frm_js.offset === '-1' ) {
1765 1379 return;
1766 1380 }
1767 - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase
1381 + newPos = newPos - frm_js.offset;
1768 1382
1769 1383 m = jQuery( 'html' ).css( 'margin-top' );
1770 1384 b = jQuery( 'body' ).css( 'margin-top' );
1771 1385 if ( m || b ) {
@@ -1868,11 +1482,9 @@
1868 1482 },
1869 1483
1870 1484 visible: function( classes ) {
1871 1485 jQuery( classes ).css( 'visibility', 'visible' );
1872 - },
1873 -
1874 - triggerCustomEvent: triggerCustomEvent
1486 + }
1875 1487 };
1876 1488 }
1877 1489 frmFrontForm = frmFrontFormJS();
1878 1490
@@ -1895,15 +1507,15 @@
1895 1507 function frmUpdateField( entryId, fieldId, value, message, num ) {
1896 1508 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
1897 1509 jQuery.ajax({
1898 1510 type: 'POST',
1899 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1511 + url: frm_js.ajax_url,
1900 1512 data: {
1901 1513 action: 'frm_entries_update_field_ajax',
1902 1514 entry_id: entryId,
1903 1515 field_id: fieldId,
1904 1516 value: value,
1905 - nonce: frm_js.nonce // eslint-disable-line camelcase
1517 + nonce: frm_js.nonce
1906 1518 },
1907 1519 success: function() {
1908 1520 if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
1909 1521 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' );
@@ -1918,13 +1530,13 @@
1918 1530 console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' );
1919 1531 jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
1920 1532 jQuery.ajax({
1921 1533 type: 'POST',
1922 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1534 + url: frm_js.ajax_url,
1923 1535 data: {
1924 1536 action: 'frm_entries_destroy',
1925 1537 entry: entryId,
1926 - nonce: frm_js.nonce // eslint-disable-line camelcase
1538 + nonce: frm_js.nonce
1927 1539 },
1928 1540 success: function( html ) {
1929 1541 if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
1930 1542 jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' );
@@ -1945,14 +1557,14 @@
1945 1557 console.warn( 'DEPRECATED: function frm_resend_email in v2.0' );
1946 1558 $link.append( '<span class="spinner" style="display:inline"></span>' );
1947 1559 jQuery.ajax({
1948 1560 type: 'POST',
1949 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1561 + url: frm_js.ajax_url,
1950 1562 data: {
1951 1563 action: 'frm_entries_send_email',
1952 1564 entry_id: entryId,
1953 1565 form_id: formId,
1954 - nonce: frm_js.nonce // eslint-disable-line camelcase
1566 + nonce: frm_js.nonce
1955 1567 },
1956 1568 success: function( msg ) {
1957 1569 $link.replaceWith( msg );
1958 1570 }