(function($){ $.validator.addMethod( "alphanumeric", function( value, element ) { return this.optional( element ) || /^\w+$/i.test( value ); }, "Letters, numbers, and underscores only please" ); FLBuilder.registerModuleHelper('contact-form', { rules: { recaptcha_action: { alphanumeric: true } }, init: function() { var form = $( '.fl-builder-settings' ), icon = form.find( 'input[name=btn_icon]' ); icon.on( 'change', this._flipSettings ); this._flipSettings(); // Toggle reCAPTCHA display this._toggleReCaptcha(); this._toggleAction(); $( 'select[name=recaptcha_toggle]' ).on( 'change', $.proxy( this._toggleReCaptcha, this ) ); $( 'select[name=recaptcha_toggle]' ).on( 'change', $.proxy( this._toggleAction, this ) ); $( 'input[name=recaptcha_site_key]' ).on( 'change', $.proxy( this._toggleReCaptcha, this ) ); $( 'select[name=recaptcha_validate_type]' ).on( 'change', $.proxy( this._toggleReCaptcha, this ) ); $( 'select[name=recaptcha_theme]' ).on( 'change', $.proxy( this._toggleReCaptcha, this ) ); $( 'input[name=btn_bg_color]' ).on( 'change', this._previewButtonBackground ); // Render reCAPTCHA after layout rendered via AJAX if ( window.onLoadFLReCaptcha ) { $( FLBuilder._contentClass ).on( 'fl-builder.layout-rendered', onLoadFLReCaptcha ); } }, _flipSettings: function() { var form = $( '.fl-builder-settings' ), icon = form.find( 'input[name=btn_icon]' ); if ( -1 !== icon.val().indexOf( 'fad fa') ) { $('#fl-field-btn_duo_color1').show(); $('#fl-field-btn_duo_color2').show(); } else { $('#fl-field-btn_duo_color1').hide(); $('#fl-field-btn_duo_color2').hide(); } }, /** * Custom preview method for reCAPTCHA settings * * @param object event The event type of where this method been called * @since 1.9.5 */ _toggleReCaptcha: function(event) { var form = $( '.fl-builder-settings' ), nodeId = form.attr( 'data-node' ), toggle = form.find( 'select[name=recaptcha_toggle]' ), captchaKey = form.find( 'input[name=recaptcha_site_key]' ).val(), captType = form.find( 'select[name=recaptcha_validate_type]' ).val(), theme = form.find( 'select[name=recaptcha_theme]' ).val(), reCaptcha = $( '.fl-node-'+ nodeId ).find( '.fl-grecaptcha' ), reCaptchaId = nodeId +'-fl-grecaptcha', target = typeof event !== 'undefined' ? $(event.currentTarget) : null, inputEvent = target != null && typeof target.attr('name') !== typeof undefined && target.attr('name') === 'recaptcha_site_key', selectEvent = target != null && typeof target.attr('name') !== typeof undefined && target.attr('name') === 'recaptcha_toggle', typeEvent = target != null && typeof target.attr('name') !== typeof undefined && target.attr('name') === 'recaptcha_validate_type', themeEvent = target != null && typeof target.attr('name') !== typeof undefined && target.attr('name') === 'recaptcha_theme', scriptTag = $('