Last active
December 27, 2015 02:39
-
-
Save fiftyandfifty/7253791 to your computer and use it in GitHub Desktop.
Using the donately.loaded event: Setting the recurring option as default on a Donately Form Load
This file contains 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
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
jQuery( window ).load(function() { | |
function receiveMessage(event){ | |
try {var data = JSON.parse(event.data);} | |
catch (e) {var data = event.data;} | |
if(data.event == 'donately.loaded'){ | |
jQuery('#donately-one-time-donation').prop('checked', false); | |
jQuery('#donately-recurring-donation').prop('checked', true); | |
} | |
} | |
if (window.addEventListener){ | |
window.addEventListener('message', receiveMessage, false); | |
} | |
else if (window.attachEvent){ | |
window.attachEvent('message', receiveMessage); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<script class="donatelyformjs" | |
src="http://www.dntly.com/assets/js/v1/form.js" | |
type="text/javascript" | |
async="async" | |
data-donately-id="1" | |
data-donately-ssl="1"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this to work, you will need to host the form on a secure (SSL) page so that it doesn't insert an iFrame
You can also accomplish this and more by creating a completely custom form. There is a working starting point for that here:
https://gist.github.com/fiftyandfifty/1cff4b1a841bca08e35a