JavaScript API Events
Our JavaScript API supports client-side handling of custom events.
By using events you can execute a JavaScript function whenever a user performs an action of your choice (i.e. login with Facebook).
You can register your own event handlers by using the set_event method. By using the
add_event method, you can register many event handlers for the same event.
Event Setup
Example for the set_event method
<script type="text/javascript">
/* Initialise the asynchronous queue */
var _oneall = _oneall || [];
/* Define your function */
var my_function = function ()
{
alert("Widget Loaded")
};
/* Have it triggered by an event */
_oneall.push(['social_login', 'set_event', 'on_widget_loaded', my_function]);
/* Rendering the widget in order to trigger the event*/
_oneall.push(['social_login', 'do_render_ui', 'social_login_signin']);
</script>
Example for the add_event method
<script type="text/javascript">
/* Initialise the asynchronous queue */
var _oneall = _oneall || [];
/* Define your function */
var my_function_1 = function ()
{
alert("First call")
};
var my_function_2 = function ()
{
alert("Second call")
};
/* Have it triggered by an event */
_oneall.push(['social_login', 'add_event', 'on_widget_loaded', my_function_1]);
_oneall.push(['social_login', 'add_event', 'on_widget_loaded', my_function_2]);
/* Rendering the widget in order to trigger the event*/
_oneall.push(['social_login', 'do_render_ui', 'social_login_signin']);
</script>
Available Events
on_widget_loaded
This event is fired after a widget (e.g. Social Login or LoudVoice) has been rendered.
/*
Signature
<scope> : string (social_login, social_link, loudvoice)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_widget_loaded', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
}
_oneall.push(['social_login', 'set_event', 'on_widget_loaded', my_function]);
on_open_popup_ui
This event is fired when a modal dialog is opened.
/*
Signature
<scope> : string (social_login)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_open_popup_ui', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
}
_oneall.push(['social_login', 'set_event', 'on_open_popup_ui', my_function]);
on_close_popup_ui
This event is fired when a modal dialog is closed by the user.
/*
Signature
<scope> : string (social_login)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_close_popup_ui', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
}
_oneall.push(['social_login', 'set_event', 'on_close_popup_ui', my_function]);
on_open_login_data_dialog
This event is fired when the user is prompted to enter additional information (e.g. his OpenID identifier when connecting with OpenId).
/*
Signature
<scope> : string (social_login, social_link)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_open_login_data_dialog', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Name of the social network
console.log (args.provider.name);
// Key of the social network
console.log (args.provider.key);
}
_oneall.push(['social_login', 'set_event', 'on_open_login_data_dialog', my_function]);
on_close_login_data_dialog
This event is fired when the dialog to request additional information is closed by the user.
/*
Signature
<scope> : string (social_login, social_link)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_close_login_data_dialog', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Name of the social network
console.log (args.provider.name);
// Key of the social network
console.log (args.provider.key);
}
_oneall.push(['social_login', 'set_event', 'on_close_login_data_dialog', my_function]);
on_login_begin
This event is fired when a user clicks on a social network icon to start the authentication process.
/*
Signature
<scope> : string (social_login, social_link)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_login_begin', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Name of the social network
console.log (args.provider.name);
// Key of the social network
console.log (args.provider.key);
}
_oneall.push(['social_login', 'set_event', 'on_login_begin', my_function]);
on_login_end
This event is fired after the user has (successfully nor not) completed the authentication with a social network.
/*
Signature
<scope> : string (social_login, social_link)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_login_end', <function>]);
/* Example */
var my_function = function(args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Name of the social network
console.log (args.provider.name);
// Key of the social network
console.log (args.provider.key);
// Status of the connection
console.log (args.connection.status);
// Used connection_token
// http://docs.oneall.com/api/resources/connections/
console.log (args.connection.connection_token);
// Used user_token
// http://docs.oneall.com/api/resources/users/
console.log (args.connection.user_token);
}
_oneall.push(['social_login', 'set_event', 'on_login_end', my_function]);
on_login_end_success
This event is similar to on_login_end but only fired if the authentication process is completed successfully.
on_login_end_error
This event is similar to on_login_end but only fired if an error occurs during the authentication process.
on_login_end_cancelled
This event is similar to on_login_end but only fired if the user cancels the authentication process.
on_login_redirect
This event is fired after on_login_end but before redirecting the user to your callback_uri.
You can abort the redirection to the callback scriptby having this function return false.
/*
Signature
<scope> : string (social_login, social_link)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_login_end', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Name of the social network
console.log (args.provider.name);
// Key of the social network
console.log (args.provider.key);
// Status of the connection
console.log (args.connection.status);
// Used connection_token
// http://docs.oneall.com/api/resources/connections/
console.log (args.connection.connection_token);
// Used user_token
// http://docs.oneall.com/api/resources/users/
console.log (args.connection.user_token);
// Callback URI to which the user will be redirected
console.log (args.callback_uri);
}
_oneall.push(['social_login', 'set_event', 'on_login_redirect', my_function]);
on_logout_end_success
This event is fired after the user has successfully logged out.
/*
Signature
<scope> : string (loudvoice)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_logout_end_success', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Name of the service
console.log (args.service);
// Reference to the DOM element of the widget
console.log (args.widget);
// Request status
console.log (args.status);
// Request status as string
console.log (args.reason);
}
_oneall.push(['loudvoice', 'set_event', 'on_logout_end_success', my_function]);
on_comment_added
This event is fired after the user has addded a new comment.
/*
Signature
<scope> : string (loudvoice)
<function> : JavaScript function to be executed
*/
_oneall.push([<scope>, 'set_event', 'on_comment_added', <function>]);
/* Example */
var my_function = function (args)
{
// Name of the event
console.log (args.event);
// Reference to the DOM element of the widget
console.log (args.widget);
// Author token
// http://docs.oneall.com/api/resources/loudvoice/authors/read/
console.log (args.author_token);
// Comment token
// http://docs.oneall.com/api/resources/loudvoice/comment/read/
console.log (args.comment_token);
// Discussion token
// http://docs.oneall.com/api/resources/loudvoice/discussions/read/
console.log (args.discussion_token);
}
_oneall.push(['loudvoice', 'set_event', 'on_comment_added', my_function]);