Skip to content

Commit

Permalink
Cleanup steps when tour is exited
Browse files Browse the repository at this point in the history
Resolves #66
  • Loading branch information
RobbieTheWagner committed Jul 12, 2018
1 parent 76979d2 commit 9c0ee27
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/js/shepherd.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class Evented {
}

class Step extends Evented {

constructor(tour, options) {
super(tour, options);
this.tour = tour;
Expand Down Expand Up @@ -592,15 +591,14 @@ class Step extends Evented {
}

class Tour extends Evented {

constructor(options = {}) {
super(options);
this.bindMethods();
this.options = options;
this.steps = this.options.steps || [];

// Pass these events onto the global Shepherd object
const events = ['complete', 'cancel', 'hide', 'start', 'show', 'active', 'inactive'];
const events = ['complete', 'cancel', 'start', 'show', 'active', 'inactive'];
events.map((event) => {
((e) => {
this.on(e, (opts) => {
Expand All @@ -619,8 +617,7 @@ class Tour extends Evented {
'next',
'back',
'cancel',
'complete',
'hide'
'complete'
];
methods.map((method) => {
this[method] = this[method].bind(this);
Expand Down Expand Up @@ -667,7 +664,7 @@ class Tour extends Evented {
if (this.steps.length) {
this.show(0);
} else {
this.hide();
this.cancel();
}
}
}
Expand All @@ -689,9 +686,7 @@ class Tour extends Evented {
const index = this.steps.indexOf(this.currentStep);

if (index === this.steps.length - 1) {
this.hide(index);
this.trigger('complete');
this.done();
this.complete();
} else {
this.show(index + 1, true);
}
Expand All @@ -702,31 +697,32 @@ class Tour extends Evented {
this.show(index - 1, false);
}

/**
* Calls done() triggering the 'cancel' event
*/
cancel() {
if (this.currentStep) {
this.currentStep.hide();
}
this.trigger('cancel');
this.done();
this.done('cancel');
}

/**
* Calls done() triggering the 'complete' event
*/
complete() {
if (this.currentStep) {
this.currentStep.hide();
}
this.trigger('complete');
this.done();
this.done('complete');
}

hide() {
/**
* Called whenever the tour is cancelled or completed, basically anytime we exit the tour
* @param event
*/
done(event) {
if (this.currentStep) {
this.currentStep.hide();
}
this.trigger('hide');
this.done();
}

done() {
this.trigger(event);

Shepherd.activeTour.steps.map(step => step.destroy());
Shepherd.activeTour = null;
document.body.classList.remove('shepherd-active');
this.trigger('inactive', { tour: this });
Expand Down

0 comments on commit 9c0ee27

Please sign in to comment.