From dfa6d08a615f68cc9e56a78d6b5e7f2d3ad56739 Mon Sep 17 00:00:00 2001 From: Cody Antcliffe Date: Thu, 28 Nov 2019 16:07:38 -0800 Subject: [PATCH] Added support for the on-before-exit action --- README.md | 8 +++++++- addon/components/intro-js.js | 5 +++++ tests/integration/components/intro-js-test.js | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5baa822..dd56246 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/addon/components/intro-js.js b/addon/components/intro-js.js index 5fbcce8..8798265 100644 --- a/addon/components/intro-js.js +++ b/addon/components/intro-js.js @@ -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){ @@ -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)); }, diff --git a/tests/integration/components/intro-js-test.js b/tests/integration/components/intro-js-test.js index 44bd69b..3874fab 100644 --- a/tests/integration/components/intro-js-test.js +++ b/tests/integration/components/intro-js-test.js @@ -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); @@ -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() {