Created
August 7, 2019 19:30
-
-
Save sudikrt/16144cbb69948087968248a406cdcccb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page showHeader="false" applyBodyTag="false"> | |
<apex:includeScript value="{!$Resource.jQuery_3_1_1}"/> | |
<script src='{!$Setup.foolish__reCaptcha__c.foolish__libraryUrl__c}?onload=onloadCallback&render=explicit' type="application/javascript"/> | |
<style> | |
body, div{ | |
background:transparent !important; | |
} | |
html {overflow:hidden;} | |
.recaptcha { | |
transform: scale(0.74); | |
transform-origin: 0 0; | |
-webkit-transform:scale(0.74); | |
-webkit-transform-origin: 0 0 | |
} | |
</style> | |
<body class="body-tag"> | |
<div id="recaptcha-div" class="g-recaptcha recaptcha"></div> | |
<script type="text/javascript"> | |
jQuery(function($){ | |
var lastHeight = 0, curHeight = 0, $frame = $('iframe:eq(0)'); | |
setInterval(function(){ | |
curHeight = $frame.prevObject[0].activeElement.scrollHeight | |
if ( curHeight != lastHeight ) { | |
var hostURL = 'https://test-dev-ed.lightning.force.com'; //window.location.origin; | |
curHeight = curHeight && curHeight === 480 ? curHeight + 18 : curHeight; | |
parent.postMessage({ action: 'heigthChange', height : curHeight + 'px' }, hostURL); | |
} | |
},500); | |
}); | |
var callPostMethod = function (action, response) { | |
var hostURL = 'https://sudikrt-dev-ed.lightning.force.com'; //window.location.origin; | |
parent.postMessage({ action: action, response : response }, hostURL); | |
} | |
var onVerifyCallback = function () { | |
console.log ('Verified'); | |
let val = document.getElementById("g-recaptcha-response").value; | |
callPostMethod ('verified', val); | |
}; | |
var onErrorCallback = function () { | |
console.log ('Error'); | |
let val = document.getElementById("g-recaptcha-response").value; | |
callPostMethod ('error', val); | |
}; | |
var onExpiredCallback = function () { | |
console.log ('Expired'); | |
let val = document.getElementById("g-recaptcha-response").value; | |
callPostMethod ('expired', val); | |
}; | |
var onloadCallback = function() { | |
console.log ('Loaded'); | |
callPostMethod ('loaded', ''); | |
grecaptcha.render('recaptcha-div', { | |
'sitekey' : '{!$Setup.foolish__reCaptcha__c.foolish__PublicKey__c}', | |
'theme' : 'light', | |
'callback' : onVerifyCallback, | |
'expired-callback' :onExpiredCallback, | |
'error-callback' : onErrorCallback | |
}); | |
}; | |
/* | |
Extra snippet to communicate with Aura component | |
*/ | |
window.addEventListener("message", function(event) { | |
var hostURL = ''; | |
if(event.origin !== hostURL){ | |
return; | |
} | |
if(event.data.action == "alohaCallingCAPTCHA"){ | |
var message = document.getElementById("g-recaptcha-response").value; | |
} | |
}, false); | |
</script> | |
</body> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment