Skip to content

Commit

Permalink
Merge pull request #212 from CodyAntcliffe/Add-On-Before-Exit-Event
Browse files Browse the repository at this point in the history
Added support for the on-before-exit action
  • Loading branch information
PoslinskiNet authored Nov 29, 2019
2 parents 7d9479c + dfa6d08 commit 741ecb7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@ Called after `on-change` when the user moves a step (backwards or
forward) in the introduction. Gives the current step, the introJS
component isntance, and the element of the current step.

### on-exit (step, introJSComponent)
### on-before-exit (step, introJSComponent)

Called when the user quits the intro via the "Skip" button, hitting
`escape`, or clicking outside the overlay. Given the current step, and
the introJS component.

### on-exit (step, introJSComponent)

Called after `on-before-exit` when the user quits the intro via the "Skip" button, hitting
`escape`, or clicking outside the overlay. Given the current step, and
the introJS component.

### on-complete (step, introJSComponent)

Called when the user finishes the intro by clicking "Done" or hitting
Expand Down
5 changes: 5 additions & 0 deletions addon/components/intro-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default Component.extend({
intro.oncomplete(bind(this, this._onComplete));
intro.onexit(bind(this, this._onExit));
intro.onskip(bind(this, this._onSkip));
intro.onbeforeexit(bind(this, this._onBeforeExit));
},

_setIntroJS(introJS){
Expand Down Expand Up @@ -185,6 +186,10 @@ export default Component.extend({
this._sendAction('on-complete', [this.get('currentStep')]);
},

_onBeforeExit() {
this._sendAction('on-before-exit', [this.get('currentStep'), this]);
},

_setCurrentStep(step){
this.set('currentStep', this._getStep(step));
},
Expand Down
17 changes: 15 additions & 2 deletions tests/integration/components/intro-js-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,20 @@ module('Integration | Component | intro js', function(hooks) {
});
});

module('when existing', function() {
module('when exiting', function() {

test('fires the on-before-exit action', async function(assert) {
assert.expect(2);

this.set('onBeforeExit', (step) => {
assert.equal(step, this.steps[0])
});

await render(hbs`{{intro-js steps=steps start-if=true on-before-exit=(action onBeforeExit)}}`);

await introJSSkip();
});

test('fires the on-exit action', async function(assert) {
assert.expect(3);

Expand All @@ -84,7 +97,7 @@ module('Integration | Component | intro js', function(hooks) {
await render(hbs`{{intro-js steps=steps start-if=true on-exit=(action myExit)}}`);

await introJSSkip();
})
});
});

module('when skiping', function() {
Expand Down

0 comments on commit 741ecb7

Please sign in to comment.