Tribe__PUE__Checker::do_license_key_javascript()
Inserts the javascript that makes the ajax checking work on the license key page
Source
File: src/Tribe/PUE/Checker.php
public function do_license_key_javascript() {
?>
<script>
jQuery(document).ready(function ($) {
$( '.tribe-field-license_key' ).each( function() {
var $el = $( this );
var $field = $el.find( 'input' );
if ( '' === $.trim( $field.val() ) ) {
$el.find( '.license-test-results' ).hide();
}
} );
$('#tribe-field-<?php echo esc_attr( $this->pue_install_key ); ?>').change(function () {
<?php echo sanitize_html_class( $this->pue_install_key ); ?>_validateKey();
});
<?php echo sanitize_html_class( $this->pue_install_key ); ?>_validateKey();
});
function <?php echo sanitize_html_class( $this->pue_install_key ); ?>_validateKey() {
var this_id = '#tribe-field-<?php echo esc_attr( $this->pue_install_key ); ?>';
var $validity_msg = jQuery(this_id + ' .key-validity');
if (jQuery(this_id + ' input').val() != '') {
jQuery( this_id + ' .license-test-results' ).show();
jQuery(this_id + ' .tooltip').hide();
jQuery(this_id + ' .ajax-loading-license').show();
$validity_msg.hide();
// Strip whitespace from key
var <?php echo sanitize_html_class( $this->pue_install_key ); ?>_license_key = jQuery(this_id + ' input').val().replace(/^\s+|\s+$/g, "");
jQuery(this_id + ' input').val(<?php echo sanitize_html_class( $this->pue_install_key ); ?>_license_key);
var data = {
action: 'pue-validate-key_<?php echo esc_attr( $this->get_slug() ); ?>',
key: <?php echo sanitize_html_class( $this->pue_install_key ); ?>_license_key,
_wpnonce: '<?php echo esc_attr( wp_create_nonce( 'pue-validate-key_' . $this->get_slug() ) ); ?>'
};
jQuery.post(ajaxurl, data, function (response) {
var data = jQuery.parseJSON(response);
jQuery(this_id + ' .ajax-loading-license').hide();
$validity_msg.show();
$validity_msg.html(data.message);
switch ( data.status ) {
case 1: $validity_msg.addClass( 'valid-key' ).removeClass( 'invalid-key' ); break;
case 2: $validity_msg.addClass( 'valid-key service-msg' ); break;
default: $validity_msg.addClass( 'invalid-key' ).removeClass( 'valid-key' ); break;
}
});
}
}
</script>
<?php
}