Skip to content

Instantly share code, notes, and snippets.

@fczbkk
Last active June 27, 2017 06:24
Show Gist options
  • Select an option

  • Save fczbkk/7614a5471f5e862b0d7428d1a30c40dd to your computer and use it in GitHub Desktop.

Select an option

Save fczbkk/7614a5471f5e862b0d7428d1a30c40dd to your computer and use it in GitHub Desktop.
Inline Manual Player: unlimited undo
// take latest step from the list of previous steps and activate it
function activatePreviousStep () {
var steps_history = JSON.parse(localStorage.getItem('inm_steps_history')) || [];
var step_data = steps_history.pop();
if (step_data) {
inline_manual_player.activateStep(step_data.topic_id, step_data.step_index);
}
localStorage.setItem('inm_steps_history', JSON.stringify(steps_history));
}
// whenever step is deactivated, add it to the list of previous steps
inline_manual_player.setOptions({
callbacks: {
onStepDeactivate: function (player, topic_id, step_index) {
var steps_history = JSON.parse(localStorage.getItem('inm_steps_history')) || [];
steps_history.push({
topic_id: topic_id,
step_index: step_index
});
// cap steps history to 100 items, to prevent storage size overflow
steps_history = steps_history.slice(-100);
localStorage.setItem('inm_steps_history', JSON.stringify(steps_history));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment