PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.14
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 +214 -566 6.4.2 → 5.0.14 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
@@ -222,10 +171,23 @@
222 171 fields = jQuery( object ).find( 'input,select,textarea' );
223 172 if ( fields.length ) {
224 173 for ( n = 0, nl = fields.length; n < nl; n++ ) {
225 174 field = fields[n];
226 - if ( '' !== field.value ) {
227 - validateFieldValue( 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 );
189 + }
228 190 }
229 191 }
230 192 }
231 193
@@ -272,9 +234,19 @@
272 234 errors = checkRequiredField( field, errors );
273 235 }
274 236
275 237 if ( errors.length < 1 ) {
276 - 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 + }
277 249 }
278 250
279 251 removeFieldError( $fieldCont );
280 252 if ( Object.keys( errors ).length > 0 ) {
@@ -283,29 +255,8 @@
283 255 }
284 256 }
285 257 }
286 258
287 - function validateFieldValue( field, errors ) {
288 - if ( field.type === 'hidden' ) {
289 - // don't validate
290 - } else if ( field.type === 'number' ) {
291 - checkNumberField( field, errors );
292 - } else if ( field.type === 'email' ) {
293 - checkEmailField( field, errors );
294 - } else if ( field.type === 'password' ) {
295 - checkPasswordField( field, errors );
296 - } else if ( field.type === 'url' ) {
297 - checkUrlField( field, errors );
298 - } else if ( field.pattern !== null ) {
299 - checkPatternField( field, errors );
300 - }
301 -
302 - triggerCustomEvent( document, 'frm_validate_field_value', {
303 - field: field,
304 - errors: errors
305 - });
306 - }
307 -
308 259 function checkRequiredField( field, errors ) {
309 260 var checkGroup, tempVal, i, placeholder,
310 261 val = '',
311 262 fieldID = '',
@@ -310,9 +261,9 @@
310 261 val = '',
311 262 fieldID = '',
312 263 fileID = field.getAttribute( 'data-frmfile' );
313 264
314 - if ( field.type === 'hidden' && fileID === null && ! isAppointmentField( field ) && ! isInlineDatepickerField( field ) ) {
265 + if ( field.type === 'hidden' && fileID === null && ! hasClass( field, 'ssa_appointment_form_field_appointment_id' ) ) {
315 266 return errors;
316 267 }
317 268
318 269 if ( field.type === 'checkbox' || field.type === 'radio' ) {
@@ -391,16 +342,8 @@
391 342 var name = field.getAttribute( 'name' );
392 343 return 'string' === typeof name && '[typed]' === name.substr( -7 );
393 344 }
394 345
395 - function isAppointmentField( field ) {
396 - return hasClass( field, 'ssa_appointment_form_field_appointment_id' );
397 - }
398 -
399 - function isInlineDatepickerField( field ) {
400 - return 'hidden' === field.type && '_alt' === field.id.substr( -4 ) && hasClass( field.nextElementSibling, 'frm_date_inline' );
401 - }
402 -
403 346 function getFileVals( fileID ) {
404 347 var val = '',
405 348 fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' );
406 349
@@ -421,8 +364,9 @@
421 364 if ( ! ( fieldID in errors ) ) {
422 365 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
423 366 }
424 367 }
368 + return errors;
425 369 }
426 370
427 371 function checkEmailField( field, errors ) {
428 372 var fieldID = getFieldId( field, true ),
@@ -433,12 +377,14 @@
433 377 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
434 378 }
435 379
436 380 confirmField( field, errors );
381 + return errors;
437 382 }
438 383
439 384 function checkPasswordField( field, errors ) {
440 385 confirmField( field, errors );
386 + return errors;
441 387 }
442 388
443 389 function confirmField( field, errors ) {
444 390 var value, confirmValue, firstField,
@@ -472,8 +418,9 @@
472 418 if ( ! ( fieldID in errors ) ) {
473 419 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
474 420 }
475 421 }
422 + return errors;
476 423 }
477 424
478 425 function checkPatternField( field, errors ) {
479 426 var fieldID,
@@ -488,8 +435,9 @@
488 435 errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' );
489 436 }
490 437 }
491 438 }
439 + return errors;
492 440 }
493 441
494 442 function hasInvisibleRecaptcha( object ) {
495 443 var recaptcha, recaptchaID, alreadyChecked;
@@ -576,9 +524,9 @@
576 524 return validate;
577 525 }
578 526
579 527 function getFormErrors( object, action ) {
580 - var fieldset, data, success, error, shouldTriggerEvent;
528 + var fieldset;
581 529
582 530 if ( typeof action === 'undefined' ) {
583 531 jQuery( object ).find( 'input[name="frm_action"]' ).val();
584 532 }
@@ -584,204 +532,145 @@
584 532 }
585 533
586 534 fieldset = jQuery( object ).find( '.frm_form_field' );
587 535 fieldset.addClass( 'frm_doing_ajax' );
536 + jQuery.ajax({
537 + type: 'POST', url: frm_js.ajax_url,
538 + data: jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce,
539 + success: function( response ) {
540 + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
541 + $fieldCont, key, inCollapsedSection, frmTrigger,
542 + defaultResponse = { 'content': '', 'errors': {}, 'pass': false };
543 + if ( response === null ) {
544 + response = defaultResponse;
545 + }
588 546
589 - data = jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce; // eslint-disable-line camelcase
590 - shouldTriggerEvent = object.classList.contains( 'frm_trigger_event_on_submit' );
591 -
592 - success = function( response ) {
593 - var defaultResponse, formID, replaceContent, pageOrder, formReturned, contSubmit, delay,
594 - $fieldCont, key, inCollapsedSection, frmTrigger, newTab;
595 -
596 - defaultResponse = {
597 - content: '',
598 - errors: {},
599 - pass: false
600 - };
601 -
602 - if ( response === null ) {
603 - response = defaultResponse;
604 - }
605 -
606 - response = response.replace( /^\s+|\s+$/g, '' );
607 - if ( response.indexOf( '{' ) === 0 ) {
608 - response = JSON.parse( response );
609 - } else {
610 - response = defaultResponse;
611 - }
612 -
613 - if ( typeof response.redirect !== 'undefined' ) {
614 - if ( shouldTriggerEvent ) {
615 - triggerCustomEvent( object, 'frmSubmitEvent' );
616 - return;
547 + response = response.replace( /^\s+|\s+$/g, '' );
548 + if ( response.indexOf( '{' ) === 0 ) {
549 + response = JSON.parse( response );
550 + } else {
551 + response = defaultResponse;
617 552 }
618 553
619 - jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
620 -
621 - if ( ! response.openInNewTab ) {
622 - // We return here because we're redirecting there is no need to update content.
554 + if ( typeof response.redirect !== 'undefined' ) {
555 + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]);
623 556 window.location = response.redirect;
624 - return;
625 - }
557 + } else if ( response.content !== '' ) {
558 + // the form or success message was returned
626 559
627 - // We don't return here because we're opening in a new tab, the old tab will still update.
628 - newTab = window.open( response.redirect, '_blank' );
629 - if ( ! newTab && response.fallbackMsg && response.content ) {
630 - response.content = response.content.trim().replace( /(<\/div><\/div>)$/, ' ' + response.fallbackMsg + '</div></div>' );
631 - }
632 - }
560 + removeSubmitLoading( jQuery( object ) );
561 + if ( frm_js.offset != -1 ) {
562 + frmFrontForm.scrollMsg( jQuery( object ), false );
563 + }
564 + formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
565 + response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
566 + replaceContent = jQuery( object ).closest( '.frm_forms' );
567 + removeAddedScripts( replaceContent, formID );
568 + delay = maybeSlideOut( replaceContent, response.content );
633 569
634 - if ( response.content !== '' ) {
635 - // the form or success message was returned
570 + setTimeout(
571 + function() {
572 + var container, input, previousInput;
636 573
637 - if ( shouldTriggerEvent ) {
638 - triggerCustomEvent( object, 'frmSubmitEvent' );
639 - return;
640 - }
574 + replaceContent.replaceWith( response.content );
641 575
642 - removeSubmitLoading( jQuery( object ) );
643 - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase
644 - frmFrontForm.scrollMsg( jQuery( object ), false );
645 - }
576 + addUrlParam( response );
646 577
647 - formID = jQuery( object ).find( 'input[name="form_id"]' ).val();
648 - response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' );
649 - replaceContent = jQuery( object ).closest( '.frm_forms' );
650 - removeAddedScripts( replaceContent, formID );
651 - delay = maybeSlideOut( replaceContent, response.content );
578 + if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
579 + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
580 + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
581 + frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
582 + }
652 583
653 - setTimeout(
654 - function() {
655 - var container, input, previousInput;
584 + if ( typeof response.recaptcha !== 'undefined' ) {
585 + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' );
586 + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">';
587 + previousInput = container.find( 'input[name="recaptcha_checked"]' );
656 588
657 - replaceContent.replaceWith( response.content );
589 + if ( previousInput.length ) {
590 + previousInput.replaceWith( input );
591 + } else {
592 + container.append( input );
593 + }
594 + }
658 595
659 - addUrlParam( response );
596 + afterFormSubmitted( object, response );
597 + },
598 + delay
599 + );
600 + } else if ( Object.keys( response.errors ).length ) {
601 + // errors were returned
660 602
661 - if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase
662 - pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val();
663 - formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val();
664 - frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object );
665 - }
603 + removeSubmitLoading( jQuery( object ), 'enable' );
666 604
667 - if ( typeof response.recaptcha !== 'undefined' ) {
668 - container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' );
669 - input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">';
670 - previousInput = container.find( 'input[name="recaptcha_checked"]' );
605 + //show errors
606 + contSubmit = true;
607 + removeAllErrors();
671 608
672 - if ( previousInput.length ) {
673 - previousInput.replaceWith( input );
674 - } else {
675 - container.append( input );
676 - }
677 - }
609 + $fieldCont = null;
678 610
679 - afterFormSubmitted( object, response );
680 - },
681 - delay
682 - );
683 - } else if ( Object.keys( response.errors ).length ) {
684 - // errors were returned
685 - removeSubmitLoading( jQuery( object ), 'enable' );
611 + for ( key in response.errors ) {
612 + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
686 613
687 - //show errors
688 - contSubmit = true;
689 - removeAllErrors();
690 -
691 - $fieldCont = null;
692 -
693 - for ( key in response.errors ) {
694 - $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' );
695 -
696 - if ( $fieldCont.length ) {
697 - if ( ! $fieldCont.is( ':visible' ) ) {
698 - inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
699 - if ( inCollapsedSection.length ) {
700 - frmTrigger = inCollapsedSection.prev();
701 - if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
702 - // If the frmTrigger object is the section description, check to see if the previous element is the trigger
703 - frmTrigger = frmTrigger.prev( '.frm_trigger' );
614 + if ( $fieldCont.length ) {
615 + if ( ! $fieldCont.is( ':visible' ) ) {
616 + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' );
617 + if ( inCollapsedSection.length ) {
618 + frmTrigger = inCollapsedSection.prev();
619 + if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) {
620 + // If the frmTrigger object is the section description, check to see if the previous element is the trigger
621 + frmTrigger = frmTrigger.prev( '.frm_trigger' );
622 + }
623 + frmTrigger.trigger( 'click' );
704 624 }
705 - frmTrigger.trigger( 'click' );
706 625 }
707 - }
708 626
709 - if ( $fieldCont.is( ':visible' ) ) {
710 - addFieldError( $fieldCont, key, response.errors );
711 - contSubmit = false;
627 + if ( $fieldCont.is( ':visible' ) ) {
628 + addFieldError( $fieldCont, key, response.errors );
629 + contSubmit = false;
630 + }
712 631 }
713 632 }
714 - }
715 633
716 - jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() {
717 - var $recaptcha = jQuery( this ),
718 - recaptchaID = $recaptcha.data( 'rid' );
634 + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() {
635 + var $recaptcha = jQuery( this ),
636 + recaptchaID = $recaptcha.data( 'rid' );
719 637
720 - if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
721 - if ( recaptchaID ) {
722 - grecaptcha.reset( recaptchaID );
723 - } else {
724 - grecaptcha.reset();
638 + if ( typeof grecaptcha !== 'undefined' && grecaptcha ) {
639 + if ( recaptchaID ) {
640 + grecaptcha.reset( recaptchaID );
641 + } else {
642 + grecaptcha.reset();
643 + }
725 644 }
726 - }
727 - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) {
728 - hcaptcha.reset();
729 - }
730 - });
645 + });
731 646
732 - jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
647 + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]);
733 648
734 - fieldset.removeClass( 'frm_doing_ajax' );
735 - scrollToFirstField( object );
649 + fieldset.removeClass( 'frm_doing_ajax' );
650 + scrollToFirstField( object );
736 651
737 - if ( contSubmit ) {
738 - object.submit();
652 + if ( contSubmit ) {
653 + object.submit();
654 + } else {
655 + jQuery( object ).prepend( response.error_message );
656 + checkForErrorsAndMaybeSetFocus();
657 + }
739 658 } else {
740 - jQuery( object ).prepend( response.error_message );
741 - checkForErrorsAndMaybeSetFocus();
742 - }
743 - } else {
744 - // there may have been a plugin conflict, or the form is not set to submit with ajax
659 + // there may have been a plugin conflict, or the form is not set to submit with ajax
745 660
746 - showFileLoading( object );
661 + showFileLoading( object );
747 662
663 + object.submit();
664 + }
665 + },
666 + error: function() {
667 + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
748 668 object.submit();
749 669 }
750 - };
751 -
752 - error = function() {
753 - jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false );
754 - object.submit();
755 - };
756 -
757 - postToAjaxUrl( object, data, success, error );
670 + });
758 671 }
759 672
760 - function postToAjaxUrl( form, data, success, error ) {
761 - var ajaxUrl, action, ajaxParams;
762 -
763 - ajaxUrl = frm_js.ajax_url; // eslint-disable-line camelcase
764 - action = form.getAttribute( 'action' );
765 -
766 - if ( 'string' === typeof action && -1 !== action.indexOf( '?action=frm_forms_preview' ) ) {
767 - ajaxUrl = action.split( '?action=frm_forms_preview' )[0];
768 - }
769 -
770 - ajaxParams = {
771 - type: 'POST',
772 - url: ajaxUrl,
773 - data: data,
774 - success: success
775 - };
776 -
777 - if ( 'function' === typeof error ) {
778 - ajaxParams.error = error;
779 - }
780 -
781 - jQuery.ajax( ajaxParams );
782 - }
783 -
784 673 function afterFormSubmitted( object, response ) {
785 674 var formCompleted = jQuery( response.content ).find( '.frm_message' );
786 675 if ( formCompleted.length ) {
787 676 jQuery( document ).trigger( 'frmFormComplete', [ object, response ]);
@@ -847,9 +736,9 @@
847 736 return kvp.join( '&' );
848 737 }
849 738
850 739 function addFieldError( $fieldCont, key, jsErrors ) {
851 - var input, id, describedBy, roleString;
740 + var input, id, describedBy;
852 741 if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) {
853 742 $fieldCont.addClass( 'frm_blank_field' );
854 743 input = $fieldCont.find( 'input, select, textarea' );
855 744 id = 'frm_error_field_' + key;
@@ -862,22 +751,16 @@
862 751 $fieldCont.append(
863 752 jsErrors[key]
864 753 );
865 754 } else {
866 - roleString = frm_js.include_alert_role ? 'role="alert"' : ''; // eslint-disable-line camelcase
867 - $fieldCont.append( '<div class="frm_error" ' + roleString + ' id="' + id + '">' + jsErrors[key] + '</div>' );
755 + $fieldCont.append( '<div class="frm_error" id="' + id + '">' + jsErrors[key] + '</div>' );
868 756 }
869 757
870 758 if ( typeof describedBy === 'undefined' ) {
871 759 describedBy = id;
872 - } else if ( describedBy.indexOf( id ) === -1 && describedBy.indexOf( 'frm_error_field_' ) === -1 ) {
873 - if ( input.data( 'error-first' ) === 0 ) {
874 - describedBy = describedBy + ' ' + id;
875 - } else {
876 - describedBy = id + ' ' + describedBy;
877 - }
760 + } else if ( describedBy.indexOf( id ) === -1 ) {
761 + describedBy = describedBy + ' ' + id;
878 762 }
879 -
880 763 input.attr( 'aria-describedby', describedBy );
881 764 }
882 765 input.attr( 'aria-invalid', true );
883 766
@@ -893,9 +776,8 @@
893 776
894 777 $fieldCont.removeClass( 'frm_blank_field has-error' );
895 778 errorMessage.remove();
896 779 input.attr( 'aria-invalid', false );
897 - input.removeAttr( 'aria-describedby' );
898 780
899 781 if ( typeof describedBy !== 'undefined' ) {
900 782 describedBy = describedBy.replace( errorId, '' );
901 783 input.attr( 'aria-describedby', describedBy );
@@ -1010,14 +892,14 @@
1010 892 label.append( '<span class="frm-wait"></span>' );
1011 893
1012 894 jQuery.ajax({
1013 895 type: 'POST',
1014 - url: frm_js.ajax_url, // eslint-disable-line camelcase
896 + url: frm_js.ajax_url,
1015 897 data: {
1016 898 action: 'frm_entries_send_email',
1017 899 entry_id: entryId,
1018 900 form_id: formId,
1019 - nonce: frm_js.nonce // eslint-disable-line camelcase
901 + nonce: frm_js.nonce
1020 902 },
1021 903 success: function( msg ) {
1022 904 var admin = document.getElementById( 'wpbody' );
1023 905 if ( admin === null ) {
@@ -1055,9 +937,32 @@
1055 937 /**********************************************
1056 938 * Fallback functions
1057 939 *********************************************/
1058 940
1059 - function addTrimFallbackForIE() {
941 + function addIndexOfFallbackForIE8() {
942 + var len, from;
943 +
944 + if ( ! Array.prototype.indexOf ) {
945 + Array.prototype.indexOf = function( elt /*, from*/ ) {
946 + len = this.length >>> 0;
947 +
948 + from = Number( arguments[1]) || 0;
949 + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from );
950 + if ( from < 0 ) {
951 + from += len;
952 + }
953 +
954 + for ( ; from < len; from++ ) {
955 + if ( from in this && this[from] === elt ) {
956 + return from;
957 + }
958 + }
959 + return -1;
960 + };
961 + }
962 + }
963 +
964 + function addTrimFallbackForIE8() {
1060 965 if ( typeof String.prototype.trim !== 'function' ) {
1061 966 String.prototype.trim = function() {
1062 967 return this.replace( /^\s+|\s+$/g, '' );
1063 968 };
@@ -1063,9 +968,9 @@
1063 968 };
1064 969 }
1065 970 }
1066 971
1067 - function addFilterFallbackForIE() {
972 + function addFilterFallbackForIE8() {
1068 973 var t, len, res, thisp, i, val;
1069 974
1070 975 if ( ! Array.prototype.filter ) {
1071 976
@@ -1096,8 +1001,26 @@
1096 1001 };
1097 1002 }
1098 1003 }
1099 1004
1005 + function addKeysFallbackForIE8() {
1006 + var keys, i;
1007 +
1008 + if ( ! Object.keys ) {
1009 + Object.keys = function( obj ) {
1010 + keys = [];
1011 +
1012 + for ( i in obj ) {
1013 + if ( obj.hasOwnProperty( i ) ) {
1014 + keys.push( i );
1015 + }
1016 + }
1017 +
1018 + return keys;
1019 + };
1020 + }
1021 + }
1022 +
1100 1023 /**
1101 1024 * Check for -webkit-box-shadow css value for input:-webkit-autofill selector.
1102 1025 * If this is a match, the User is autofilling the input on a Webkit browser.
1103 1026 * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete.
@@ -1108,38 +1031,8 @@
1108 1031 this.parentNode.removeChild( this );
1109 1032 }
1110 1033 }
1111 1034
1112 - function maybeMakeHoneypotFieldsUntabbable() {
1113 - document.addEventListener( 'keydown', handleKeyUp );
1114 -
1115 - function handleKeyUp( event ) {
1116 - var code;
1117 -
1118 - if ( 'undefined' !== typeof event.key ) {
1119 - code = event.key;
1120 - } else if ( 'undefined' !== typeof event.keyCode && 9 === event.keyCode ) {
1121 - code = 'Tab';
1122 - }
1123 -
1124 - if ( 'Tab' === code ) {
1125 - makeHoneypotFieldsUntabbable();
1126 - document.removeEventListener( 'keydown', handleKeyUp );
1127 - }
1128 - }
1129 -
1130 - function makeHoneypotFieldsUntabbable() {
1131 - document.querySelectorAll( '.frm_verify' ).forEach(
1132 - function( wrapper ) {
1133 - var input = wrapper.querySelector( 'input[id^=frm_email]' );
1134 - if ( input ) {
1135 - input.setAttribute( 'tabindex', -1 );
1136 - }
1137 - }
1138 - );
1139 - }
1140 - }
1141 -
1142 1035 /**
1143 1036 * Focus on the first sub field when clicking to the primary label of combo field.
1144 1037 *
1145 1038 * @since 4.10.02
@@ -1144,11 +1037,11 @@
1144 1037 *
1145 1038 * @since 4.10.02
1146 1039 */
1147 1040 function changeFocusWhenClickComboFieldLabel() {
1148 - var label;
1041 + let label;
1149 1042
1150 - var comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1043 + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' );
1151 1044 comboInputsContainer.forEach( function( inputsContainer ) {
1152 1045 if ( ! inputsContainer.closest( '.frm_form_field' ) ) {
1153 1046 return;
1154 1047 }
@@ -1166,12 +1059,8 @@
1166 1059
1167 1060 function checkForErrorsAndMaybeSetFocus() {
1168 1061 var errors, element, timeoutCallback;
1169 1062
1170 - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase
1171 - return;
1172 - }
1173 -
1174 1063 errors = document.querySelectorAll( '.frm_form_field .frm_error' );
1175 1064 if ( ! errors.length ) {
1176 1065 return;
1177 1066 }
@@ -1205,246 +1094,10 @@
1205 1094 }
1206 1095 } while ( element.previousSibling );
1207 1096 }
1208 1097
1209 - /**
1210 - * Checks if is on IE browser.
1211 - *
1212 - * @since 5.4
1213 - *
1214 - * @return {Boolean}
1215 - */
1216 - function isIE() {
1217 - return navigator.userAgent.indexOf( 'MSIE' ) > -1 || navigator.userAgent.indexOf( 'Trident' ) > -1;
1218 - }
1219 -
1220 - /**
1221 - * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
1222 - *
1223 - * @since 5.4
1224 - *
1225 - * @param {String} event Event name.
1226 - * @param {String} selector Selector.
1227 - * @param {Function} handler Handler.
1228 - * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`.
1229 - */
1230 - function documentOn( event, selector, handler, options ) {
1231 - if ( 'undefined' === typeof options ) {
1232 - options = false;
1233 - }
1234 -
1235 - document.addEventListener( event, function( e ) {
1236 - var target;
1237 -
1238 - // loop parent nodes from the target to the delegation node.
1239 - for ( target = e.target; target && target != this; target = target.parentNode ) {
1240 - if ( target && target.matches && target.matches( selector ) ) {
1241 - handler.call( target, e );
1242 - break;
1243 - }
1244 - }
1245 - }, options );
1246 - }
1247 -
1248 - function initFloatingLabels() {
1249 - var checkFloatLabel, checkDropdownLabel, checkPlaceholderIE, runOnLoad, selector, floatClass;
1250 -
1251 - selector = '.frm-show-form .frm_inside_container input, .frm-show-form .frm_inside_container select, .frm-show-form .frm_inside_container textarea';
1252 - floatClass = 'frm_label_float_top';
1253 -
1254 - checkFloatLabel = function( input ) {
1255 - var container, shouldFloatTop, firstOpt;
1256 -
1257 - container = input.closest( '.frm_inside_container' );
1258 - if ( ! container ) {
1259 - return;
1260 - }
1261 -
1262 - shouldFloatTop = input.value || document.activeElement === input;
1263 -
1264 - container.classList.toggle( floatClass, shouldFloatTop );
1265 -
1266 - if ( 'SELECT' === input.tagName ) {
1267 - firstOpt = input.querySelector( 'option:first-child' );
1268 -
1269 - if ( shouldFloatTop ) {
1270 - if ( firstOpt.hasAttribute( 'data-label' ) ) {
1271 - firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
1272 - firstOpt.removeAttribute( 'data-label' );
1273 - }
1274 - } else {
1275 - if ( firstOpt.textContent ) {
1276 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1277 - firstOpt.textContent = '';
1278 - }
1279 - }
1280 - } else if ( isIE() ) {
1281 - checkPlaceholderIE( input );
1282 - }
1283 - };
1284 -
1285 - checkDropdownLabel = function() {
1286 - document.querySelectorAll( '.frm-show-form .frm_inside_container:not(.' + floatClass + ') select' ).forEach( function( input ) {
1287 - var firstOpt = input.querySelector( 'option:first-child' );
1288 -
1289 - if ( firstOpt.textContent ) {
1290 - firstOpt.setAttribute( 'data-label', firstOpt.textContent );
1291 - firstOpt.textContent = '';
1292 - }
1293 - });
1294 - };
1295 -
1296 - checkPlaceholderIE = function( input ) {
1297 - if ( input.value ) {
1298 - // Don't need to handle this case because placeholder isn't shown.
1299 - return;
1300 - }
1301 -
1302 - if ( document.activeElement === input ) {
1303 - if ( input.hasAttribute( 'data-placeholder' ) ) {
1304 - input.placeholder = input.getAttribute( 'data-placeholder' );
1305 - input.removeAttribute( 'data-placeholder' );
1306 - }
1307 - } else {
1308 - if ( input.placeholder ) {
1309 - input.setAttribute( 'data-placeholder', input.placeholder );
1310 - input.placeholder = '';
1311 - }
1312 - }
1313 - };
1314 -
1315 - [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
1316 - documentOn(
1317 - eventName,
1318 - selector,
1319 - function( event ) {
1320 - checkFloatLabel( event.target );
1321 - },
1322 - true
1323 - );
1324 - });
1325 -
1326 - jQuery( document ).on( 'change', selector, function( event ) {
1327 - checkFloatLabel( event.target );
1328 - });
1329 -
1330 - runOnLoad = function( firstLoad ) {
1331 - if ( firstLoad && document.activeElement && -1 !== [ 'INPUT', 'SELECT', 'TEXTAREA' ].indexOf( document.activeElement.tagName ) ) {
1332 - checkFloatLabel( document.activeElement );
1333 - } else if ( firstLoad ) {
1334 - document.querySelectorAll( '.frm_inside_container' ).forEach(
1335 - function( container ) {
1336 - var input = container.querySelector( 'input, select, textarea' );
1337 - if ( input && '' !== input.value ) {
1338 - checkFloatLabel( input );
1339 - }
1340 - }
1341 - );
1342 - }
1343 -
1344 - checkDropdownLabel();
1345 -
1346 - if ( isIE() ) {
1347 - document.querySelectorAll( selector ).forEach( function( input ) {
1348 - checkPlaceholderIE( input );
1349 - });
1350 - }
1351 - };
1352 -
1353 - runOnLoad( true );
1354 -
1355 - jQuery( document ).on( 'frmPageChanged', function( event ) {
1356 - runOnLoad();
1357 - });
1358 -
1359 - document.addEventListener( 'frm_after_start_over', function( event ) {
1360 - runOnLoad();
1361 - });
1362 - }
1363 -
1364 - function shouldUpdateValidityMessage( target ) {
1365 - if ( 'INPUT' !== target.nodeName ) {
1366 - return false;
1367 - }
1368 -
1369 - if ( ! target.dataset.invmsg ) {
1370 - return false;
1371 - }
1372 -
1373 - if ( 'text' !== target.getAttribute( 'type' ) ) {
1374 - return false;
1375 - }
1376 -
1377 - if ( target.classList.contains( 'frm_verify' ) ) {
1378 - return false;
1379 - }
1380 -
1381 - return true;
1382 - }
1383 -
1384 - function maybeClearCustomValidityMessage( event, field ) {
1385 - var key,
1386 - isInvalid = false;
1387 -
1388 - if ( ! shouldUpdateValidityMessage( field ) ) {
1389 - return;
1390 - }
1391 -
1392 - for ( key in field.validity ) {
1393 - if ( 'customError' === key ) {
1394 - continue;
1395 - }
1396 - if ( 'valid' !== key && field.validity[ key ] === true ) {
1397 - isInvalid = true;
1398 - break;
1399 - }
1400 - };
1401 -
1402 - if ( ! isInvalid ) {
1403 - field.setCustomValidity( '' );
1404 - }
1405 - }
1406 -
1407 - function maybeShowNewTabFallbackMessage() {
1408 - var messageEl;
1409 -
1410 - if ( ! window.frmShowNewTabFallback ) {
1411 - return;
1412 - }
1413 -
1414 - messageEl = document.querySelector( '#frm_form_' + frmShowNewTabFallback.formId + '_container .frm_message' );
1415 - if ( ! messageEl ) {
1416 - return;
1417 - }
1418 -
1419 - messageEl.insertAdjacentHTML( 'beforeend', ' ' + frmShowNewTabFallback.message );
1420 - }
1421 -
1422 - function setCustomValidityMessage() {
1423 - var forms, length, index;
1424 -
1425 - forms = document.getElementsByClassName( 'frm-show-form' );
1426 - length = forms.length;
1427 -
1428 - for ( index = 0; index < length; ++index ) {
1429 - forms[ index ].addEventListener(
1430 - 'invalid',
1431 - function( event ) {
1432 - var target = event.target;
1433 -
1434 - if ( shouldUpdateValidityMessage( target ) ) {
1435 - target.setCustomValidity( target.dataset.invmsg );
1436 - }
1437 - },
1438 - true
1439 - );
1440 - }
1441 - }
1442 -
1443 1098 return {
1444 1099 init: function() {
1445 - maybeAddPolyfills();
1446 -
1447 1100 jQuery( document ).off( 'submit.formidable', '.frm-show-form' );
1448 1101 jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm );
1449 1102
1450 1103 jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() {
@@ -1459,11 +1112,11 @@
1459 1112
1460 1113 jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail );
1461 1114
1462 1115 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 );
1116 + 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 );
1463 1117
1464 1118 jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange );
1465 - maybeMakeHoneypotFieldsUntabbable();
1466 1119
1467 1120 jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick );
1468 1121 jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv );
1469 1122
@@ -1471,18 +1124,13 @@
1471 1124
1472 1125 // Focus on the first sub field when clicking to the primary label of combo field.
1473 1126 changeFocusWhenClickComboFieldLabel();
1474 1127
1475 - // Add fallbacks for IE.
1476 - addTrimFallbackForIE(); // Trim only works in IE10+.
1477 - addFilterFallbackForIE(); // Filter is not supported in any version of IE.
1478 -
1479 - initFloatingLabels();
1480 - maybeShowNewTabFallbackMessage();
1481 -
1482 - jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
1483 - setCustomValidityMessage();
1484 - jQuery( document ).on( 'frmFieldChanged', maybeClearCustomValidityMessage );
1128 + // Add fallbacks for the beloved IE8
1129 + addIndexOfFallbackForIE8();
1130 + addTrimFallbackForIE8();
1131 + addFilterFallbackForIE8();
1132 + addKeysFallbackForIE8();
1485 1133 },
1486 1134
1487 1135 getFieldId: function( field, fullID ) {
1488 1136 return getFieldId( field, fullID );
@@ -1665,12 +1313,12 @@
1665 1313 removeSubmitLoading: function( $object, enable, processesRunning ) {
1666 1314 removeSubmitLoading( $object, enable, processesRunning );
1667 1315 },
1668 1316
1669 - scrollToID: function( id ) {
1670 - var object = jQuery( document.getElementById( id ) );
1671 - frmFrontForm.scrollMsg( object, false );
1672 - },
1317 + scrollToID: function( id ) {
1318 + var object = jQuery( document.getElementById( id ) );
1319 + frmFrontForm.scrollMsg( object, false );
1320 + },
1673 1321
1674 1322 scrollMsg: function( id, object, animate ) {
1675 1323 var newPos, m, b, screenTop, screenBottom,
1676 1324 scrollObj = '';
@@ -1686,12 +1334,12 @@
1686 1334 }
1687 1335
1688 1336 jQuery( scrollObj ).trigger( 'focus' );
1689 1337 newPos = scrollObj.offset().top;
1690 - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase
1338 + if ( ! newPos || frm_js.offset === '-1' ) {
1691 1339 return;
1692 1340 }
1693 - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase
1341 + newPos = newPos - frm_js.offset;
1694 1342
1695 1343 m = jQuery( 'html' ).css( 'margin-top' );
1696 1344 b = jQuery( 'body' ).css( 'margin-top' );
1697 1345 if ( m || b ) {
@@ -1819,15 +1467,15 @@
1819 1467 function frmUpdateField( entryId, fieldId, value, message, num ) {
1820 1468 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' );
1821 1469 jQuery.ajax({
1822 1470 type: 'POST',
1823 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1471 + url: frm_js.ajax_url,
1824 1472 data: {
1825 1473 action: 'frm_entries_update_field_ajax',
1826 1474 entry_id: entryId,
1827 1475 field_id: fieldId,
1828 1476 value: value,
1829 - nonce: frm_js.nonce // eslint-disable-line camelcase
1477 + nonce: frm_js.nonce
1830 1478 },
1831 1479 success: function() {
1832 1480 if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) {
1833 1481 jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' );
@@ -1842,13 +1490,13 @@
1842 1490 console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' );
1843 1491 jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' );
1844 1492 jQuery.ajax({
1845 1493 type: 'POST',
1846 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1494 + url: frm_js.ajax_url,
1847 1495 data: {
1848 1496 action: 'frm_entries_destroy',
1849 1497 entry: entryId,
1850 - nonce: frm_js.nonce // eslint-disable-line camelcase
1498 + nonce: frm_js.nonce
1851 1499 },
1852 1500 success: function( html ) {
1853 1501 if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) {
1854 1502 jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' );
@@ -1869,14 +1517,14 @@
1869 1517 console.warn( 'DEPRECATED: function frm_resend_email in v2.0' );
1870 1518 $link.append( '<span class="spinner" style="display:inline"></span>' );
1871 1519 jQuery.ajax({
1872 1520 type: 'POST',
1873 - url: frm_js.ajax_url, // eslint-disable-line camelcase
1521 + url: frm_js.ajax_url,
1874 1522 data: {
1875 1523 action: 'frm_entries_send_email',
1876 1524 entry_id: entryId,
1877 1525 form_id: formId,
1878 - nonce: frm_js.nonce // eslint-disable-line camelcase
1526 + nonce: frm_js.nonce
1879 1527 },
1880 1528 success: function( msg ) {
1881 1529 $link.replaceWith( msg );
1882 1530 }