Last active
July 20, 2016 20:10
-
-
Save dangerouse/2370891 to your computer and use it in GitHub Desktop.
Cloudsponge Widget Reference - The afterSubmitContacts callback
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- | |
Include the script anywhere on your page, usually in the head | |
(don't forget to replace `localhost-only` with your own CloudSponge Widget Key) | |
--> | |
<script src="//api.cloudsponge.com/widget/localhost-only.js"></script> | |
<script> | |
// these values will hold the owner information | |
var owner_email, owner_first_name, owner_last_name; | |
var appendInTextarea = true; // whether to append to existing contacts in the textarea | |
var emailSep = ", "; // email address separator to use in textarea | |
function populateTextarea(contacts, source, owner) { | |
var contact, name, email, entry; | |
var emails = []; | |
var textarea = document.getElementById('contact_list'); | |
// preserve the original value in the textarea | |
if (appendInTextarea && textarea.value.trim().length > 0) { | |
emails = textarea.value.split(emailSep); | |
} | |
// format each email address properly | |
for (var i = 0; i < contacts.length; i++) { | |
contact = contacts[i]; | |
name = contact.fullName(); | |
email = contact.selectedEmail(); | |
entry = name + "<" + email +">"; | |
if (emails.indexOf(entry) < 0) { | |
emails.push(entry); | |
} | |
} | |
// dump everything into the textarea | |
textarea.value = emails.join(emailSep); | |
// capture the owner information | |
owner_email = (owner && owner.email && owner.email[0] && owner.email[0].address) || ""; | |
owner_first_name = (owner && owner.first_name) || ""; | |
owner_last_name = (owner && owner.last_name) || ""; | |
} | |
// extra widget options go here: | |
cloudsponge.init({ | |
afterSubmitContacts: populateTextarea | |
}); | |
</script> | |
</head> | |
<body> | |
<a class="cloudsponge-launch">Add from Address Book</a> | |
<textarea id="contact_list"></textarea> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment