Skip to content

Commit

Permalink
refactor callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Jul 1, 2016
1 parent cdc270f commit e5a36e2
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions lib/scripts/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Component = React.createClass({
displayName: 'Joyride',

propTypes: {
callback: React.PropTypes.func,
completeCallback: React.PropTypes.func,
debug: React.PropTypes.bool,
keyboardNavigation: React.PropTypes.bool,
Expand Down Expand Up @@ -61,9 +62,7 @@ var Component = React.createClass({
showStepsProgress: false,
steps: [],
tooltipOffset: 15,
type: 'single',
completeCallback: undefined,
stepCallback: undefined
type: 'single'
};
},

Expand Down Expand Up @@ -432,7 +431,16 @@ var Component = React.createClass({
*/
_onBeaconTrigger: function(e) {
e.preventDefault();
this._toggleTooltip(true, this.state.index);
var props = this.props;
var state = this.state;

if (typeof props.callback === 'function') {
props.callback({
type: 'step:before',
step: props.steps[state.index]
});
}
this._toggleTooltip(true, state.index);
},

/**
Expand Down Expand Up @@ -495,14 +503,31 @@ var Component = React.createClass({
}, function() {
var lastIndex = action === 'back' ? index + 1 : index - 1;

if (action && typeof props.stepCallback === 'function' && props.steps[lastIndex]) {
props.stepCallback(props.steps[lastIndex]);
if (action && props.steps[lastIndex]) {
if (typeof props.stepCallback === 'function') { // Deprecated
props.stepCallback(props.steps[lastIndex]);
}

if (typeof props.callback === 'function') {
props.callback({
type: 'step:after',
step: props.steps[lastIndex]
});
}
}

if (props.steps.length && !props.steps[index]) {
if (typeof props.completeCallback === 'function') {
if (typeof props.completeCallback === 'function') { // Deprecated
props.completeCallback(props.steps, this.state.skipped);
}

if (typeof props.callback === 'function') {
props.callback({
type: 'finished',
steps: props.steps,
skipped: this.state.skipped
});
}
}
});
},
Expand Down

0 comments on commit e5a36e2

Please sign in to comment.