| 1 |
/** |
| 2 |
* Patchstack |
| 3 |
* https://patchstack.com |
| 4 |
*/ |
| 5 |
|
| 6 |
window.Patchstack = window.Patchstack || {}; |
| 7 |
|
| 8 |
( function( window, document, $, plugin ) { |
| 9 |
var $c = {}; |
| 10 |
var polling = null; |
| 11 |
var isPolling = false; |
| 12 |
var pollingDelay = 0; |
| 13 |
|
| 14 |
plugin.init = function() { |
| 15 |
plugin.cache(); |
| 16 |
plugin.bindEvents(); |
| 17 |
}; |
| 18 |
|
| 19 |
plugin.cache = function() { |
| 20 |
$c.window = $( window ); |
| 21 |
$c.body = $( document.body ); |
| 22 |
}; |
| 23 |
|
| 24 |
plugin.poller = function() { |
| 25 |
polling = setInterval(() => { |
| 26 |
if (!isPolling && pollingDelay == 0) { |
| 27 |
plugin.autoActivate(); |
| 28 |
pollingDelay = 5; |
| 29 |
} |
| 30 |
|
| 31 |
pollingDelay--; |
| 32 |
}, 1000); |
| 33 |
}; |
| 34 |
|
| 35 |
plugin.autoActivate = function() { |
| 36 |
isPolling = true; |
| 37 |
|
| 38 |
var postData = { |
| 39 |
action: 'patchstack_activate_auto', |
| 40 |
PatchstackNonce: PatchstackVars.nonce |
| 41 |
}; |
| 42 |
|
| 43 |
$.post( PatchstackVars.ajaxurl, postData, function( response ) { |
| 44 |
var postData = { |
| 45 |
action: 'patchstack_activation_status', |
| 46 |
PatchstackNonce: PatchstackVars.nonce |
| 47 |
}; |
| 48 |
|
| 49 |
$.post ( PatchstackVars.ajaxurl, postData, function( response ) { |
| 50 |
if ( response.activated ) { |
| 51 |
window.location = window.location.href.replace('&ps_autoa=1', '') + '&resync=1'; |
| 52 |
} |
| 53 |
|
| 54 |
isPolling = false; |
| 55 |
}); |
| 56 |
}); |
| 57 |
}; |
| 58 |
|
| 59 |
plugin.bindEvents = function() { |
| 60 |
$('input#patchstack-activate').on( 'click', function(e) { |
| 61 |
e.preventDefault(); |
| 62 |
var postData = { |
| 63 |
action: 'patchstack_activate_license', |
| 64 |
key: $('.patchstack-auto-activate').attr('style') == '' ? $( '#patchstack_api_key2' ).val() : $( '#patchstack_api_key' ).val(), |
| 65 |
PatchstackNonce: PatchstackVars.nonce |
| 66 |
}; |
| 67 |
|
| 68 |
if ( $.trim( postData.key ).length == 0 ) { |
| 69 |
alert( 'Please enter the API key.' ); |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
$( '.patchstack-resync' ).hide(); |
| 74 |
$( '#patchstack-activate' ).hide(); |
| 75 |
$( '.patchstack-loading' ).show(); |
| 76 |
$( '.is-polling-section' ).hide(); |
| 77 |
isPolling = true |
| 78 |
|
| 79 |
$.post( PatchstackVars.ajaxurl, postData, function( response ) { |
| 80 |
isPolling = false |
| 81 |
pollingDelay = 5 |
| 82 |
if ( response.result == 'error' ) { |
| 83 |
$( '#patchstack-activate, .is-polling-section' ).show(); |
| 84 |
$( '.patchstack-loading' ).hide(); |
| 85 |
if ( response.error_message ) { |
| 86 |
alert( response.error_message ); |
| 87 |
} else { |
| 88 |
alert( PatchstackVars.error_message ); |
| 89 |
} |
| 90 |
} else { |
| 91 |
window.location = window.location.href + '&resync=1'; |
| 92 |
} |
| 93 |
}); |
| 94 |
}); |
| 95 |
|
| 96 |
if($("#patchstack_captcha_type").val() == "v2"){ |
| 97 |
$("#patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3, #patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").hide(); |
| 98 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key").show(); |
| 99 |
}else if($("#patchstack_captcha_type").val() == "invisible"){ |
| 100 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key, #patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").hide(); |
| 101 |
$("#patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3").show(); |
| 102 |
}else{ |
| 103 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key, #patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3").hide(); |
| 104 |
$("#patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").show(); |
| 105 |
} |
| 106 |
|
| 107 |
$("#patchstack_captcha_type").change(function() { |
| 108 |
if($("#patchstack_captcha_type").val() == "v2"){ |
| 109 |
$("#patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3, #patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").hide(); |
| 110 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key").show(); |
| 111 |
}else if($("#patchstack_captcha_type").val() == "invisible"){ |
| 112 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key, #patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").hide(); |
| 113 |
$("#patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3").show(); |
| 114 |
}else{ |
| 115 |
$("#patchstack_captcha_public_key, #patchstack_captcha_private_key, #patchstack_captcha_public_key_v3, #patchstack_captcha_private_key_v3").hide(); |
| 116 |
$("#patchstack_captcha_public_key_v3_new, #patchstack_captcha_private_key_v3_new").show(); |
| 117 |
} |
| 118 |
}); |
| 119 |
|
| 120 |
if($('#geo-countries').length > 0){ |
| 121 |
var items = [] |
| 122 |
if($('#geo-countries').data('selected') != ''){ |
| 123 |
items = $('#geo-countries').data('selected').split(',') |
| 124 |
} |
| 125 |
|
| 126 |
$('#geo-countries').selectize({ |
| 127 |
maxItems: null, |
| 128 |
delimiter: ',', |
| 129 |
plugins: ['remove_button'], |
| 130 |
items: items |
| 131 |
}); |
| 132 |
} |
| 133 |
}; |
| 134 |
|
| 135 |
$( plugin.init ); |
| 136 |
}( window, document, jQuery, window.Patchstack ) ); |