( function( $ ) { $( document ).ready( function() { $( '.wpcf7-submit' ).click( function( event ) { cptchpls_reload( $( this ) ); }); cptchpls_init(); }); })(jQuery); /** * Add custom events for captcha`s elevents * @param void * @return void */ function cptchpls_init() { (function($) { /* reload captcha */ $( '.cptchpls_reload_button' ).click( function( event ) { cptchpls_reload( $( this ), event ); }); /* enlarge images by click on mobile devices */ if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Windows Phone|Opera Mini/i.test( navigator.userAgent ) && cptchpls_vars.enlarge == '1' ) { $( '.cptchpls_img' ).click( function( event ) { event.preventDefault(); var reduce = $( this ).hasClass( 'cptchpls_reduce' ); if ( $( this ).hasClass( 'cptchpls_reduce' ) ) $( this ).css({ zIndex: 1 }).animate({ width: $( this ).width() / 2 + 'px' }, 800 ).toggleClass( 'cptchpls_reduce' ); else $( this ).css({ position: 'absolute', zIndex: 2 }).animate({ width: $( this ).width() * 2 + 'px' }, 800 ).toggleClass( 'cptchpls_reduce' ); $( '.cptchpls_span' ).children( '.cptchpls_reduce' ).not( this ).each( function() { $( this ).css({ zIndex: 1 }).animate({ width: $( this ).width() / 2 + 'px' }, 800 ).toggleClass( 'cptchpls_reduce' ); }); }).parent( '.cptchpls_span' ).each( function() { var image = $( this ).children( 'img' ); if ( image.length ) { $( this ).css({ width: image.width() + 'px', height: image.height() + 'px', }); } }); } })(jQuery); } /** * Reload captcha */ function cptchpls_reload( object, event ) { (function($) { $( object ).each( function() { var block_class = $( this ).attr( 'class' ), captcha; if ( $.type( block_class ) === 'string' && block_class.match( /cptchpls_reload_button/ ) ) { if ( $.type( event ) === 'object' ) event.preventDefault(); captcha = $( this ).parent().parent( '.cptchpls_wrap' ); $( this ).addClass( 'cptchpls_active' ); } else { captcha = $( this ).closest( 'form' ).find( '.cptchpls_wrap' ); } if ( captcha.length ) { var captcha_block = captcha.parent(), input = captcha.find( 'input:text' ), input_name = input.attr( 'name' ), input_class = input.attr( 'class' ).replace( /cptchpls_input/, '' ).replace( /^\s+|\s+$/g, '' ), form_slug = captcha_block.find( 'input[name="cptchpls_form"]' ).val(); $.ajax({ type: 'POST', url: cptchpls_vars.ajaxurl, data: { action: 'cptchpls_reload', cptchpls_nonce: cptchpls_vars.nonce, cptchpls_input_name: input_name, cptchpls_input_class: input_class, cptchpls_form_slug: form_slug }, success: function( result ) { captcha_block.find( 'input[type="hidden"], .cptchpls_reload_button_wrap, .cptchpls_reload_button' ).remove(); var forms = [ 'default', 'wp_login', 'wp_register', 'wp_comments', 'wp_lost_password' ]; if ( input_class === '' ) captcha.replaceWith( result ); /* for default forms */ else captcha_block.replaceWith( result ); /* for custom forms */ cptchpls_init(); }, error : function ( xhr, ajaxOptions, thrownError ) { alert( xhr.status ); alert( thrownError ); } }); } }); })(jQuery); }