| @@ -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 | |
| @@ -210,12 +159,8 @@ | ||
| 210 | 159 | '.frm_required_field:visible input, .frm_required_field:visible select, .frm_required_field:visible textarea' |
| 211 | 160 | ).filter( ':not(.frm_optional)' ); |
| 212 | 161 | if ( requiredFields.length ) { |
| 213 | 162 | for ( r = 0, rl = requiredFields.length; r < rl; r++ ) { |
| 214 | - if ( hasClass( requiredFields[r], 'ed_button' ) ) { | |
| 215 | - // skip rich text field buttons. | |
| 216 | - continue; | |
| 217 | - } | |
| 218 | 163 | errors = checkRequiredField( requiredFields[r], errors ); |
| 219 | 164 | } |
| 220 | 165 | } |
| 221 | 166 | |
| @@ -222,10 +167,23 @@ | ||
| 222 | 167 | fields = jQuery( object ).find( 'input,select,textarea' ); |
| 223 | 168 | if ( fields.length ) { |
| 224 | 169 | for ( n = 0, nl = fields.length; n < nl; n++ ) { |
| 225 | 170 | field = fields[n]; |
| 226 | - if ( '' !== field.value ) { | |
| 227 | - validateFieldValue( field, errors ); | |
| 171 | + value = field.value; | |
| 172 | + if ( value !== '' ) { | |
| 173 | + if ( field.type === 'hidden' ) { | |
| 174 | + // don't validate | |
| 175 | + } else if ( field.type === 'number' ) { | |
| 176 | + errors = checkNumberField( field, errors ); | |
| 177 | + } else if ( field.type === 'email' ) { | |
| 178 | + errors = checkEmailField( field, errors ); | |
| 179 | + } else if ( field.type === 'password' ) { | |
| 180 | + errors = checkPasswordField( field, errors ); | |
| 181 | + } else if ( field.type === 'url' ) { | |
| 182 | + errors = checkUrlField( field, errors ); | |
| 183 | + } else if ( field.pattern !== null ) { | |
| 184 | + errors = checkPatternField( field, errors ); | |
| 185 | + } | |
| 228 | 186 | } |
| 229 | 187 | } |
| 230 | 188 | } |
| 231 | 189 | |
| @@ -233,26 +191,14 @@ | ||
| 233 | 191 | |
| 234 | 192 | return errors; |
| 235 | 193 | } |
| 236 | 194 | |
| 237 | - /** | |
| 238 | - * @since 5.0.10 | |
| 239 | - * | |
| 240 | - * @param {object} element | |
| 241 | - * @param {string} targetClass | |
| 242 | - * @returns {boolean} | |
| 243 | - */ | |
| 244 | - function hasClass( element, targetClass ) { | |
| 245 | - var className = ' ' + element.className + ' '; | |
| 246 | - return -1 !== className.indexOf( ' ' + targetClass + ' ' ); | |
| 247 | - } | |
| 248 | - | |
| 249 | - function maybeValidateChange( field ) { | |
| 195 | + function maybeValidateChange( fieldId, field ) { | |
| 250 | 196 | if ( field.type === 'url' ) { |
| 251 | 197 | maybeAddHttpToUrl( field ); |
| 252 | 198 | } |
| 253 | 199 | if ( jQuery( field ).closest( 'form' ).hasClass( 'frm_js_validate' ) ) { |
| 254 | - validateField( field ); | |
| 200 | + validateField( fieldId, field ); | |
| 255 | 201 | } |
| 256 | 202 | } |
| 257 | 203 | |
| 258 | 204 | function maybeAddHttpToUrl( field ) { |
| @@ -262,19 +208,29 @@ | ||
| 262 | 208 | field.value = 'http://' + url; |
| 263 | 209 | } |
| 264 | 210 | } |
| 265 | 211 | |
| 266 | - function validateField( field ) { | |
| 212 | + function validateField( fieldId, field ) { | |
| 267 | 213 | var key, |
| 268 | - errors = [], | |
| 269 | - $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 214 | + errors = []; | |
| 270 | 215 | |
| 216 | + var $fieldCont = jQuery( field ).closest( '.frm_form_field' ); | |
| 271 | 217 | if ( $fieldCont.hasClass( 'frm_required_field' ) && ! jQuery( field ).hasClass( 'frm_optional' ) ) { |
| 272 | 218 | errors = checkRequiredField( field, errors ); |
| 273 | 219 | } |
| 274 | 220 | |
| 275 | 221 | if ( errors.length < 1 ) { |
| 276 | - validateFieldValue( field, errors ); | |
| 222 | + if ( field.type === 'email' ) { | |
| 223 | + errors = checkEmailField( field, errors ); | |
| 224 | + } else if ( field.type === 'password' ) { | |
| 225 | + errors = checkPasswordField( field, errors ); | |
| 226 | + } else if ( field.type === 'number' ) { | |
| 227 | + errors = checkNumberField( field, errors ); | |
| 228 | + } else if ( field.type === 'url' ) { | |
| 229 | + errors = checkUrlField( field, errors ); | |
| 230 | + } else if ( field.pattern !== null ) { | |
| 231 | + errors = checkPatternField( field, errors ); | |
| 232 | + } | |
| 277 | 233 | } |
| 278 | 234 | |
| 279 | 235 | removeFieldError( $fieldCont ); |
| 280 | 236 | if ( Object.keys( errors ).length > 0 ) { |
| @@ -283,36 +239,15 @@ | ||
| 283 | 239 | } |
| 284 | 240 | } |
| 285 | 241 | } |
| 286 | 242 | |
| 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 | 243 | function checkRequiredField( field, errors ) { |
| 309 | - var checkGroup, tempVal, i, placeholder, | |
| 244 | + var checkGroup, fieldClasses, tempVal, i, placeholder, | |
| 310 | 245 | val = '', |
| 311 | 246 | fieldID = '', |
| 312 | 247 | fileID = field.getAttribute( 'data-frmfile' ); |
| 313 | 248 | |
| 314 | - if ( field.type === 'hidden' && fileID === null && ! isAppointmentField( field ) && ! isInlineDatepickerField( field ) ) { | |
| 249 | + if ( field.type === 'hidden' && fileID === null ) { | |
| 315 | 250 | return errors; |
| 316 | 251 | } |
| 317 | 252 | |
| 318 | 253 | if ( field.type === 'checkbox' || field.type === 'radio' ) { |
| @@ -330,9 +265,10 @@ | ||
| 330 | 265 | val = getFileVals( fileID ); |
| 331 | 266 | } |
| 332 | 267 | fieldID = fileID; |
| 333 | 268 | } else { |
| 334 | - if ( hasClass( field, 'frm_pos_none' ) ) { | |
| 269 | + fieldClasses = field.className; | |
| 270 | + if ( fieldClasses.indexOf( 'frm_pos_none' ) !== -1 ) { | |
| 335 | 271 | // skip hidden other fields |
| 336 | 272 | return errors; |
| 337 | 273 | } |
| 338 | 274 | |
| @@ -348,26 +284,17 @@ | ||
| 348 | 284 | } |
| 349 | 285 | } |
| 350 | 286 | } |
| 351 | 287 | |
| 352 | - if ( hasClass( field, 'frm_other_input' ) ) { | |
| 288 | + if ( fieldClasses.indexOf( 'frm_other_input' ) === -1 ) { | |
| 289 | + fieldID = getFieldId( field, true ); | |
| 290 | + } else { | |
| 353 | 291 | fieldID = getFieldId( field, false ); |
| 354 | - | |
| 355 | - if ( val === '' ) { | |
| 356 | - field = document.getElementById( field.id.replace( '-otext', '' ) ); | |
| 357 | - } | |
| 358 | - } else { | |
| 359 | - fieldID = getFieldId( field, true ); | |
| 360 | 292 | } |
| 361 | 293 | |
| 362 | - if ( hasClass( field, 'frm_time_select' ) ) { | |
| 294 | + if ( fieldClasses.indexOf( 'frm_time_select' ) !== -1 ) { | |
| 363 | 295 | // set id for time field |
| 364 | 296 | fieldID = fieldID.replace( '-H', '' ).replace( '-m', '' ); |
| 365 | - } else if ( isSignatureField( field ) ) { | |
| 366 | - if ( val === '' ) { | |
| 367 | - val = jQuery( field ).closest( '.frm_form_field' ).find( '[name="' + field.getAttribute( 'name' ).replace( '[typed]', '[output]' ) + '"]' ).val(); | |
| 368 | - } | |
| 369 | - fieldID = fieldID.replace( '-typed', '' ); | |
| 370 | 297 | } |
| 371 | 298 | |
| 372 | 299 | placeholder = field.getAttribute( 'data-frmplaceholder' ); |
| 373 | 300 | if ( placeholder !== null && val === placeholder ) { |
| @@ -386,21 +313,8 @@ | ||
| 386 | 313 | |
| 387 | 314 | return errors; |
| 388 | 315 | } |
| 389 | 316 | |
| 390 | - function isSignatureField( field ) { | |
| 391 | - var name = field.getAttribute( 'name' ); | |
| 392 | - return 'string' === typeof name && '[typed]' === name.substr( -7 ); | |
| 393 | - } | |
| 394 | - | |
| 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 | 317 | function getFileVals( fileID ) { |
| 404 | 318 | var val = '', |
| 405 | 319 | fileFields = jQuery( 'input[name="file' + fileID + '"], input[name="file' + fileID + '[]"], input[name^="item_meta[' + fileID + ']"]' ); |
| 406 | 320 | |
| @@ -421,8 +335,9 @@ | ||
| 421 | 335 | if ( ! ( fieldID in errors ) ) { |
| 422 | 336 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 423 | 337 | } |
| 424 | 338 | } |
| 339 | + return errors; | |
| 425 | 340 | } |
| 426 | 341 | |
| 427 | 342 | function checkEmailField( field, errors ) { |
| 428 | 343 | var fieldID = getFieldId( field, true ), |
| @@ -433,12 +348,14 @@ | ||
| 433 | 348 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 434 | 349 | } |
| 435 | 350 | |
| 436 | 351 | confirmField( field, errors ); |
| 352 | + return errors; | |
| 437 | 353 | } |
| 438 | 354 | |
| 439 | 355 | function checkPasswordField( field, errors ) { |
| 440 | 356 | confirmField( field, errors ); |
| 357 | + return errors; | |
| 441 | 358 | } |
| 442 | 359 | |
| 443 | 360 | function confirmField( field, errors ) { |
| 444 | 361 | var value, confirmValue, firstField, |
| @@ -458,9 +375,9 @@ | ||
| 458 | 375 | if ( '' !== value && '' !== confirmValue && value !== confirmValue ) { |
| 459 | 376 | errors[ 'conf_' + strippedFieldID ] = getFieldValidationMessage( confirmField, 'data-confmsg' ); |
| 460 | 377 | } |
| 461 | 378 | } else { |
| 462 | - validateField( confirmField ); | |
| 379 | + validateField( 'conf_' + strippedFieldID, confirmField ); | |
| 463 | 380 | } |
| 464 | 381 | } |
| 465 | 382 | |
| 466 | 383 | function checkNumberField( field, errors ) { |
| @@ -472,8 +389,9 @@ | ||
| 472 | 389 | if ( ! ( fieldID in errors ) ) { |
| 473 | 390 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 474 | 391 | } |
| 475 | 392 | } |
| 393 | + return errors; | |
| 476 | 394 | } |
| 477 | 395 | |
| 478 | 396 | function checkPatternField( field, errors ) { |
| 479 | 397 | var fieldID, |
| @@ -488,8 +406,9 @@ | ||
| 488 | 406 | errors[ fieldID ] = getFieldValidationMessage( field, 'data-invmsg' ); |
| 489 | 407 | } |
| 490 | 408 | } |
| 491 | 409 | } |
| 410 | + return errors; | |
| 492 | 411 | } |
| 493 | 412 | |
| 494 | 413 | function hasInvisibleRecaptcha( object ) { |
| 495 | 414 | var recaptcha, recaptchaID, alreadyChecked; |
| @@ -543,31 +462,15 @@ | ||
| 543 | 462 | return errors; |
| 544 | 463 | } |
| 545 | 464 | |
| 546 | 465 | function getFieldValidationMessage( field, messageType ) { |
| 547 | - var msg, errorHtml; | |
| 548 | - | |
| 549 | - msg = field.getAttribute( messageType ); | |
| 550 | - if ( null === msg ) { | |
| 466 | + var msg = field.getAttribute( messageType ); | |
| 467 | + if ( msg === null ) { | |
| 551 | 468 | msg = ''; |
| 552 | 469 | } |
| 553 | - | |
| 554 | - if ( '' !== msg && shouldWrapErrorHtmlAroundMessageType( messageType ) ) { | |
| 555 | - errorHtml = field.getAttribute( 'data-error-html' ); | |
| 556 | - if ( null !== errorHtml ) { | |
| 557 | - errorHtml = errorHtml.replace( /\+/g, '%20' ); | |
| 558 | - msg = decodeURIComponent( errorHtml ).replace( '[error]', msg ); | |
| 559 | - msg = msg.replace( '[key]', getFieldId( field, false ) ); | |
| 560 | - } | |
| 561 | - } | |
| 562 | - | |
| 563 | 470 | return msg; |
| 564 | 471 | } |
| 565 | 472 | |
| 566 | - function shouldWrapErrorHtmlAroundMessageType( type ) { | |
| 567 | - return 'pattern' !== type; | |
| 568 | - } | |
| 569 | - | |
| 570 | 473 | function shouldJSValidate( object ) { |
| 571 | 474 | var validate = jQuery( object ).hasClass( 'frm_js_validate' ); |
| 572 | 475 | if ( validate && typeof frmProForm !== 'undefined' && ( frmProForm.savingDraft( object ) || frmProForm.goingToPreviousPage( object ) ) ) { |
| 573 | 476 | validate = false; |
| @@ -576,9 +479,9 @@ | ||
| 576 | 479 | return validate; |
| 577 | 480 | } |
| 578 | 481 | |
| 579 | 482 | function getFormErrors( object, action ) { |
| 580 | - var fieldset, data, success, error, shouldTriggerEvent; | |
| 483 | + var fieldset; | |
| 581 | 484 | |
| 582 | 485 | if ( typeof action === 'undefined' ) { |
| 583 | 486 | jQuery( object ).find( 'input[name="frm_action"]' ).val(); |
| 584 | 487 | } |
| @@ -584,204 +487,145 @@ | ||
| 584 | 487 | } |
| 585 | 488 | |
| 586 | 489 | fieldset = jQuery( object ).find( '.frm_form_field' ); |
| 587 | 490 | fieldset.addClass( 'frm_doing_ajax' ); |
| 491 | + jQuery.ajax({ | |
| 492 | + type: 'POST', url: frm_js.ajax_url, | |
| 493 | + data: jQuery( object ).serialize() + '&action=frm_entries_' + action + '&nonce=' + frm_js.nonce, | |
| 494 | + success: function( response ) { | |
| 495 | + var formID, replaceContent, pageOrder, formReturned, contSubmit, delay, | |
| 496 | + $fieldCont, key, inCollapsedSection, frmTrigger, | |
| 497 | + defaultResponse = { 'content': '', 'errors': {}, 'pass': false }; | |
| 498 | + if ( response === null ) { | |
| 499 | + response = defaultResponse; | |
| 500 | + } | |
| 588 | 501 | |
| 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; | |
| 502 | + response = response.replace( /^\s+|\s+$/g, '' ); | |
| 503 | + if ( response.indexOf( '{' ) === 0 ) { | |
| 504 | + response = JSON.parse( response ); | |
| 505 | + } else { | |
| 506 | + response = defaultResponse; | |
| 617 | 507 | } |
| 618 | 508 | |
| 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. | |
| 509 | + if ( typeof response.redirect !== 'undefined' ) { | |
| 510 | + jQuery( document ).trigger( 'frmBeforeFormRedirect', [ object, response ]); | |
| 623 | 511 | window.location = response.redirect; |
| 624 | - return; | |
| 625 | - } | |
| 512 | + } else if ( response.content !== '' ) { | |
| 513 | + // the form or success message was returned | |
| 626 | 514 | |
| 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 | - } | |
| 515 | + removeSubmitLoading( jQuery( object ) ); | |
| 516 | + if ( frm_js.offset != -1 ) { | |
| 517 | + frmFrontForm.scrollMsg( jQuery( object ), false ); | |
| 518 | + } | |
| 519 | + formID = jQuery( object ).find( 'input[name="form_id"]' ).val(); | |
| 520 | + response.content = response.content.replace( / frm_pro_form /g, ' frm_pro_form frm_no_hide ' ); | |
| 521 | + replaceContent = jQuery( object ).closest( '.frm_forms' ); | |
| 522 | + removeAddedScripts( replaceContent, formID ); | |
| 523 | + delay = maybeSlideOut( replaceContent, response.content ); | |
| 633 | 524 | |
| 634 | - if ( response.content !== '' ) { | |
| 635 | - // the form or success message was returned | |
| 525 | + setTimeout( | |
| 526 | + function() { | |
| 527 | + var container, input, previousInput; | |
| 636 | 528 | |
| 637 | - if ( shouldTriggerEvent ) { | |
| 638 | - triggerCustomEvent( object, 'frmSubmitEvent' ); | |
| 639 | - return; | |
| 640 | - } | |
| 529 | + replaceContent.replaceWith( response.content ); | |
| 641 | 530 | |
| 642 | - removeSubmitLoading( jQuery( object ) ); | |
| 643 | - if ( frm_js.offset != -1 ) { // eslint-disable-line camelcase | |
| 644 | - frmFrontForm.scrollMsg( jQuery( object ), false ); | |
| 645 | - } | |
| 531 | + addUrlParam( response ); | |
| 646 | 532 | |
| 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 ); | |
| 533 | + if ( typeof frmThemeOverride_frmAfterSubmit === 'function' ) { // eslint-disable-line camelcase | |
| 534 | + pageOrder = jQuery( 'input[name="frm_page_order_' + formID + '"]' ).val(); | |
| 535 | + formReturned = jQuery( response.content ).find( 'input[name="form_id"]' ).val(); | |
| 536 | + frmThemeOverride_frmAfterSubmit( formReturned, pageOrder, response.content, object ); | |
| 537 | + } | |
| 652 | 538 | |
| 653 | - setTimeout( | |
| 654 | - function() { | |
| 655 | - var container, input, previousInput; | |
| 539 | + if ( typeof response.recaptcha !== 'undefined' ) { | |
| 540 | + container = jQuery( '#frm_form_' + formID + '_container' ).find( '.frm_fields_container' ); | |
| 541 | + input = '<input type="hidden" name="recaptcha_checked" value="' + response.recaptcha + '">'; | |
| 542 | + previousInput = container.find( 'input[name="recaptcha_checked"]' ); | |
| 656 | 543 | |
| 657 | - replaceContent.replaceWith( response.content ); | |
| 544 | + if ( previousInput.length ) { | |
| 545 | + previousInput.replaceWith( input ); | |
| 546 | + } else { | |
| 547 | + container.append( input ); | |
| 548 | + } | |
| 549 | + } | |
| 658 | 550 | |
| 659 | - addUrlParam( response ); | |
| 551 | + afterFormSubmitted( object, response ); | |
| 552 | + }, | |
| 553 | + delay | |
| 554 | + ); | |
| 555 | + } else if ( Object.keys( response.errors ).length ) { | |
| 556 | + // errors were returned | |
| 660 | 557 | |
| 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 | - } | |
| 558 | + removeSubmitLoading( jQuery( object ), 'enable' ); | |
| 666 | 559 | |
| 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"]' ); | |
| 560 | + //show errors | |
| 561 | + contSubmit = true; | |
| 562 | + removeAllErrors(); | |
| 671 | 563 | |
| 672 | - if ( previousInput.length ) { | |
| 673 | - previousInput.replaceWith( input ); | |
| 674 | - } else { | |
| 675 | - container.append( input ); | |
| 676 | - } | |
| 677 | - } | |
| 564 | + $fieldCont = null; | |
| 678 | 565 | |
| 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' ); | |
| 566 | + for ( key in response.errors ) { | |
| 567 | + $fieldCont = jQuery( object ).find( '#frm_field_' + key + '_container' ); | |
| 686 | 568 | |
| 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' ); | |
| 569 | + if ( $fieldCont.length ) { | |
| 570 | + if ( ! $fieldCont.is( ':visible' ) ) { | |
| 571 | + inCollapsedSection = $fieldCont.closest( '.frm_toggle_container' ); | |
| 572 | + if ( inCollapsedSection.length ) { | |
| 573 | + frmTrigger = inCollapsedSection.prev(); | |
| 574 | + if ( ! frmTrigger.hasClass( 'frm_trigger' ) ) { | |
| 575 | + // If the frmTrigger object is the section description, check to see if the previous element is the trigger | |
| 576 | + frmTrigger = frmTrigger.prev( '.frm_trigger' ); | |
| 577 | + } | |
| 578 | + frmTrigger.trigger( 'click' ); | |
| 704 | 579 | } |
| 705 | - frmTrigger.trigger( 'click' ); | |
| 706 | 580 | } |
| 707 | - } | |
| 708 | 581 | |
| 709 | - if ( $fieldCont.is( ':visible' ) ) { | |
| 710 | - addFieldError( $fieldCont, key, response.errors ); | |
| 711 | - contSubmit = false; | |
| 582 | + if ( $fieldCont.is( ':visible' ) ) { | |
| 583 | + addFieldError( $fieldCont, key, response.errors ); | |
| 584 | + contSubmit = false; | |
| 585 | + } | |
| 712 | 586 | } |
| 713 | 587 | } |
| 714 | - } | |
| 715 | 588 | |
| 716 | - jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha, .h-captcha' ).each( function() { | |
| 717 | - var $recaptcha = jQuery( this ), | |
| 718 | - recaptchaID = $recaptcha.data( 'rid' ); | |
| 589 | + jQuery( object ).find( '.frm-g-recaptcha, .g-recaptcha' ).each( function() { | |
| 590 | + var $recaptcha = jQuery( this ), | |
| 591 | + recaptchaID = $recaptcha.data( 'rid' ); | |
| 719 | 592 | |
| 720 | - if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { | |
| 721 | - if ( recaptchaID ) { | |
| 722 | - grecaptcha.reset( recaptchaID ); | |
| 723 | - } else { | |
| 724 | - grecaptcha.reset(); | |
| 593 | + if ( typeof grecaptcha !== 'undefined' && grecaptcha ) { | |
| 594 | + if ( recaptchaID ) { | |
| 595 | + grecaptcha.reset( recaptchaID ); | |
| 596 | + } else { | |
| 597 | + grecaptcha.reset(); | |
| 598 | + } | |
| 725 | 599 | } |
| 726 | - } | |
| 727 | - if ( typeof hcaptcha !== 'undefined' && hcaptcha ) { | |
| 728 | - hcaptcha.reset(); | |
| 729 | - } | |
| 730 | - }); | |
| 600 | + }); | |
| 731 | 601 | |
| 732 | - jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 602 | + jQuery( document ).trigger( 'frmFormErrors', [ object, response ]); | |
| 733 | 603 | |
| 734 | - fieldset.removeClass( 'frm_doing_ajax' ); | |
| 735 | - scrollToFirstField( object ); | |
| 604 | + fieldset.removeClass( 'frm_doing_ajax' ); | |
| 605 | + scrollToFirstField( object ); | |
| 736 | 606 | |
| 737 | - if ( contSubmit ) { | |
| 738 | - object.submit(); | |
| 607 | + if ( contSubmit ) { | |
| 608 | + object.submit(); | |
| 609 | + } else { | |
| 610 | + jQuery( object ).prepend( response.error_message ); | |
| 611 | + checkForErrorsAndMaybeSetFocus(); | |
| 612 | + } | |
| 739 | 613 | } 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 | |
| 614 | + // there may have been a plugin conflict, or the form is not set to submit with ajax | |
| 745 | 615 | |
| 746 | - showFileLoading( object ); | |
| 616 | + showFileLoading( object ); | |
| 747 | 617 | |
| 618 | + object.submit(); | |
| 619 | + } | |
| 620 | + }, | |
| 621 | + error: function() { | |
| 622 | + jQuery( object ).find( 'input[type="submit"], input[type="button"]' ).prop( 'disabled', false ); | |
| 748 | 623 | object.submit(); |
| 749 | 624 | } |
| 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 ); | |
| 625 | + }); | |
| 758 | 626 | } |
| 759 | 627 | |
| 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 | 628 | function afterFormSubmitted( object, response ) { |
| 785 | 629 | var formCompleted = jQuery( response.content ).find( '.frm_message' ); |
| 786 | 630 | if ( formCompleted.length ) { |
| 787 | 631 | jQuery( document ).trigger( 'frmFormComplete', [ object, response ]); |
| @@ -847,9 +691,9 @@ | ||
| 847 | 691 | return kvp.join( '&' ); |
| 848 | 692 | } |
| 849 | 693 | |
| 850 | 694 | function addFieldError( $fieldCont, key, jsErrors ) { |
| 851 | - var input, id, describedBy, roleString; | |
| 695 | + var input, id, describedBy; | |
| 852 | 696 | if ( $fieldCont.length && $fieldCont.is( ':visible' ) ) { |
| 853 | 697 | $fieldCont.addClass( 'frm_blank_field' ); |
| 854 | 698 | input = $fieldCont.find( 'input, select, textarea' ); |
| 855 | 699 | id = 'frm_error_field_' + key; |
| @@ -857,27 +701,15 @@ | ||
| 857 | 701 | |
| 858 | 702 | if ( typeof frmThemeOverride_frmPlaceError === 'function' ) { // eslint-disable-line camelcase |
| 859 | 703 | frmThemeOverride_frmPlaceError( key, jsErrors ); |
| 860 | 704 | } else { |
| 861 | - if ( -1 !== jsErrors[key].indexOf( '<div' ) ) { | |
| 862 | - $fieldCont.append( | |
| 863 | - jsErrors[key] | |
| 864 | - ); | |
| 865 | - } 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>' ); | |
| 868 | - } | |
| 705 | + $fieldCont.append( '<div class="frm_error" id="' + id + '">' + jsErrors[key] + '</div>' ); | |
| 869 | 706 | |
| 870 | 707 | if ( typeof describedBy === 'undefined' ) { |
| 871 | 708 | 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 | - } | |
| 709 | + } else if ( describedBy.indexOf( id ) === -1 ) { | |
| 710 | + describedBy = describedBy + ' ' + id; | |
| 878 | 711 | } |
| 879 | - | |
| 880 | 712 | input.attr( 'aria-describedby', describedBy ); |
| 881 | 713 | } |
| 882 | 714 | input.attr( 'aria-invalid', true ); |
| 883 | 715 | |
| @@ -893,9 +725,8 @@ | ||
| 893 | 725 | |
| 894 | 726 | $fieldCont.removeClass( 'frm_blank_field has-error' ); |
| 895 | 727 | errorMessage.remove(); |
| 896 | 728 | input.attr( 'aria-invalid', false ); |
| 897 | - input.removeAttr( 'aria-describedby' ); | |
| 898 | 729 | |
| 899 | 730 | if ( typeof describedBy !== 'undefined' ) { |
| 900 | 731 | describedBy = describedBy.replace( errorId, '' ); |
| 901 | 732 | input.attr( 'aria-describedby', describedBy ); |
| @@ -1010,14 +841,14 @@ | ||
| 1010 | 841 | label.append( '<span class="frm-wait"></span>' ); |
| 1011 | 842 | |
| 1012 | 843 | jQuery.ajax({ |
| 1013 | 844 | type: 'POST', |
| 1014 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 845 | + url: frm_js.ajax_url, | |
| 1015 | 846 | data: { |
| 1016 | 847 | action: 'frm_entries_send_email', |
| 1017 | 848 | entry_id: entryId, |
| 1018 | 849 | form_id: formId, |
| 1019 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 850 | + nonce: frm_js.nonce | |
| 1020 | 851 | }, |
| 1021 | 852 | success: function( msg ) { |
| 1022 | 853 | var admin = document.getElementById( 'wpbody' ); |
| 1023 | 854 | if ( admin === null ) { |
| @@ -1055,9 +886,32 @@ | ||
| 1055 | 886 | /********************************************** |
| 1056 | 887 | * Fallback functions |
| 1057 | 888 | *********************************************/ |
| 1058 | 889 | |
| 1059 | - function addTrimFallbackForIE() { | |
| 890 | + function addIndexOfFallbackForIE8() { | |
| 891 | + var len, from; | |
| 892 | + | |
| 893 | + if ( ! Array.prototype.indexOf ) { | |
| 894 | + Array.prototype.indexOf = function( elt /*, from*/ ) { | |
| 895 | + len = this.length >>> 0; | |
| 896 | + | |
| 897 | + from = Number( arguments[1]) || 0; | |
| 898 | + from = ( from < 0 ) ? Math.ceil( from ) : Math.floor( from ); | |
| 899 | + if ( from < 0 ) { | |
| 900 | + from += len; | |
| 901 | + } | |
| 902 | + | |
| 903 | + for ( ; from < len; from++ ) { | |
| 904 | + if ( from in this && this[from] === elt ) { | |
| 905 | + return from; | |
| 906 | + } | |
| 907 | + } | |
| 908 | + return -1; | |
| 909 | + }; | |
| 910 | + } | |
| 911 | + } | |
| 912 | + | |
| 913 | + function addTrimFallbackForIE8() { | |
| 1060 | 914 | if ( typeof String.prototype.trim !== 'function' ) { |
| 1061 | 915 | String.prototype.trim = function() { |
| 1062 | 916 | return this.replace( /^\s+|\s+$/g, '' ); |
| 1063 | 917 | }; |
| @@ -1063,9 +917,9 @@ | ||
| 1063 | 917 | }; |
| 1064 | 918 | } |
| 1065 | 919 | } |
| 1066 | 920 | |
| 1067 | - function addFilterFallbackForIE() { | |
| 921 | + function addFilterFallbackForIE8() { | |
| 1068 | 922 | var t, len, res, thisp, i, val; |
| 1069 | 923 | |
| 1070 | 924 | if ( ! Array.prototype.filter ) { |
| 1071 | 925 | |
| @@ -1096,8 +950,26 @@ | ||
| 1096 | 950 | }; |
| 1097 | 951 | } |
| 1098 | 952 | } |
| 1099 | 953 | |
| 954 | + function addKeysFallbackForIE8() { | |
| 955 | + var keys, i; | |
| 956 | + | |
| 957 | + if ( ! Object.keys ) { | |
| 958 | + Object.keys = function( obj ) { | |
| 959 | + keys = []; | |
| 960 | + | |
| 961 | + for ( i in obj ) { | |
| 962 | + if ( obj.hasOwnProperty( i ) ) { | |
| 963 | + keys.push( i ); | |
| 964 | + } | |
| 965 | + } | |
| 966 | + | |
| 967 | + return keys; | |
| 968 | + }; | |
| 969 | + } | |
| 970 | + } | |
| 971 | + | |
| 1100 | 972 | /** |
| 1101 | 973 | * Check for -webkit-box-shadow css value for input:-webkit-autofill selector. |
| 1102 | 974 | * If this is a match, the User is autofilling the input on a Webkit browser. |
| 1103 | 975 | * We want to delete the Honeypot field, otherwise it will get triggered as spam on autocomplete. |
| @@ -1108,38 +980,8 @@ | ||
| 1108 | 980 | this.parentNode.removeChild( this ); |
| 1109 | 981 | } |
| 1110 | 982 | } |
| 1111 | 983 | |
| 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 | 984 | /** |
| 1143 | 985 | * Focus on the first sub field when clicking to the primary label of combo field. |
| 1144 | 986 | * |
| 1145 | 987 | * @since 4.10.02 |
| @@ -1144,11 +986,11 @@ | ||
| 1144 | 986 | * |
| 1145 | 987 | * @since 4.10.02 |
| 1146 | 988 | */ |
| 1147 | 989 | function changeFocusWhenClickComboFieldLabel() { |
| 1148 | - var label; | |
| 990 | + let label; | |
| 1149 | 991 | |
| 1150 | - var comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' ); | |
| 992 | + const comboInputsContainer = document.querySelectorAll( '.frm_combo_inputs_container' ); | |
| 1151 | 993 | comboInputsContainer.forEach( function( inputsContainer ) { |
| 1152 | 994 | if ( ! inputsContainer.closest( '.frm_form_field' ) ) { |
| 1153 | 995 | return; |
| 1154 | 996 | } |
| @@ -1166,12 +1008,8 @@ | ||
| 1166 | 1008 | |
| 1167 | 1009 | function checkForErrorsAndMaybeSetFocus() { |
| 1168 | 1010 | var errors, element, timeoutCallback; |
| 1169 | 1011 | |
| 1170 | - if ( ! frm_js.focus_first_error ) { // eslint-disable-line camelcase | |
| 1171 | - return; | |
| 1172 | - } | |
| 1173 | - | |
| 1174 | 1012 | errors = document.querySelectorAll( '.frm_form_field .frm_error' ); |
| 1175 | 1013 | if ( ! errors.length ) { |
| 1176 | 1014 | return; |
| 1177 | 1015 | } |
| @@ -1205,246 +1043,10 @@ | ||
| 1205 | 1043 | } |
| 1206 | 1044 | } while ( element.previousSibling ); |
| 1207 | 1045 | } |
| 1208 | 1046 | |
| 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 | 1047 | return { |
| 1444 | 1048 | init: function() { |
| 1445 | - maybeAddPolyfills(); | |
| 1446 | - | |
| 1447 | 1049 | jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); |
| 1448 | 1050 | jQuery( document ).on( 'submit.formidable', '.frm-show-form', frmFrontForm.submitForm ); |
| 1449 | 1051 | |
| 1450 | 1052 | jQuery( '.frm-show-form input[onblur], .frm-show-form textarea[onblur]' ).each( function() { |
| @@ -1459,11 +1061,11 @@ | ||
| 1459 | 1061 | |
| 1460 | 1062 | jQuery( document.getElementById( 'frm_resend_email' ) ).on( 'click', resendEmail ); |
| 1461 | 1063 | |
| 1462 | 1064 | 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 ); |
| 1065 | + 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 | 1066 | |
| 1464 | 1067 | jQuery( document ).on( 'change', '[id^=frm_email_]', onHoneypotFieldChange ); |
| 1465 | - maybeMakeHoneypotFieldsUntabbable(); | |
| 1466 | 1068 | |
| 1467 | 1069 | jQuery( document ).on( 'click', 'a[data-frmconfirm]', confirmClick ); |
| 1468 | 1070 | jQuery( 'a[data-frmtoggle]' ).on( 'click', toggleDiv ); |
| 1469 | 1071 | |
| @@ -1471,18 +1073,13 @@ | ||
| 1471 | 1073 | |
| 1472 | 1074 | // Focus on the first sub field when clicking to the primary label of combo field. |
| 1473 | 1075 | changeFocusWhenClickComboFieldLabel(); |
| 1474 | 1076 | |
| 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 ); | |
| 1077 | + // Add fallbacks for the beloved IE8 | |
| 1078 | + addIndexOfFallbackForIE8(); | |
| 1079 | + addTrimFallbackForIE8(); | |
| 1080 | + addFilterFallbackForIE8(); | |
| 1081 | + addKeysFallbackForIE8(); | |
| 1485 | 1082 | }, |
| 1486 | 1083 | |
| 1487 | 1084 | getFieldId: function( field, fullID ) { |
| 1488 | 1085 | return getFieldId( field, fullID ); |
| @@ -1665,12 +1262,12 @@ | ||
| 1665 | 1262 | removeSubmitLoading: function( $object, enable, processesRunning ) { |
| 1666 | 1263 | removeSubmitLoading( $object, enable, processesRunning ); |
| 1667 | 1264 | }, |
| 1668 | 1265 | |
| 1669 | - scrollToID: function( id ) { | |
| 1670 | - var object = jQuery( document.getElementById( id ) ); | |
| 1671 | - frmFrontForm.scrollMsg( object, false ); | |
| 1672 | - }, | |
| 1266 | + scrollToID: function( id ) { | |
| 1267 | + var object = jQuery( document.getElementById( id ) ); | |
| 1268 | + frmFrontForm.scrollMsg( object, false ); | |
| 1269 | + }, | |
| 1673 | 1270 | |
| 1674 | 1271 | scrollMsg: function( id, object, animate ) { |
| 1675 | 1272 | var newPos, m, b, screenTop, screenBottom, |
| 1676 | 1273 | scrollObj = ''; |
| @@ -1686,12 +1283,12 @@ | ||
| 1686 | 1283 | } |
| 1687 | 1284 | |
| 1688 | 1285 | jQuery( scrollObj ).trigger( 'focus' ); |
| 1689 | 1286 | newPos = scrollObj.offset().top; |
| 1690 | - if ( ! newPos || frm_js.offset === '-1' ) { // eslint-disable-line camelcase | |
| 1287 | + if ( ! newPos || frm_js.offset === '-1' ) { | |
| 1691 | 1288 | return; |
| 1692 | 1289 | } |
| 1693 | - newPos = newPos - frm_js.offset; // eslint-disable-line camelcase | |
| 1290 | + newPos = newPos - frm_js.offset; | |
| 1694 | 1291 | |
| 1695 | 1292 | m = jQuery( 'html' ).css( 'margin-top' ); |
| 1696 | 1293 | b = jQuery( 'body' ).css( 'margin-top' ); |
| 1697 | 1294 | if ( m || b ) { |
| @@ -1728,9 +1325,9 @@ | ||
| 1728 | 1325 | |
| 1729 | 1326 | jQuery( document ).trigger( 'frmFieldChanged', [ this, fieldId, e ]); |
| 1730 | 1327 | |
| 1731 | 1328 | if ( e.selfTriggered !== true ) { |
| 1732 | - maybeValidateChange( this ); | |
| 1329 | + maybeValidateChange( fieldId, this ); | |
| 1733 | 1330 | } |
| 1734 | 1331 | }, |
| 1735 | 1332 | |
| 1736 | 1333 | savingDraft: function( object ) { |
| @@ -1819,15 +1416,15 @@ | ||
| 1819 | 1416 | function frmUpdateField( entryId, fieldId, value, message, num ) { |
| 1820 | 1417 | jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).html( '<span class="frm-loading-img"></span>' ); |
| 1821 | 1418 | jQuery.ajax({ |
| 1822 | 1419 | type: 'POST', |
| 1823 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1420 | + url: frm_js.ajax_url, | |
| 1824 | 1421 | data: { |
| 1825 | 1422 | action: 'frm_entries_update_field_ajax', |
| 1826 | 1423 | entry_id: entryId, |
| 1827 | 1424 | field_id: fieldId, |
| 1828 | 1425 | value: value, |
| 1829 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1426 | + nonce: frm_js.nonce | |
| 1830 | 1427 | }, |
| 1831 | 1428 | success: function() { |
| 1832 | 1429 | if ( message.replace( /^\s+|\s+$/g, '' ) === '' ) { |
| 1833 | 1430 | jQuery( document.getElementById( 'frm_update_field_' + entryId + '_' + fieldId + '_' + num ) ).fadeOut( 'slow' ); |
| @@ -1842,13 +1439,13 @@ | ||
| 1842 | 1439 | console.warn( 'DEPRECATED: function frmDeleteEntry in v2.0.13 use frmFrontForm.deleteEntry' ); |
| 1843 | 1440 | jQuery( document.getElementById( 'frm_delete_' + entryId ) ).replaceWith( '<span class="frm-loading-img" id="frm_delete_' + entryId + '"></span>' ); |
| 1844 | 1441 | jQuery.ajax({ |
| 1845 | 1442 | type: 'POST', |
| 1846 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1443 | + url: frm_js.ajax_url, | |
| 1847 | 1444 | data: { |
| 1848 | 1445 | action: 'frm_entries_destroy', |
| 1849 | 1446 | entry: entryId, |
| 1850 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1447 | + nonce: frm_js.nonce | |
| 1851 | 1448 | }, |
| 1852 | 1449 | success: function( html ) { |
| 1853 | 1450 | if ( html.replace( /^\s+|\s+$/g, '' ) === 'success' ) { |
| 1854 | 1451 | jQuery( document.getElementById( prefix + entryId ) ).fadeOut( 'slow' ); |
| @@ -1869,14 +1466,14 @@ | ||
| 1869 | 1466 | console.warn( 'DEPRECATED: function frm_resend_email in v2.0' ); |
| 1870 | 1467 | $link.append( '<span class="spinner" style="display:inline"></span>' ); |
| 1871 | 1468 | jQuery.ajax({ |
| 1872 | 1469 | type: 'POST', |
| 1873 | - url: frm_js.ajax_url, // eslint-disable-line camelcase | |
| 1470 | + url: frm_js.ajax_url, | |
| 1874 | 1471 | data: { |
| 1875 | 1472 | action: 'frm_entries_send_email', |
| 1876 | 1473 | entry_id: entryId, |
| 1877 | 1474 | form_id: formId, |
| 1878 | - nonce: frm_js.nonce // eslint-disable-line camelcase | |
| 1475 | + nonce: frm_js.nonce | |
| 1879 | 1476 | }, |
| 1880 | 1477 | success: function( msg ) { |
| 1881 | 1478 | $link.replaceWith( msg ); |
| 1882 | 1479 | } |