To use the widget inside a WebUI component on a mobile device, there are a few considerations that this sample takes into account.
- It launches the widget immediately if you want to user to select the source from our list
- It prevents the popup window from opening so that the OAuth flow will reuse the same WebUI
- It receives the contacts in Javascript using our
afterSubmitContacts
callback.
<script src="https://api.cloudsponge.com/widget/localhost-only.js"></script>
<script>
cloudsponge.init({
// automatically show the widget once it is ready:
autoLaunch: true,
// restrict the widget to a single window, no popups allowed here
inlineOauth: true,
// receive the contacts via Javascript
afterSubmitContacts: function(contacts, source, owner) {
// it's time to sent the contacts back to the owner of this window.
alert('Got '+contacts.length+' contacts from the user');
},
// what if the import failed?
afterImport: function(source, success, code) {
if (!success) {
// the widget will display an error to the user
// your app may want to take additional action at this time
}
},
afterClosing: function() {
// the widget has just closed so your app may want to clean up the WebUI now
}
});
</script>