File: /wordpress/mu-plugins/wpcloud-bot-protection/assets/bootstrap.js
(function () {
var cfg = window.__wpcloudBlackbox || {};
if ( ! cfg.apiKey ) {
return;
}
var form = document.getElementById( 'loginform' ) || document.getElementById( 'lostpasswordform' );
var field = document.getElementById( cfg.field );
if ( ! form || ! field ) {
return;
}
var challengeInProgress = false;
var attempts = 0;
( function whenReady() {
if ( ! window.Blackbox || typeof window.Blackbox.configure !== 'function' ) {
if ( attempts++ < 50 ) {
window.setTimeout( whenReady, 100 );
} else if ( window.console && window.console.warn ) {
window.console.warn( '[wpcloud-blackbox] client did not load; gate inactive.' );
}
return;
}
try {
window.Blackbox.configure( {
apiKey: cfg.apiKey,
challengeContainer: document.getElementById( 'wpcloud-blackbox-challenge' ),
onSuccess: function ( result ) {
if ( result && result.sessionId ) {
field.value = result.sessionId;
}
},
onChallengeStart: function () {
challengeInProgress = true;
},
onChallengeComplete: function () {
challengeInProgress = false;
},
onChallengeFailure: function () {
challengeInProgress = false;
}
} );
window.Blackbox.init();
} catch ( err ) {
}
} )();
var submitting = false;
form.addEventListener( 'submit', function ( e ) {
if ( submitting ) {
return;
}
if ( ! window.Blackbox || typeof window.Blackbox.getSessionId !== 'function' ) {
return;
}
if ( challengeInProgress ) {
e.preventDefault();
return;
}
if ( field.value ) {
return;
}
e.preventDefault();
submitting = true;
var submitted = false;
var submit = function () {
if ( submitted ) { return; }
submitted = true;
if ( typeof form.requestSubmit === 'function' ) {
form.requestSubmit();
} else {
form.submit();
}
};
var safety = window.setTimeout( submit, 3000 );
window.Blackbox.getSessionId()
.then( function ( sid ) { if ( sid ) { field.value = sid; } } )
.catch( function () {} )
.then( function () { window.clearTimeout( safety ); submit(); } );
} );
})();