Skip to content

Commit dfa6d08

Browse files
author
Cody Antcliffe
committed
Added support for the on-before-exit action
1 parent 7d9479c commit dfa6d08

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,18 @@ Called after `on-change` when the user moves a step (backwards or
123123
forward) in the introduction. Gives the current step, the introJS
124124
component isntance, and the element of the current step.
125125

126-
### on-exit (step, introJSComponent)
126+
### on-before-exit (step, introJSComponent)
127127

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

132+
### on-exit (step, introJSComponent)
133+
134+
Called after `on-before-exit` when the user quits the intro via the "Skip" button, hitting
135+
`escape`, or clicking outside the overlay. Given the current step, and
136+
the introJS component.
137+
132138
### on-complete (step, introJSComponent)
133139

134140
Called when the user finishes the intro by clicking "Done" or hitting

addon/components/intro-js.js

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default Component.extend({
144144
intro.oncomplete(bind(this, this._onComplete));
145145
intro.onexit(bind(this, this._onExit));
146146
intro.onskip(bind(this, this._onSkip));
147+
intro.onbeforeexit(bind(this, this._onBeforeExit));
147148
},
148149

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

189+
_onBeforeExit() {
190+
this._sendAction('on-before-exit', [this.get('currentStep'), this]);
191+
},
192+
188193
_setCurrentStep(step){
189194
this.set('currentStep', this._getStep(step));
190195
},

tests/integration/components/intro-js-test.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,20 @@ module('Integration | Component | intro js', function(hooks) {
7373
});
7474
});
7575

76-
module('when existing', function() {
76+
module('when exiting', function() {
77+
78+
test('fires the on-before-exit action', async function(assert) {
79+
assert.expect(2);
80+
81+
this.set('onBeforeExit', (step) => {
82+
assert.equal(step, this.steps[0])
83+
});
84+
85+
await render(hbs`{{intro-js steps=steps start-if=true on-before-exit=(action onBeforeExit)}}`);
86+
87+
await introJSSkip();
88+
});
89+
7790
test('fires the on-exit action', async function(assert) {
7891
assert.expect(3);
7992

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

8699
await introJSSkip();
87-
})
100+
});
88101
});
89102

90103
module('when skiping', function() {

0 commit comments

Comments
 (0)