admin_script.js
129 lines
| 1 | ( function( $ ) { |
| 2 | $( document ).ready( function() { |
| 3 | |
| 4 | |
| 5 | $( "#gglcptch_score_v3").change(function() { |
| 6 | var score; |
| 7 | score = $(this).val(); |
| 8 | $("#gglcptch_score_out_v3").text(score); |
| 9 | }) |
| 10 | .trigger('change'); |
| 11 | |
| 12 | $( 'input[name="gglcptch_recaptcha_version"]' ).change( function() { |
| 13 | var versions = $( 'input[name="gglcptch_recaptcha_version"]' ); |
| 14 | versions.each( function() { |
| 15 | if ( $( this ).is( ':checked' ) ) { |
| 16 | $( '.gglcptch_theme_' + $( this ).val() ).show(); |
| 17 | $( '.gglcptch_score_' + $( this ).val() ).show(); |
| 18 | } else { |
| 19 | $( '.gglcptch_theme_' + $( this ).val() ).hide(); |
| 20 | $( '.gglcptch_score_' + $( this ).val() ).hide(); |
| 21 | } |
| 22 | } ); |
| 23 | } ).trigger( 'change' ); |
| 24 | |
| 25 | $( 'input[name="gglcptch_private_key"], input[name="gglcptch_public_key"]' ).change( function() { |
| 26 | $( '.gglcptch_verified, #gglcptch-test-keys, #gglcptch-test-block' ).hide(); |
| 27 | } ); |
| 28 | |
| 29 | $( '.gglcptch-settings-accordion' ).accordion( |
| 30 | { |
| 31 | collapsible: true, |
| 32 | heightStyle: "content" |
| 33 | } |
| 34 | ); |
| 35 | |
| 36 | /* Prevent jQuery accordion collapsing on link click */ |
| 37 | $( ".gglcptch-settings-accordion a" ).on( "click", function( event ) { |
| 38 | event.stopPropagation(); |
| 39 | } ); |
| 40 | |
| 41 | /** |
| 42 | * Handle the "Whitelist" tab on the plugins option page |
| 43 | */ |
| 44 | $( 'button[name="gglcptch_show_whitelist_form"]' ).click( function() { |
| 45 | $( this ).closest( 'form' ).hide(); |
| 46 | $( '.gglcptch_whitelist_form' ).show(); |
| 47 | return false; |
| 48 | } ); |
| 49 | |
| 50 | /* add my ip to the whitelist */ |
| 51 | $( 'input[name="gglcptch_add_to_whitelist_my_ip"]' ).change( function() { |
| 52 | if ( $( this ).is( ':checked' ) ) { |
| 53 | var my_ip = $( 'input[name="gglcptch_add_to_whitelist_my_ip_value"]' ).val(); |
| 54 | $( 'input[name="gglcptch_add_to_whitelist"]' ).val( my_ip ).attr( 'readonly', 'readonly' ); |
| 55 | } else { |
| 56 | $( 'input[name="gglcptch_add_to_whitelist"]' ).val( '' ).removeAttr( 'readonly' ); |
| 57 | } |
| 58 | } ); |
| 59 | } ); |
| 60 | |
| 61 | $( document ).on( 'click', '#gglcptch-test-keys a', function( e ) { |
| 62 | e.preventDefault(); |
| 63 | |
| 64 | if ( ! $( '#gglcptch-test-block' ).length ) { |
| 65 | $( '#gglcptch-test-keys' ).after( '<div id="gglcptch-test-block"></div>' ); |
| 66 | } |
| 67 | |
| 68 | $( '.gglcptch-test-results' ).remove(); |
| 69 | $( '#gglcptch-test-block' ).load( $( this ).prop( 'href' ), function() { |
| 70 | $( '.gglcptch_v1, .gglcptch_v2, .gglcptch_invisible' ).each( function() { |
| 71 | var container = $( this ).find( '.gglcptch_recaptcha' ).attr( 'id' ); |
| 72 | if ( $( this ).is( ':visible' ) ) { |
| 73 | gglcptch.display( container ); |
| 74 | if ( $( this ).hasClass( 'gglcptch_invisible' ) ) { |
| 75 | var gglcptch_index = $( this ).find( '.gglcptch_recaptcha' ).data( 'gglcptch_index' ); |
| 76 | grecaptcha.execute( gglcptch_index ); |
| 77 | } |
| 78 | } |
| 79 | } ); |
| 80 | } ); |
| 81 | |
| 82 | e.stopPropagation(); |
| 83 | $( '#gglcptch-test-keys' ).hide(); |
| 84 | setTimeout( function(){ |
| 85 | if( $( '#gglcptch_test_keys_verification' ).length > 0 ) { |
| 86 | $( '#gglcptch_test_keys_verification' ).removeAttr('disabled'); |
| 87 | } |
| 88 | }, 2000 ); |
| 89 | return false; |
| 90 | } ); |
| 91 | |
| 92 | $( document ).on( 'click', '#gglcptch_test_keys_verification', function( e ) { |
| 93 | e.preventDefault(); |
| 94 | $.ajax( { |
| 95 | async : false, |
| 96 | cache : false, |
| 97 | type : 'POST', |
| 98 | url : ajaxurl, |
| 99 | headers : { |
| 100 | 'Content-Type' : 'application/x-www-form-urlencoded' |
| 101 | }, |
| 102 | data : { |
| 103 | action: 'gglcptch_test_keys_verification', |
| 104 | recaptcha_challenge_field : $( '#recaptcha_challenge_field' ).val(), |
| 105 | recaptcha_response_field : $( '#recaptcha_response_field' ).val(), |
| 106 | 'g-recaptcha-response' : $( '.g-recaptcha-response' ).val(), |
| 107 | _wpnonce : $( '[name="gglcptch_test_keys_verification-nonce"]' ).val() |
| 108 | }, |
| 109 | success: function( data ) { |
| 110 | $( '#gglcptch-test-block' ).after( data ); |
| 111 | $( '#gglcptch-test-block' ).html( '' ); |
| 112 | if ( $( '.gglcptch-test-results' ).hasClass( 'updated' ) ) { |
| 113 | $( '.gglcptch_verified' ).show(); |
| 114 | } else { |
| 115 | $( '.gglcptch_verified' ).hide(); |
| 116 | if ( |
| 117 | 'v2' == $( 'input[name="gglcptch_recaptcha_version"]:checked' ).val() || |
| 118 | 'invisible' == $( 'input[name="gglcptch_recaptcha_version"]:checked' ).val() |
| 119 | ) { |
| 120 | $( '#gglcptch-test-keys' ).show(); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } ); |
| 125 | |
| 126 | e.stopPropagation(); |
| 127 | return false; |
| 128 | } ); |
| 129 | } )( jQuery ); |