How to: player callbacks

You can set callbacks for Inline Manual Player either via optionsĀ or via method setCallbacks().

For example:

inline_manual_player.setCallbacks({
  onStepShow: function (player, topic_id, step_id) {
    console.log('Step was displayed.');
  }
});

You can use these callbacks:

onInit

arguments: player_instance

Called when Player object is initialised.

onDestroy

arguments: player_instance

Called when Player object is destroyed.

onTopicStart

arguments: player_instance, topic_id

Called when Topic is started.

onTopicPrevious

arguments: player_instance, topic_id, step_id

Called when the previous step within the topic is requested.

Note that the requested step may not actually exist (e.g. calling the previous step when the first step is active).

onTopicNext

arguments: player_instance, topic_id, step_id

Called when next step within the topic is requested.

Note that the requested step may not actually exist (e.g. calling next step when the last step is active).

onTopicEnd

arguments: player_instance, topic_id

Called when the topic is ended.

This may be because the user ended it, or because another topic was started.

onStepActivate

arguments: player_instance, topic_id, step_id

Called when the step is activated.

Note that the step may actually not be displayed, for example, because it is delayed, or it is waiting for the condition to be fulfilled.

onStepShow

arguments: player_instance, topic_id, step_id

Called when step's popover is actually displayed.

onRedirect

arguments: player_instance, url, target, done

This callback is called when Player attempts to redirect or open a new window. It can be used to intercept and cancel or modify the redirect request.

done callback expects two parameters - url and target

Example:

// always add GET parameter with timestamp to URL of the redirect
inline_manual_player.setCallbacks({
  onRedirect: function (player, url, target, done) {
    url += '?timestamp=' + (new Date).getTime()
    done(url, target);
  }
});
 
// only execute the redirect if user confirms the dialog
inline_manual_player.setCallbacks({
  onRedirect: function (player, url, target, done) {
    if (confirm('Do you really want to redirect to ' + url + '?')) {
      done(url, target);
    }
  }
});

onProfileLoad

arguments: player_instance, profile_data

This callback is called when Player successfully loads profile data from the server. It will not be called if request for profile data results in an error.

Was this article helpful?