Skip to content

Commit f5a3fa4

Browse files
authored
Merge pull request #737 from usablica/afshinm-onbeforexit
Adding onbeforexit and force option
2 parents 0249c86 + 7b06e42 commit f5a3fa4

File tree

8 files changed

+149
-10
lines changed

8 files changed

+149
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Intro.js v2.6.0
1+
# Intro.js v2.7.0
22

33
> Better introductions for websites and features with a step-by-step guide for your projects.
44

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release History
22

3+
* **v2.7.0** - 2017-08-17
4+
- Added `onbeforeexit` callback
5+
- Added `force` parameter to `exit()`
6+
- Added Code of Conduct and Contributing guide files
7+
38
* **v2.6.0** - 2017-07-29
49
- Per step disable interaction
510
- Adding `scrollTo` option

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "intro.js",
33
"repo": "usablica/intro.js",
44
"description": "Better introductions for websites and features with a step-by-step guide for your projects",
5-
"version": "2.6.0",
5+
"version": "2.7.0",
66
"main": "intro.js",
77
"scripts": [
88
"intro.js"

docs/docs/getting-started/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ We have prepared a list of common examples using Introjs for both hints and intr
1414
* [Basic usage with buttons](http://introjs.com/example/hello-world/withoutBullets.html "Basic usage with buttons")
1515
* [Basic usage with bullets](http://introjs.com/example/hello-world/withoutButtons.html "Basic usage with bullets")
1616
* [Basic usage with progress-bar](http://introjs.com/example/hello-world/withProgress.html "Basic usage with progress-bar")
17+
* [Confirm before exit](http://introjs.com/example/hello-world/exit-confirm.html "Shows a confirm before exit")
1718
* [Programmatic defining using JSON](http://introjs.com/example/programmatic/index.html "Programmatic defining using JSON")
1819
* [Multi-Page introduction](http://introjs.com/example/multi-page/index.html "Multi-Page introduction")
1920
* [Disabling interaction with elements](http://introjs.com/example/disable-interaction/index.html "Disabling interaction with elements")

docs/docs/intro/api.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ introJs().goToStep(2).start(); //starts introduction from step 2
6767

6868
-----
6969

70-
###introJs.goToStepNumber(step)
70+
##### introJs.goToStepNumber(step)
7171

7272
Go to specific step of introduction with the concrete step.
7373
This differs from `goToStep` in the way that `data-step`
@@ -165,12 +165,16 @@ introJs().goToStep(3).start().previousStep(); //starts introduction from step 2
165165

166166
-----
167167

168-
##### introJs.exit()
168+
##### introJs.exit([force])
169169

170170
Exit the introduction.
171171

172172
**Available since**: v0.3.0
173173

174+
**Parameters:**
175+
176+
- force : Boolean (optional) - Exit the tour even if `introJs.onbeforeexit` returns `false` (Available since 2.7.0)
177+
174178
**Returns:**
175179

176180
- introJs object.
@@ -296,6 +300,33 @@ introJs().onexit(function() {
296300

297301
-----
298302

303+
##### introJs.onbeforeexit(providedCallback)
304+
305+
Works exactly same as `onexit` but calls before closing the tour. Also, returning `false` would prevent the tour from closing.
306+
307+
**Available since:** v0.2.7
308+
309+
**Parameters:**
310+
311+
- providedCallback : Function
312+
313+
**Returns:**
314+
315+
- introJs object.
316+
317+
**Example:**
318+
319+
```javascript
320+
introJs().onbeforeexit(function() {
321+
console.log("on before exit")
322+
323+
// returning false means don't exit the intro
324+
return false;
325+
});
326+
````
327+
328+
-----
329+
299330
##### introJs.onchange(providedCallback)
300331
301332
Set callback to change of each step of introduction. Given callback function will be called after completing each step.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Basic usage</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta name="description" content="Intro.js - Better introductions for websites and features with a step-by-step guide for your projects.">
8+
<meta name="author" content="Afshin Mehrabani (@afshinmeh) in usabli.ca group">
9+
10+
<!-- styles -->
11+
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
12+
<link href="../assets/css/demo.css" rel="stylesheet">
13+
14+
<!-- Add IntroJs styles -->
15+
<link href="../../introjs.css" rel="stylesheet">
16+
17+
<link href="../assets/css/bootstrap-responsive.min.css" rel="stylesheet">
18+
</head>
19+
20+
<body>
21+
22+
<div class="container-narrow">
23+
24+
<div class="masthead">
25+
<ul class="nav nav-pills pull-right" data-step="5" data-intro="Get it, use it.">
26+
<li><a href="https://github.com/usablica/intro.js/tags"><i class='icon-black icon-download-alt'></i> Download</a></li>
27+
<li><a href="https://github.com/usablica/intro.js">Github</a></li>
28+
<li><a href="https://twitter.com/usablica">@usablica</a></li>
29+
</ul>
30+
<h3 class="muted">Intro.js</h3>
31+
</div>
32+
33+
<hr>
34+
35+
<div class="jumbotron">
36+
<h1 data-step="1" data-intro="This is a tooltip!">Confirm before exit</h1>
37+
<p class="lead" data-step="4" data-intro="Another step.">Shows a confirmation box before existing the tour using <code>onbeforeexit</code> callback.</p>
38+
<a class="btn btn-large btn-success" href="javascript:void(0);" onclick="javascript:startTour();">Show me how</a>
39+
</div>
40+
41+
<hr>
42+
43+
<div class="row-fluid marketing">
44+
<div class="span6" data-step="2" data-intro="Ok, wasn't that fun?" data-position='right' data-scrollTo='tooltip'>
45+
<h4>Section One</h4>
46+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
47+
48+
<h4>Section Two</h4>
49+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
50+
51+
<h4>Section Three</h4>
52+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
53+
</div>
54+
55+
<div class="span6" data-step="3" data-intro="More features, more fun." data-position='left'>
56+
<h4>Section Four</h4>
57+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
58+
59+
<h4>Section Five</h4>
60+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
61+
62+
<h4>Section Six</h4>
63+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis augue a neque cursus ac blandit orci faucibus. Phasellus nec metus purus.</p>
64+
65+
</div>
66+
</div>
67+
68+
<hr>
69+
</div>
70+
<script type="text/javascript" src="../../intro.js"></script>
71+
72+
<script type="text/javascript">
73+
function startTour() {
74+
introJs().start().onbeforeexit(function () {
75+
return confirm("Are you sure?");
76+
});
77+
}
78+
</script>
79+
</body>
80+
</html>

intro.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Intro.js v2.6.0
2+
* Intro.js v2.7.0
33
* https://github.com/usablica/intro.js
44
*
55
* Copyright (C) 2017 Afshin Mehrabani (@afshinmeh)
@@ -18,7 +18,7 @@
1818
}
1919
} (this, function (exports) {
2020
//Default config/variables
21-
var VERSION = '2.6.0';
21+
var VERSION = '2.7.0';
2222

2323
/**
2424
* IntroJs main class
@@ -435,8 +435,22 @@
435435
* @api private
436436
* @method _exitIntro
437437
* @param {Object} targetElement
438+
* @param {Boolean} force - Setting to `true` will skip the result of beforeExit callback
438439
*/
439-
function _exitIntro(targetElement) {
440+
function _exitIntro(targetElement, force) {
441+
var continueExit = true;
442+
443+
// calling onbeforeexit callback
444+
//
445+
// If this callback return `false`, it would halt the process
446+
if (this._introBeforeExitCallback != undefined) {
447+
continueExit = this._introBeforeExitCallback.call(self);
448+
}
449+
450+
// skip this check if `force` parameter is `true`
451+
// otherwise, if `onbeforeexit` returned `false`, don't exit the intro
452+
if (!force && continueExit === false) return;
453+
440454
//remove overlay layers from the page
441455
var overlayLayers = targetElement.querySelectorAll('.introjs-overlay');
442456

@@ -2006,8 +2020,8 @@
20062020
_previousStep.call(this);
20072021
return this;
20082022
},
2009-
exit: function() {
2010-
_exitIntro.call(this, this._targetElement);
2023+
exit: function(force) {
2024+
_exitIntro.call(this, this._targetElement, force);
20112025
return this;
20122026
},
20132027
refresh: function() {
@@ -2078,6 +2092,14 @@
20782092
}
20792093
return this;
20802094
},
2095+
onbeforeexit: function(providedCallback) {
2096+
if (typeof (providedCallback) === 'function') {
2097+
this._introBeforeExitCallback = providedCallback;
2098+
} else {
2099+
throw new Error('Provided callback for onbeforeexit was not a function.');
2100+
}
2101+
return this;
2102+
},
20812103
addHints: function() {
20822104
_populateHints.call(this, this._targetElement);
20832105
return this;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "intro.js",
33
"description": "Better introductions for websites and features with a step-by-step guide for your projects",
4-
"version": "2.6.0",
4+
"version": "2.7.0",
55
"author": "Afshin Mehrabani <[email protected]>",
66
"homepage": "http://introjs.com",
77
"repository": {

0 commit comments

Comments
 (0)