ajax-submission.js
6 years ago
ajax-submission.min.js
6 years ago
everest-forms.js
6 years ago
everest-forms.min.js
6 years ago
text-limit.js
6 years ago
text-limit.min.js
6 years ago
everest-forms.js
459 lines
| 1 | /* eslint-disable max-len */ |
| 2 | /* global everest_forms_params */ |
| 3 | jQuery( function ( $ ) { |
| 4 | 'use strict'; |
| 5 | |
| 6 | // everest_forms_params is required to continue, ensure the object exists. |
| 7 | if ( typeof everest_forms_params === 'undefined' ) { |
| 8 | return false; |
| 9 | } |
| 10 | |
| 11 | var everest_forms = { |
| 12 | $everest_form: $( 'form.everest-form' ), |
| 13 | init: function() { |
| 14 | this.init_inputMask(); |
| 15 | this.init_mailcheck(); |
| 16 | this.init_datepicker(); |
| 17 | this.load_validation(); |
| 18 | this.submission_scroll(); |
| 19 | this.randomize_elements(); |
| 20 | |
| 21 | // Inline validation. |
| 22 | this.$everest_form.on( 'input validate change', '.input-text, select, input:checkbox, input:radio', this.validate_field ); |
| 23 | }, |
| 24 | init_inputMask: function() { |
| 25 | // Only load if jQuery inputMask library exists. |
| 26 | if ( typeof $.fn.inputmask !== 'undefined' ) { |
| 27 | $( '.evf-masked-input' ).inputmask(); |
| 28 | } |
| 29 | }, |
| 30 | init_mailcheck: function() { |
| 31 | // Only load if Mailcheck library exists and enabled. |
| 32 | if ( typeof $.fn.mailcheck === 'undefined' || ! everest_forms_params.mailcheck_enabled ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | // Setup default domains for Mailcheck. |
| 37 | if ( everest_forms_params.mailcheck_domains.length > 0 ) { |
| 38 | Mailcheck.defaultDomains = Mailcheck.defaultDomains.concat( everest_forms_params.mailcheck_domains ); |
| 39 | } |
| 40 | |
| 41 | // Setup default top level domains for Mailcheck. |
| 42 | if ( everest_forms_params.mailcheck_toplevel_domains.length > 0 ) { |
| 43 | Mailcheck.defaultTopLevelDomains = Mailcheck.defaultTopLevelDomains.concat( everest_forms_params.mailcheck_toplevel_domains ); |
| 44 | } |
| 45 | |
| 46 | // Mailcheck suggestion. |
| 47 | $( document ).on( 'blur', '.evf-field-email input', function() { |
| 48 | var $el = $( this ), |
| 49 | id = $el.attr( 'id' ); |
| 50 | |
| 51 | $el.mailcheck( { |
| 52 | suggested: function( el, suggestion ) { |
| 53 | $( '#' + id + '_suggestion' ).remove(); |
| 54 | var suggestion_msg = everest_forms_params.i18n_messages_email_suggestion.replace( '{suggestion}', '<a href="#" class="mailcheck-suggestion" data-id="' + id + '" title="' + everest_forms_params.i18n_messages_email_suggestion_title + '">' + suggestion.full + '</a>' ); |
| 55 | $( el ).after( '<label class="evf-error mailcheck-error" id="' + id + '_suggestion">' + suggestion_msg + '</label>' ); |
| 56 | }, |
| 57 | empty: function() { |
| 58 | $( '#' + id + '_suggestion' ).remove(); |
| 59 | }, |
| 60 | } ); |
| 61 | } ); |
| 62 | |
| 63 | // Apply Mailcheck suggestion. |
| 64 | $( document ).on( 'click', '.evf-field-email .mailcheck-suggestion', function( e ) { |
| 65 | var $el = $( this ), |
| 66 | id = $el.attr( 'data-id' ); |
| 67 | e.preventDefault(); |
| 68 | $( '#' + id ).val( $el.text() ); |
| 69 | $el.parent().remove(); |
| 70 | } ); |
| 71 | }, |
| 72 | init_datepicker: function () { |
| 73 | var evfDateField = $( '.evf-field-date-time' ); |
| 74 | if ( evfDateField.length > 0 ) { |
| 75 | $( '.flatpickr-field' ).each( function() { |
| 76 | var timeInterval = 5, |
| 77 | inputData = $( this ).data(); |
| 78 | |
| 79 | switch( inputData.dateTime ) { |
| 80 | case 'date': |
| 81 | // Apply flatpicker to field. |
| 82 | $( this ).flatpickr({ |
| 83 | disableMobile : true, |
| 84 | mode : inputData.mode, |
| 85 | minDate : inputData.minDate, |
| 86 | maxDate : inputData.maxDate, |
| 87 | dateFormat : inputData.dateFormat |
| 88 | }); |
| 89 | break; |
| 90 | case 'time': |
| 91 | if ( undefined !== inputData.timeInterval ) { |
| 92 | timeInterval = parseInt( inputData.timeInterval, 10 ); |
| 93 | } |
| 94 | |
| 95 | // Apply flatpicker to field. |
| 96 | $( this ).flatpickr({ |
| 97 | enableTime : true, |
| 98 | noCalendar : true, |
| 99 | minuteIncrement : timeInterval, |
| 100 | dateFormat : inputData.dateFormat, |
| 101 | disableMobile : true, |
| 102 | time_24hr : inputData.dateFormat.includes('H:i') |
| 103 | }); |
| 104 | break; |
| 105 | case 'date-time': |
| 106 | if ( undefined !== inputData.timeInterval ) { |
| 107 | timeInterval = parseInt( inputData.timeInterval, 10 ); |
| 108 | } |
| 109 | |
| 110 | // Apply flatpicker to field. |
| 111 | $( this ).flatpickr({ |
| 112 | enableTime : true, |
| 113 | noCalendar : false, |
| 114 | disableMobile : true, |
| 115 | mode : inputData.mode, |
| 116 | minDate : inputData.minDate, |
| 117 | maxDate : inputData.maxDate, |
| 118 | minuteIncrement : timeInterval, |
| 119 | dateFormat : inputData.dateFormat, |
| 120 | time_24hr : inputData.dateFormat.includes( 'H:i' ) |
| 121 | }); |
| 122 | break; |
| 123 | default: |
| 124 | } |
| 125 | }); |
| 126 | } |
| 127 | }, |
| 128 | load_validation: function() { |
| 129 | if ( typeof $.fn.validate === 'undefined' ) { |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | // Prepend URL field contents with http:// if user input doesn't contain a schema. |
| 134 | $( '.evf-field-url input[type=url]' ).change( function () { |
| 135 | var url = $( this ).val(); |
| 136 | if ( ! url ) { |
| 137 | return false; |
| 138 | } |
| 139 | if ( url.substr( 0, 7 ) !== 'http://' && url.substr( 0, 8 ) !== 'https://' ) { |
| 140 | $( this ).val( 'http://' + url ); |
| 141 | } |
| 142 | }); |
| 143 | |
| 144 | // Validator messages. |
| 145 | $.extend( $.validator.messages, { |
| 146 | required: everest_forms_params.i18n_messages_required, |
| 147 | url: everest_forms_params.i18n_messages_url, |
| 148 | email: everest_forms_params.i18n_messages_email, |
| 149 | number: everest_forms_params.i18n_messages_number |
| 150 | }); |
| 151 | |
| 152 | // Validate email addresses. |
| 153 | $.validator.methods.email = function( value, element ) { |
| 154 | /* https://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */ |
| 155 | var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); |
| 156 | return this.optional( element ) || pattern.test( value ); |
| 157 | }; |
| 158 | |
| 159 | // Validate confirmations. |
| 160 | $.validator.addMethod( 'confirm', function( value, element, param ) { |
| 161 | return $.validator.methods.equalTo.call( this, value, element, param ); |
| 162 | }, everest_forms_params.i18n_messages_confirm ); |
| 163 | |
| 164 | // Validate checkbox choice limit. |
| 165 | $.validator.addMethod( 'check-limit', function( value, element ) { |
| 166 | var $ul = $( element ).closest( 'ul' ), |
| 167 | $checked = $ul.find( 'input[type="checkbox"]:checked' ), |
| 168 | choiceLimit = parseInt( $ul.attr( 'data-choice-limit' ) || 0, 10 ); |
| 169 | |
| 170 | if ( 0 === choiceLimit ) { |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | return $checked.length <= choiceLimit; |
| 175 | }, function( params, element ) { |
| 176 | var choiceLimit = parseInt( $( element ).closest( 'ul' ).attr( 'data-choice-limit' ) || 0, 10 ); |
| 177 | return everest_forms_params.i18n_messages_check_limit.replace( '{#}', choiceLimit ); |
| 178 | } ); |
| 179 | |
| 180 | this.$everest_form.each( function() { |
| 181 | var $this = $( this ); |
| 182 | |
| 183 | // List messages to show for required fields. Use name of the field as key. |
| 184 | var error_messages = {}; |
| 185 | $( '.evf-field' ).each( function() { |
| 186 | var form_id = $( this ).closest( 'form' ).data( 'formid' ); |
| 187 | var field_id = $( this ).data( 'field-id' ); |
| 188 | var error_message = $( this ).data( 'required-field-message' ); |
| 189 | var key = 'everest_forms[form_fields][' + field_id + ']'; // Name of the input field is used as a key. |
| 190 | |
| 191 | if ( $( this ).is( '.evf-field-payment-single' ) ) { |
| 192 | if ( ! $( this ).find('.evf-payment-price').is( '.evf-payment-user-input' ) ) { |
| 193 | $( this ).find('.evf-payment-price').attr( 'required', false ); |
| 194 | error_message = null; |
| 195 | } |
| 196 | } else if ( $( this ).is( '.evf-field-checkbox, .evf-field-payment-checkbox' ) ) { |
| 197 | key = key + '[]'; |
| 198 | } else if ( $( this ).is( '.evf-field-file-upload, .evf-field-image-upload' ) ) { |
| 199 | key = 'evf_' + form_id + '_' + field_id; |
| 200 | } else if ( $( this ).is( '.evf-field-signature' ) ) { |
| 201 | key = 'everest_forms[form_fields][' + field_id + '][signature_image]'; |
| 202 | } else if ( $( this ).is( '.evf-field-phone' ) ) { |
| 203 | key = key + '[phone_field]'; |
| 204 | } else if ( $( this ).is( '.evf-field-email' ) || $( this ).is( '.evf-field-password' ) ) { |
| 205 | // For when the confirm is disabled. |
| 206 | key = 'everest_forms[form_fields][' + field_id + ']'; |
| 207 | error_messages[ key ] = { |
| 208 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 209 | }; |
| 210 | |
| 211 | // For when the confirm is enabled. |
| 212 | key = 'everest_forms[form_fields][' + field_id + '][primary]'; |
| 213 | error_messages[ key ] = { |
| 214 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 215 | }; |
| 216 | key = 'everest_forms[form_fields][' + field_id + '][secondary]'; |
| 217 | error_messages[ key ] = { |
| 218 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 219 | }; |
| 220 | error_message = null; |
| 221 | } else if ( $( this ).is( '.evf-field-address' ) ) { |
| 222 | var sub_field_error_messages = { |
| 223 | 'address1': $( this ).data( 'required-field-message-address1' ), |
| 224 | 'city' : $( this ).data( 'required-field-message-city' ), |
| 225 | 'state' : $( this ).data( 'required-field-message-state' ), |
| 226 | 'postal' : $( this ).data( 'required-field-message-postal' ), |
| 227 | 'country' : $( this ).data( 'required-field-message-country' ), |
| 228 | } |
| 229 | |
| 230 | var sub_field_types = Object.keys( sub_field_error_messages ); |
| 231 | for ( var i = 0; i < sub_field_types.length; i++ ) { |
| 232 | var sub_field_type = sub_field_types[i], |
| 233 | error_message = sub_field_error_messages[ sub_field_types[i] ]; |
| 234 | |
| 235 | key = 'everest_forms[form_fields][' + field_id + '][' + sub_field_type + ']'; |
| 236 | error_messages[ key ] = { |
| 237 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 238 | }; |
| 239 | } |
| 240 | error_message = null; |
| 241 | } else if ( $( this ).is( '.evf-field-likert' ) ) { |
| 242 | var row_keys = $( this ).data( 'row-keys' ); |
| 243 | var sub_field_error_messages = {}; |
| 244 | |
| 245 | if ( row_keys && Array.isArray( row_keys ) ) { |
| 246 | for ( var i = 0; i < row_keys.length; i++ ) { |
| 247 | var row_key = row_keys[i]; |
| 248 | sub_field_error_messages[ row_key ] = $( this ).data( 'required-field-message-' + row_key ); |
| 249 | } |
| 250 | for ( var i = 0; i < row_keys.length; i++ ) { |
| 251 | error_message = sub_field_error_messages[ row_keys[i] ]; |
| 252 | key = 'everest_forms[form_fields][' + field_id + '][' + row_keys[i] + ']'; |
| 253 | error_messages[ key ] = { |
| 254 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 255 | }; |
| 256 | } |
| 257 | } |
| 258 | error_message = null; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Check if the error message has been already set (null value in error_message variable |
| 263 | * should indicate that the message has already been set). |
| 264 | */ |
| 265 | if ( error_message ) { |
| 266 | error_messages[ key ] = { |
| 267 | required: error_message, // Set message using 'required' key to avoid conflicts with other validations. |
| 268 | }; |
| 269 | } |
| 270 | }); |
| 271 | |
| 272 | $this.validate({ |
| 273 | messages: error_messages, |
| 274 | ignore: '', |
| 275 | errorClass: 'evf-error', |
| 276 | validClass: 'evf-valid', |
| 277 | errorPlacement: function( error, element ) { |
| 278 | if ( element.closest( '.evf-field' ).is( '.evf-field-scale-rating' ) ) { |
| 279 | element.closest( '.evf-field' ).find( '.everest-forms-field-scale-rating' ).after( error ); |
| 280 | } else if ( 'radio' === element.attr( 'type' ) || 'checkbox' === element.attr( 'type' ) ) { |
| 281 | if ( element.hasClass( 'everest-forms-likert-field-option' ) ) { |
| 282 | element.closest( 'tr' ).children( 'th' ).append( error ); |
| 283 | } else { |
| 284 | element.closest( '.evf-field-checkbox' ).find( 'label.evf-error' ).remove(); |
| 285 | element.parent().parent().parent().append( error ); |
| 286 | } |
| 287 | } else if ( element.is( 'select' ) && element.attr( 'class' ).match( /date-month|date-day|date-year/ ) ) { |
| 288 | if ( element.parent().find( 'label.evf-error:visible' ).length === 0 ) { |
| 289 | element.parent().find( 'select:last' ).after( error ); |
| 290 | } |
| 291 | } else if ( element.hasClass( 'evf-smart-phone-field' ) || element.hasClass( 'everest-forms-field-password-primary' ) || element.hasClass( 'everest-forms-field-password-secondary' ) ) { |
| 292 | element.parent().after( error ); |
| 293 | } else { |
| 294 | error.insertAfter( element ); |
| 295 | } |
| 296 | }, |
| 297 | highlight: function( element, errorClass, validClass ) { |
| 298 | var $element = $( element ), |
| 299 | $parent = $element.closest( '.form-row' ), |
| 300 | inputName = $element.attr( 'name' ); |
| 301 | |
| 302 | if ( $element.attr( 'type' ) === 'radio' || $element.attr( 'type' ) === 'checkbox' ) { |
| 303 | $parent.find( 'input[name=\''+inputName+'\']' ).addClass( errorClass ).removeClass( validClass ); |
| 304 | } else { |
| 305 | $element.addClass( errorClass ).removeClass( validClass ); |
| 306 | } |
| 307 | |
| 308 | $parent.removeClass( 'everest-forms-validated' ).addClass( 'everest-forms-invalid evf-has-error' ); |
| 309 | }, |
| 310 | unhighlight: function( element, errorClass, validClass ) { |
| 311 | var $element = $( element ), |
| 312 | $parent = $element.closest( '.form-row' ), |
| 313 | inputName = $element.attr( 'name' ); |
| 314 | |
| 315 | if ( $element.attr( 'type' ) === 'radio' || $element.attr( 'type' ) === 'checkbox' ) { |
| 316 | $parent.find( 'input[name=\''+inputName+'\']' ).addClass( validClass ).removeClass( errorClass ); |
| 317 | } else { |
| 318 | $element.addClass( validClass ).removeClass( errorClass ); |
| 319 | } |
| 320 | |
| 321 | $parent.removeClass( 'evf-has-error' ); |
| 322 | }, |
| 323 | submitHandler: function( form ) { |
| 324 | var $form = $( form ), |
| 325 | $submit = $form.find( '.evf-submit' ), |
| 326 | processText = $submit.data( 'process-text' ); |
| 327 | |
| 328 | // Process form. |
| 329 | if ( processText ) { |
| 330 | $submit.text( processText ).prop( 'disabled', true ); |
| 331 | } |
| 332 | |
| 333 | if ( 1 !== $form.data( 'ajax_submission' ) ) { |
| 334 | form.submit(); |
| 335 | } else { |
| 336 | return; |
| 337 | } |
| 338 | }, |
| 339 | onkeyup: function( element, event ) { |
| 340 | // This code is copied from JQuery Validate 'onkeyup' method with only one change: 'everest-forms-novalidate-onkeyup' class check. |
| 341 | var excludedKeys = [ 16, 17, 18, 20, 35, 36, 37, 38, 39, 40, 45, 144, 225 ]; |
| 342 | |
| 343 | // Disable onkeyup validation for some elements (e.g. remote calls). |
| 344 | if ( $( element ).hasClass( 'everest-forms-novalidate-onkeyup' ) ) { |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | if ( 9 === event.which && '' === this.elementValue( element ) || -1 !== $.inArray( event.keyCode, excludedKeys ) ) { |
| 349 | return; |
| 350 | } else if ( element.name in this.submitted || element.name in this.invalid ) { |
| 351 | this.element( element ); |
| 352 | } |
| 353 | }, |
| 354 | onfocusout: function( element ) { |
| 355 | // This code is copied from JQuery Validate 'onfocusout' method with only one change: 'everest-forms-novalidate-onkeyup' class check. |
| 356 | var validate = false; |
| 357 | |
| 358 | // Empty value error handling for elements with onkeyup validation disabled. |
| 359 | if ( $( element ).hasClass( 'everest-forms-novalidate-onkeyup' ) && ! element.value ) { |
| 360 | validate = true; |
| 361 | } |
| 362 | |
| 363 | if ( ! this.checkable( element ) && ( element.name in this.submitted || ! this.optional( element ) ) ) { |
| 364 | validate = true; |
| 365 | } |
| 366 | |
| 367 | if ( validate ) { |
| 368 | this.element( element ); |
| 369 | } |
| 370 | }, |
| 371 | onclick: function( element ) { |
| 372 | var validate = false; |
| 373 | |
| 374 | if ( 'checkbox' === ( element || {} ).type ) { |
| 375 | $( element ).closest( '.evf-field-checkbox' ).find( 'label.evf-error' ).remove(); |
| 376 | validate = true; |
| 377 | } else { |
| 378 | $( element ).valid(); |
| 379 | } |
| 380 | |
| 381 | if ( validate ) { |
| 382 | this.element( element ); |
| 383 | } |
| 384 | } |
| 385 | }); |
| 386 | }); |
| 387 | }, |
| 388 | validate_field: function ( e ) { |
| 389 | var $this = $( this ), |
| 390 | $parent = $this.closest( '.form-row' ), |
| 391 | validated = true, |
| 392 | validate_required = $parent.is( '.validate-required' ), |
| 393 | validate_email = $parent.is( '.validate-email' ), |
| 394 | event_type = e.type; |
| 395 | |
| 396 | if ( $parent.hasClass( 'evf-field-address' ) || $parent.hasClass( 'evf-field-payment-single' ) ) { |
| 397 | if ( 0 === $parent.find( 'input.evf-error' ).length ) { |
| 398 | $parent.removeClass( 'everest-forms-invalid everest-forms-invalid-required-field everest-forms-invalid-email' ).addClass( 'everest-forms-validated' ); |
| 399 | } |
| 400 | } else { |
| 401 | if ( 'input' === event_type ) { |
| 402 | $parent.removeClass( 'everest-forms-invalid everest-forms-invalid-required-field everest-forms-invalid-email everest-forms-validated' ); |
| 403 | } |
| 404 | |
| 405 | if ( 'validate' === event_type || 'change' === event_type ) { |
| 406 | if ( validate_required ) { |
| 407 | if ( $this.hasClass( 'everest-forms-likert-field-option' ) ) { |
| 408 | if ( $parent.find('input.evf-error').length > 0 ) { |
| 409 | $parent.removeClass( 'everest-forms-validated' ).addClass( 'everest-forms-invalid everest-forms-invalid-required-field' ); |
| 410 | validated = false; |
| 411 | } |
| 412 | } else if ( 'checkbox' === $this.attr( 'type' ) && 0 === $parent.find('input:checked').length ) { |
| 413 | $parent.removeClass( 'everest-forms-validated' ).addClass( 'everest-forms-invalid everest-forms-invalid-required-field' ); |
| 414 | validated = false; |
| 415 | } else if ( '' === $this.val() ) { |
| 416 | $parent.removeClass( 'everest-forms-validated' ).addClass( 'everest-forms-invalid everest-forms-invalid-required-field' ); |
| 417 | validated = false; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if ( validate_email ) { |
| 422 | if ( $this.val() ) { |
| 423 | /* https://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */ |
| 424 | var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); |
| 425 | |
| 426 | if ( ! pattern.test( $this.val() ) ) { |
| 427 | $parent.removeClass( 'everest-forms-validated' ).addClass( 'everest-forms-invalid everest-forms-invalid-email' ); |
| 428 | validated = false; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | if ( validated ) { |
| 433 | $parent.removeClass( 'everest-forms-invalid everest-forms-invalid-required-field everest-forms-invalid-email' ).addClass( 'everest-forms-validated' ); |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | }, |
| 438 | submission_scroll: function(){ |
| 439 | if ( $( 'div.everest-forms-submission-scroll' ).length ) { |
| 440 | $( 'html,body' ).animate( { |
| 441 | scrollTop: ( $( 'div.everest-forms-submission-scroll' ).offset().top ) - 100 |
| 442 | }, 1000 ); |
| 443 | } |
| 444 | }, |
| 445 | randomize_elements: function() { |
| 446 | $( '.everest-forms-randomize' ).each( function() { |
| 447 | var $list = $( this ), |
| 448 | $listItems = $list.children(); |
| 449 | |
| 450 | while ( $listItems.length ) { |
| 451 | $list.append( $listItems.splice( Math.floor( Math.random() * $listItems.length ), 1 )[0] ); |
| 452 | } |
| 453 | } ); |
| 454 | } |
| 455 | }; |
| 456 | |
| 457 | everest_forms.init(); |
| 458 | }); |
| 459 |